Node-RED: Rozdiel medzi revíziami
Zo stránky SensorWiki
Bez shrnutí editace |
|||
(12 medziľahlých úprav od rovnakého používateľa nie je zobrazených.) | |||
Riadok 1: | Riadok 1: | ||
== '''Quick Start''' == | |||
Node-RED | # Inštalácia: https://nodered.org/docs/getting-started/windows | ||
#* Online Node-RED environment FRED: https://fred.sensetecnic.com/ | |||
# START http://localhost:1880/ | |||
#* Start Dashboard http://localhost:1880/ui | |||
# Základy | |||
#* Node-RED Guide http://noderedguide.com | |||
#* Cookbook: https://cookbook.nodered.org/basic/map-between-different-number-ranges | |||
# Knižnice: obvykle radia cez npm (node package manager), ale mne to velmi neslo, preto odporucam postup priamo z Node-RED menu: Settings -> Palette -> Install | |||
# Ukladanie: vytvorené flows sa nikam extra neukladajú, ale ak by to náhodou spadlo, prídete o ne. Preto odporúčam cez Menu -> Export uložiť to čo potrebujete | |||
# Koniec: Ctrl+C | |||
'''Čo ďalej? Podrobnejšie informácie:''' | |||
* http://noderedguide.com/node-red-lecture- | * Node-RED Guide: http://noderedguide.com | ||
* | * Toto je dolezite pochopit https://nodered.org/docs/user-guide/messages#understanding-the-structure-of-a-message | ||
* Inak vysvetlené messages http://www.steves-internet-guide.com/node-red-message-object/ | |||
* A hodi sa asi aj vysvetlenie ako je to s premennymi http://www.steves-internet-guide.com/node-red-variables/ | |||
* Dashboard podrobnejšie http://noderedguide.com/lecture-7-node-red-dashboard-part2/ | |||
* Komunikácia s IBM Watson https://developer.ibm.com/recipes/tutorials/connecting-raspberry-pi-gateway-watson-iot-using-node-red-part-ii/ | |||
< | |||
== '''Inštalácia''' == | |||
1. Najprv nainštalujeme odtialto Node.js | |||
https://nodejs.org/en/ | |||
'''Čo je node js?''' | |||
Node.js is an open-source, cross-platform, JavaScript runtime | |||
environment that executes JavaScript code outside of a web browser. | |||
Node.js lets developers use JavaScript to write command line tools | |||
and for server-side scripting—running scripts server-side to | |||
produce dynamic web page content before the page is sent to | |||
the user's web browser. Consequently, Node.js represents a | |||
"JavaScript everywhere" paradigm,[6] unifying web-application | |||
development around a single programming language, rather | |||
than different languages for server- and client-side scripts. | |||
Inštaláciu skontrolujeme | |||
C:\>node --version && npm --version | |||
U mňa bola odozva takáto | |||
v12.14.1 | |||
6.13.4 | |||
funguje to až keď po inštalácii zavrieme vsetky cmd okna a potom v novootvorenom cmd uz to funguje. | |||
2. Potom nainštalujeme z cmd konzoly Node-RED, pre linuxy je | |||
popis na stranke, pre win je trocha zmena: | |||
Spsutit cmd (ale run as administrator) | |||
C:\>npm install -g --unsafe-perm node-red | |||
(mne to skoncilo takto | |||
node-pre-gyp WARN Using request for node-pre-gyp https download | |||
ale nevadilo to) | |||
3. Po instalacii to uz funguje, takze staci spustit z cmd | |||
C:>node-red | |||
Musi to bezat v cmd okne na pozadi stale. | |||
4. A potom, tak ako je to aj v tom cmd okne napisane: | |||
Server now running at http://127.0.0.1:1880/ | |||
alebo http://localhost:1880 | |||
Viac info tu: https://nodered.org/docs/getting-started/windows | |||
First flow | |||
https://nodered.org/docs/tutorials/first-flow | |||
5. Ukoncenie: | |||
It can then be stopped by pressing Ctrl-C or by closing the terminal window. | |||
Alebo na unixovych strojoch cez KILL a PID | |||
Po inštalácii Node-RED budete mať k dispozícii iba základnú sadu uzlov. Dodatočné uzly je možné inštalovať priamo z editora, ale je to trochu skryté. Musíte kliknúť na ikonu menu v pravej hornej časti obrazovky a v menu vybrať funkciu Manage palette. Vyberiete si záložku Palette/Install. Do vyhľadávania napíšte nasledovné výrazy a nainštalujte si ich. | |||
node-red-node-serialport -> pre príjem dát zo sériového portu | |||
node-red-dashboard -> pre vytváranie HMI panelov s prístrojmi | |||
node-red-node-email -> pre posielanie mailov | |||
Poznámka: nepotrebujeme ziadnu Arduino specific kniznicu, lebo ideme komunikovat cez seriovy port, co je ovela univerzalnejsie ako Arduino. | |||
== '''Príklad 1''' == | |||
Najjednoduchší základný príklad | |||
[[Súbor:Node-RED-Example01.png|600px]] | |||
<source lang="json"> | |||
[ | [ | ||
{ | { | ||
"id": " | "id": "cc236d6c.fe202", | ||
"type": "inject", | "type": "inject", | ||
"z": " | "z": "176a8127.e35c5f", | ||
"name": "", | "name": "", | ||
"topic": "", | "topic": "", | ||
"payload": "", | "payload": "{\"Temperature\":27}", | ||
"payloadType": "str", | "payloadType": "str", | ||
"repeat": " | "repeat": "", | ||
"crontab": "", | "crontab": "", | ||
"once": false, | "once": false, | ||
"onceDelay": | "onceDelay": 0.1, | ||
"x": 150, | |||
"y": 200, | |||
"x": | |||
"y": | |||
"wires": [ | "wires": [ | ||
[ | [ | ||
" | "be082013.640bb" | ||
] | ] | ||
] | ] | ||
}, | }, | ||
{ | { | ||
"id": " | "id": "92282460.c4e178", | ||
"type": "debug", | "type": "debug", | ||
"z": " | "z": "176a8127.e35c5f", | ||
"name": "", | "name": "", | ||
"active": | "active": true, | ||
"tosidebar": true, | "tosidebar": true, | ||
"console": false, | "console": false, | ||
Riadok 225: | Riadok 142: | ||
"complete": "payload", | "complete": "payload", | ||
"targetType": "msg", | "targetType": "msg", | ||
"x": | "x": 810, | ||
"y": | "y": 200, | ||
"wires": [] | "wires": [] | ||
}, | }, | ||
{ | { | ||
"id": " | "id": "be082013.640bb", | ||
"type": " | "type": "json", | ||
"z": " | "z": "176a8127.e35c5f", | ||
"name": "", | "name": "", | ||
"property": "payload | "property": "payload", | ||
" | "action": "", | ||
" | "pretty": false, | ||
"x": 370, | |||
"y": 200, | |||
"x": | |||
"y": | |||
"wires": [ | "wires": [ | ||
[ | [ | ||
" | "3a67409b.6b098" | ||
] | ] | ||
] | ] | ||
}, | }, | ||
{ | { | ||
"id": " | "id": "3a67409b.6b098", | ||
"type": " | "type": "function", | ||
"z": " | "z": "176a8127.e35c5f", | ||
"name": "", | "name": "Temperature", | ||
" | "func": "/* extrahujeme len jednu z hodnot */\nmsg.payload = msg.payload.Temperature;\nreturn msg;", | ||
"outputs": 1, | |||
"noerr": 0, | |||
"x": 570, | |||
"y": 200, | |||
" | |||
" | |||
"x": | |||
"y": | |||
"wires": [ | "wires": [ | ||
[ | [ | ||
" | "92282460.c4e178" | ||
] | ] | ||
] | ] | ||
} | |||
] | |||
</source> | |||
== '''Príklad 2''' == | |||
[[Súbor:Node-RED-Example02.png|600px]] | |||
<source lang="json"> | |||
[ | |||
{ | |||
"id": "5855d622.ab8758", | |||
"type": "tab", | |||
"label": "Flow 1", | |||
"disabled": false, | |||
"info": "" | |||
}, | }, | ||
{ | { | ||
"id": " | "id": "dd03e979.ca34a8", | ||
"type": " | "type": "serial in", | ||
"z": " | "z": "5855d622.ab8758", | ||
"name": "", | "name": "", | ||
" | "serial": "f73cdcfa.3b1a", | ||
"x": 210, | |||
"y": 140, | |||
"x": | |||
"y | |||
"wires": [ | "wires": [ | ||
[ | [ | ||
" | "82b6fb5f.243848" | ||
] | ] | ||
] | ] | ||
}, | }, | ||
{ | { | ||
"id": " | "id": "37b2b2a.4c2ab4e", | ||
"type": " | "type": "ui_gauge", | ||
"z": " | "z": "5855d622.ab8758", | ||
"name": "", | "name": "Temp", | ||
" | "group": "8b2bccd7.70966", | ||
" | "order": 1, | ||
" | "width": "6", | ||
" | "height": "5", | ||
" | "gtype": "gage", | ||
" | "title": "Teplota", | ||
" | "label": "v tieni", | ||
" | "format": "{{value}} °C", | ||
" | "min": "-10", | ||
" | "max": "40", | ||
" | "colors": [ | ||
"#18ebf5", | |||
"#258141", | |||
" | "#ca3838" | ||
" | ], | ||
"x": | "seg1": "10", | ||
"y": | "seg2": "28", | ||
"wires": [ | "x": 830, | ||
"y": 80, | |||
"wires": [] | |||
}, | }, | ||
{ | { | ||
"id": " | "id": "eb1afe0.5b288", | ||
"type": "debug", | "type": "debug", | ||
"z": " | "z": "5855d622.ab8758", | ||
"name": "", | "name": "", | ||
"active": false, | "active": false, | ||
Riadok 361: | Riadok 243: | ||
"console": false, | "console": false, | ||
"tostatus": false, | "tostatus": false, | ||
"complete": " | "complete": "false", | ||
"x": 810, | |||
"x": | "y": 140, | ||
"y": | |||
"wires": [] | "wires": [] | ||
}, | }, | ||
{ | { | ||
"id": " | "id": "d8a28ce2.04c82", | ||
"type": "inject", | "type": "inject", | ||
"z": " | "z": "5855d622.ab8758", | ||
"name": " | "name": "", | ||
"topic": " | "topic": "", | ||
"payload": "", | "payload": "{\"Temperature\":27}", | ||
"payloadType": " | "payloadType": "str", | ||
"repeat": " | "repeat": "", | ||
"crontab": "", | "crontab": "", | ||
"once": false, | "once": false, | ||
"onceDelay": 0.1, | "onceDelay": 0.1, | ||
"x": | "x": 190, | ||
"y": | "y": 80, | ||
"wires": [ | "wires": [ | ||
[ | [ | ||
" | "82b6fb5f.243848" | ||
] | ] | ||
] | ] | ||
}, | }, | ||
{ | { | ||
"id": " | "id": "82b6fb5f.243848", | ||
"type": " | "type": "json", | ||
"z": " | "z": "5855d622.ab8758", | ||
"name": " | "name": "", | ||
" | "property": "payload", | ||
"action": "", | |||
"pretty": false, | |||
" | "x": 410, | ||
" | "y": 80, | ||
"x": | |||
"y": | |||
"wires": [ | "wires": [ | ||
[ | [ | ||
" | "3f55b492.096fcc" | ||
] | ] | ||
] | ] | ||
}, | }, | ||
{ | { | ||
"id": " | "id": "3f55b492.096fcc", | ||
"type": "function", | "type": "function", | ||
"z": " | "z": "5855d622.ab8758", | ||
"name": " | "name": "Temperature", | ||
"func": " | "func": "/* extrahujeme len jednu z hodnot */\nmsg.payload = msg.payload.Temperature;\nreturn msg;", | ||
"outputs": 1, | "outputs": 1, | ||
"noerr": 0, | "noerr": 0, | ||
"x": | "x": 610, | ||
"y": | "y": 80, | ||
"wires": [ | "wires": [ | ||
[ | [ | ||
" | "eb1afe0.5b288", | ||
" | "37b2b2a.4c2ab4e" | ||
] | ] | ||
] | ] | ||
}, | }, | ||
{ | { | ||
"id": " | "id": "f73cdcfa.3b1a", | ||
"type": " | "type": "serial-port", | ||
"z": " | "z": "", | ||
" | "serialport": "COM12", | ||
" | "serialbaud": "9600", | ||
" | "databits": "8", | ||
" | "parity": "none", | ||
" | "stopbits": "1", | ||
" | "waitfor": "", | ||
" | "newline": "\\n", | ||
"bin": "false", | |||
"out": "char", | |||
"addchar": "false", | |||
"responsetimeout": "" | |||
}, | }, | ||
{ | { | ||
"id": " | "id": "8b2bccd7.70966", | ||
"type": " | "type": "ui_group", | ||
"z": " | "z": "", | ||
"name": " | "name": "Aktuálny stav", | ||
" | "tab": "37ac9c98.3fb884", | ||
" | "order": 2, | ||
" | "disp": true, | ||
" | "width": "12", | ||
"collapse": false | |||
" | |||
}, | }, | ||
{ | { | ||
"id": " | "id": "37ac9c98.3fb884", | ||
"type": " | "type": "ui_tab", | ||
"z": " | "z": "", | ||
"name": "Station", | |||
"icon": "dashboard", | |||
"name": "", | |||
" | |||
"order": 1, | "order": 1, | ||
" | "disabled": false, | ||
" | "hidden": false | ||
} | } | ||
] | ] | ||
</source> | |||
== '''Príklad 3''' == | |||
[[Súbor:Node-RED-Example03.png|800px]] | |||
'''Download:''' k niektorým blokom je samostatný stručný návod | |||
* inject [[Súbor:nodeInject.pdf]] | |||
* e-mail node [[Súbor:nodeEmail.pdf]] | |||
* serial-in node [[Súbor:nodeSerial.pdf]] | |||
* mqtt node [[Súbor:nodeMqtt.pdf]] | |||
Celý komplexný príklad je k dispozícii na stiahnutie tu: [[Médiá:Node-RED-Example03JSON.zip]] | |||
Kto by potreboval, tu je aj zdroják pre snímač teploty a vlhkosti DHT11 k Arduinu [[Médiá:Node-RED-Example03Arduino.zip]] | |||
Vo vyššie uvedených prikladoch sme použili okrem iného: | |||
* https://discourse.nodered.org/t/multiple-lines-on-a-graph-from-one-message/9315/4 | |||
* http://noderedguide.com/tutorial-node-red-dashboards-multiple-lines-on-a-chart/ | |||
* https://flows.nodered.org/node/node-red-contrib-ui-level - Pekny indikator |
Aktuálna revízia z 17:54, 12. máj 2020
Quick Start
- Inštalácia: https://nodered.org/docs/getting-started/windows
- Online Node-RED environment FRED: https://fred.sensetecnic.com/
- START http://localhost:1880/
- Start Dashboard http://localhost:1880/ui
- Základy
- Node-RED Guide http://noderedguide.com
- Cookbook: https://cookbook.nodered.org/basic/map-between-different-number-ranges
- Knižnice: obvykle radia cez npm (node package manager), ale mne to velmi neslo, preto odporucam postup priamo z Node-RED menu: Settings -> Palette -> Install
- Ukladanie: vytvorené flows sa nikam extra neukladajú, ale ak by to náhodou spadlo, prídete o ne. Preto odporúčam cez Menu -> Export uložiť to čo potrebujete
- Koniec: Ctrl+C
Čo ďalej? Podrobnejšie informácie:
- Node-RED Guide: http://noderedguide.com
- Toto je dolezite pochopit https://nodered.org/docs/user-guide/messages#understanding-the-structure-of-a-message
- Inak vysvetlené messages http://www.steves-internet-guide.com/node-red-message-object/
- A hodi sa asi aj vysvetlenie ako je to s premennymi http://www.steves-internet-guide.com/node-red-variables/
- Dashboard podrobnejšie http://noderedguide.com/lecture-7-node-red-dashboard-part2/
- Komunikácia s IBM Watson https://developer.ibm.com/recipes/tutorials/connecting-raspberry-pi-gateway-watson-iot-using-node-red-part-ii/
Inštalácia
1. Najprv nainštalujeme odtialto Node.js
https://nodejs.org/en/
Čo je node js? Node.js is an open-source, cross-platform, JavaScript runtime environment that executes JavaScript code outside of a web browser. Node.js lets developers use JavaScript to write command line tools and for server-side scripting—running scripts server-side to produce dynamic web page content before the page is sent to the user's web browser. Consequently, Node.js represents a "JavaScript everywhere" paradigm,[6] unifying web-application development around a single programming language, rather than different languages for server- and client-side scripts.
Inštaláciu skontrolujeme
C:\>node --version && npm --version
U mňa bola odozva takáto
v12.14.1 6.13.4
funguje to až keď po inštalácii zavrieme vsetky cmd okna a potom v novootvorenom cmd uz to funguje.
2. Potom nainštalujeme z cmd konzoly Node-RED, pre linuxy je
popis na stranke, pre win je trocha zmena:
Spsutit cmd (ale run as administrator)
C:\>npm install -g --unsafe-perm node-red
(mne to skoncilo takto
node-pre-gyp WARN Using request for node-pre-gyp https download
ale nevadilo to)
3. Po instalacii to uz funguje, takze staci spustit z cmd
C:>node-red
Musi to bezat v cmd okne na pozadi stale.
4. A potom, tak ako je to aj v tom cmd okne napisane:
Server now running at http://127.0.0.1:1880/ alebo http://localhost:1880
Viac info tu: https://nodered.org/docs/getting-started/windows
First flow
https://nodered.org/docs/tutorials/first-flow
5. Ukoncenie:
It can then be stopped by pressing Ctrl-C or by closing the terminal window. Alebo na unixovych strojoch cez KILL a PID
Po inštalácii Node-RED budete mať k dispozícii iba základnú sadu uzlov. Dodatočné uzly je možné inštalovať priamo z editora, ale je to trochu skryté. Musíte kliknúť na ikonu menu v pravej hornej časti obrazovky a v menu vybrať funkciu Manage palette. Vyberiete si záložku Palette/Install. Do vyhľadávania napíšte nasledovné výrazy a nainštalujte si ich.
node-red-node-serialport -> pre príjem dát zo sériového portu node-red-dashboard -> pre vytváranie HMI panelov s prístrojmi node-red-node-email -> pre posielanie mailov
Poznámka: nepotrebujeme ziadnu Arduino specific kniznicu, lebo ideme komunikovat cez seriovy port, co je ovela univerzalnejsie ako Arduino.
Príklad 1
Najjednoduchší základný príklad
[
{
"id": "cc236d6c.fe202",
"type": "inject",
"z": "176a8127.e35c5f",
"name": "",
"topic": "",
"payload": "{\"Temperature\":27}",
"payloadType": "str",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 150,
"y": 200,
"wires": [
[
"be082013.640bb"
]
]
},
{
"id": "92282460.c4e178",
"type": "debug",
"z": "176a8127.e35c5f",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"x": 810,
"y": 200,
"wires": []
},
{
"id": "be082013.640bb",
"type": "json",
"z": "176a8127.e35c5f",
"name": "",
"property": "payload",
"action": "",
"pretty": false,
"x": 370,
"y": 200,
"wires": [
[
"3a67409b.6b098"
]
]
},
{
"id": "3a67409b.6b098",
"type": "function",
"z": "176a8127.e35c5f",
"name": "Temperature",
"func": "/* extrahujeme len jednu z hodnot */\nmsg.payload = msg.payload.Temperature;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 570,
"y": 200,
"wires": [
[
"92282460.c4e178"
]
]
}
]
Príklad 2
[
{
"id": "5855d622.ab8758",
"type": "tab",
"label": "Flow 1",
"disabled": false,
"info": ""
},
{
"id": "dd03e979.ca34a8",
"type": "serial in",
"z": "5855d622.ab8758",
"name": "",
"serial": "f73cdcfa.3b1a",
"x": 210,
"y": 140,
"wires": [
[
"82b6fb5f.243848"
]
]
},
{
"id": "37b2b2a.4c2ab4e",
"type": "ui_gauge",
"z": "5855d622.ab8758",
"name": "Temp",
"group": "8b2bccd7.70966",
"order": 1,
"width": "6",
"height": "5",
"gtype": "gage",
"title": "Teplota",
"label": "v tieni",
"format": "{{value}} °C",
"min": "-10",
"max": "40",
"colors": [
"#18ebf5",
"#258141",
"#ca3838"
],
"seg1": "10",
"seg2": "28",
"x": 830,
"y": 80,
"wires": []
},
{
"id": "eb1afe0.5b288",
"type": "debug",
"z": "5855d622.ab8758",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"x": 810,
"y": 140,
"wires": []
},
{
"id": "d8a28ce2.04c82",
"type": "inject",
"z": "5855d622.ab8758",
"name": "",
"topic": "",
"payload": "{\"Temperature\":27}",
"payloadType": "str",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 190,
"y": 80,
"wires": [
[
"82b6fb5f.243848"
]
]
},
{
"id": "82b6fb5f.243848",
"type": "json",
"z": "5855d622.ab8758",
"name": "",
"property": "payload",
"action": "",
"pretty": false,
"x": 410,
"y": 80,
"wires": [
[
"3f55b492.096fcc"
]
]
},
{
"id": "3f55b492.096fcc",
"type": "function",
"z": "5855d622.ab8758",
"name": "Temperature",
"func": "/* extrahujeme len jednu z hodnot */\nmsg.payload = msg.payload.Temperature;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 610,
"y": 80,
"wires": [
[
"eb1afe0.5b288",
"37b2b2a.4c2ab4e"
]
]
},
{
"id": "f73cdcfa.3b1a",
"type": "serial-port",
"z": "",
"serialport": "COM12",
"serialbaud": "9600",
"databits": "8",
"parity": "none",
"stopbits": "1",
"waitfor": "",
"newline": "\\n",
"bin": "false",
"out": "char",
"addchar": "false",
"responsetimeout": ""
},
{
"id": "8b2bccd7.70966",
"type": "ui_group",
"z": "",
"name": "Aktuálny stav",
"tab": "37ac9c98.3fb884",
"order": 2,
"disp": true,
"width": "12",
"collapse": false
},
{
"id": "37ac9c98.3fb884",
"type": "ui_tab",
"z": "",
"name": "Station",
"icon": "dashboard",
"order": 1,
"disabled": false,
"hidden": false
}
]
Príklad 3
Download: k niektorým blokom je samostatný stručný návod
- inject Súbor:NodeInject.pdf
- e-mail node Súbor:NodeEmail.pdf
- serial-in node Súbor:NodeSerial.pdf
- mqtt node Súbor:NodeMqtt.pdf
Celý komplexný príklad je k dispozícii na stiahnutie tu: Médiá:Node-RED-Example03JSON.zip
Kto by potreboval, tu je aj zdroják pre snímač teploty a vlhkosti DHT11 k Arduinu Médiá:Node-RED-Example03Arduino.zip
Vo vyššie uvedených prikladoch sme použili okrem iného: