NodeRED
Salta a la navegació
Salta a la cerca
Nodered a la RPi
Install/Upgrade. Aquesta comanda fa tota la feina:
$ bash <(curl -sL https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/update-nodejs-and-nodered)
Autostart on boot
$ sudo systemctl enable nodered.service reinicio $ service nodered status ● nodered.service - Node-RED graphical event wiring tool Loaded: loaded (/lib/systemd/system/nodered.service; enabled; vendor preset: Active: active (running) since Tue 2018-06-26 14:08:18 UTC; 4min 55s ago
Des del portàtil:
I ara ja puc fer les primeres proves. Si vull treballar amb els pins GPIO de la RPi, m'he d'acabar de mirar el document, però ha de ser fàcil.
Proves amb el node JSON, funcions, i d'altres coses
He fet proves, i a vegades no és tan evident. El projecte que estic fent es pot exportar per tal de poder reproduir-lo en un altre servidor de Node-Red:
[ { "id": "41a49b9.e8e4864", "type": "mqtt in", "z": "136051ed.8837e6", "name": "sensors/temp", "topic": "sensors/temp", "qos": "2", "broker": "63ab529b.a5043c", "x": 110, "y": 200, "wires": [ [ "6e6e9778.625478" ] ] }, { "id": "c18fce18.dbcd18", "type": "debug", "z": "136051ed.8837e6", "name": "", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "payload.temp", "x": 450, "y": 160, "wires": [] }, { "id": "1f1b8ac.0966ef5", "type": "mqtt out", "z": "136051ed.8837e6", "name": "", "topic": "sensors/temp", "qos": "", "retain": "", "broker": "63ab529b.a5043c", "x": 320, "y": 80, "wires": [] }, { "id": "b6486aee.3b3ad", "type": "inject", "z": "136051ed.8837e6", "name": "valor_sensors", "topic": "", "payload": "{\"temp\":15,\"hr\":50}", "payloadType": "str", "repeat": "", "crontab": "", "once": true, "onceDelay": 0.1, "x": 140, "y": 80, "wires": [ [ "1f1b8ac.0966ef5" ] ] }, { "id": "6e6e9778.625478", "type": "json", "z": "136051ed.8837e6", "name": "", "property": "payload", "action": "", "pretty": false, "x": 270, "y": 200, "wires": [ [ "c18fce18.dbcd18", "c483ca38.b267e8", "68fc3de7.a6a8dc", "106902ed.6018bd", "17adb637.1414ea" ] ] }, { "id": "c483ca38.b267e8", "type": "debug", "z": "136051ed.8837e6", "name": "", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "payload.hr", "x": 440, "y": 200, "wires": [] }, { "id": "68fc3de7.a6a8dc", "type": "switch", "z": "136051ed.8837e6", "name": "switch", "property": "payload.temp", "propertyType": "msg", "rules": [ { "t": "gte", "v": "30", "vt": "jsonata" }, { "t": "lt", "v": "20", "vt": "jsonata" } ], "checkall": "true", "repair": false, "outputs": 2, "x": 410, "y": 240, "wires": [ [ "9a8f0549.de7b88" ], [ "3336973a.8ab3d8" ] ] }, { "id": "3336973a.8ab3d8", "type": "change", "z": "136051ed.8837e6", "name": "", "rules": [ { "t": "set", "p": "payload.temp", "pt": "msg", "to": "encendre el calentador", "tot": "str" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 600, "y": 280, "wires": [ [ "e230ed4a.4bac6" ] ] }, { "id": "9a8f0549.de7b88", "type": "change", "z": "136051ed.8837e6", "name": "", "rules": [ { "t": "set", "p": "payload.temp", "pt": "msg", "to": "encendre l'aire acondicionat", "tot": "str" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 600, "y": 240, "wires": [ [ "e230ed4a.4bac6" ] ] }, { "id": "e230ed4a.4bac6", "type": "debug", "z": "136051ed.8837e6", "name": "", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "x": 810, "y": 260, "wires": [] }, { "id": "106902ed.6018bd", "type": "function", "z": "136051ed.8837e6", "name": "return_temp_hr", "func": "var keys = Object.keys(msg.payload);\n\nvar msgs = keys.map(function(key) {\n return { topic: key, payload: msg.payload[key] };\n});\nreturn [msgs];", "outputs": 1, "noerr": 0, "x": 440, "y": 360, "wires": [ [ "cbbebf79.53dce" ] ], "outputLabels": [ "number" ] }, { "id": "cbbebf79.53dce", "type": "debug", "z": "136051ed.8837e6", "name": "", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "payload", "x": 610, "y": 360, "wires": [] }, { "id": "17adb637.1414ea", "type": "function", "z": "136051ed.8837e6", "name": "return_temp", "func": "var keys = Object.keys(msg.payload);\n\nvar msgs = keys.map(function(key) {\n return { topic: key, payload: msg.payload[key] };\n});\nreturn [msgs[0]];", "outputs": 1, "noerr": 0, "x": 330, "y": 440, "wires": [ [ "2c3eb87a.189be8" ] ] }, { "id": "9ed0b840.189b", "type": "debug", "z": "136051ed.8837e6", "name": "", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "x": 850, "y": 440, "wires": [] }, { "id": "2c3eb87a.189be8", "type": "switch", "z": "136051ed.8837e6", "name": "switch_temp", "property": "payload", "propertyType": "msg", "rules": [ { "t": "gte", "v": "30", "vt": "num" }, { "t": "lt", "v": "20", "vt": "num" } ], "checkall": "true", "repair": false, "outputs": 2, "x": 490, "y": 440, "wires": [ [ "e54c99b.bb22e68" ], [ "97c530f4.40ad8" ] ] }, { "id": "e54c99b.bb22e68", "type": "change", "z": "136051ed.8837e6", "name": "", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "encendre aire acondicionat", "tot": "str" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 670, "y": 420, "wires": [ [ "9ed0b840.189b" ] ] }, { "id": "97c530f4.40ad8", "type": "change", "z": "136051ed.8837e6", "name": "", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "encendre calentador", "tot": "str" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 670, "y": 460, "wires": [ [ "9ed0b840.189b" ] ] }, { "id": "63ab529b.a5043c", "type": "mqtt-broker", "z": "", "name": "mosquitto", "broker": "192.168.1.33", "port": "1883", "clientid": "", "usetls": false, "compatmode": true, "keepalive": "60", "cleansession": true, "birthTopic": "", "birthQos": "0", "birthPayload": "", "closeTopic": "", "closeQos": "0", "closePayload": "", "willTopic": "", "willQos": "0", "willPayload": "" } ]