Operácie

Node-RED: Rozdiel medzi revíziami

Z SensorWiki

(Príklad 3)
 
(11 medziľahlých úprav od rovnakého používateľa nie je zobrazených.)
Riadok 1: Riadok 1:
Moje hratky s Node-RED
 
  
Pripojit sem aj poznamky z desktopu
+
== '''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
  
* START http://localhost:1880/
+
'''Čo ďalej? Podrobnejšie informácie:'''
* START Dashboard http://localhost:1880/ui
 
  
* http://noderedguide.com/node-red-lecture-3-basic-nodes-and-flows/
+
* Node-RED Guide: http://noderedguide.com
* Cookbook: https://cookbook.nodered.org/basic/map-between-different-number-ranges
+
* 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/ 
 +
 
  
* 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
 
  
A sem dame jeden priklad na Dashboard s viacerymi prvkami
+
 
 +
 
 +
== '''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">
 
<source lang="json">
 
[
 
[
 
     {
 
     {
         "id": "667ca37f.39af9c",
+
         "id": "cc236d6c.fe202",
        "type": "tab",
 
        "label": "Flow 1",
 
        "disabled": false,
 
        "info": ""
 
    },
 
    {
 
        "id": "716b65e3.f5fd44",
 
        "type": "ui_tab",
 
        "z": "",
 
        "name": "FEI STU Bratislava : N48 11 06 E 017 12 023 : meteo",
 
        "icon": "dashboard",
 
        "disabled": false,
 
        "hidden": false
 
    },
 
    {
 
        "id": "3fbaf987.a5a6f6",
 
        "type": "ui_group",
 
        "z": "",
 
        "name": "Aktuálne počasie",
 
        "tab": "716b65e3.f5fd44",
 
        "disp": true,
 
        "width": "19",
 
        "collapse": false
 
    },
 
    {
 
        "id": "53a055fc.9dee3c",
 
        "type": "ui_base",
 
        "theme": {
 
            "name": "theme-dark",
 
            "lightTheme": {
 
                "default": "#0094CE",
 
                "baseColor": "#0094CE",
 
                "baseFont": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif",
 
                "edited": true,
 
                "reset": false
 
            },
 
            "darkTheme": {
 
                "default": "#097479",
 
                "baseColor": "#0b3f7d",
 
                "baseFont": "Copperplate,Copperplate Gothic Light,fantasy",
 
                "edited": true,
 
                "reset": false
 
            },
 
            "customTheme": {
 
                "name": "Untitled Theme 1",
 
                "default": "#4B7930",
 
                "baseColor": "#4B7930",
 
                "baseFont": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif"
 
            },
 
            "themeState": {
 
                "base-color": {
 
                    "default": "#097479",
 
                    "value": "#0b3f7d",
 
                    "edited": true
 
                },
 
                "page-titlebar-backgroundColor": {
 
                    "value": "#0b3f7d",
 
                    "edited": false
 
                },
 
                "page-backgroundColor": {
 
                    "value": "#111111",
 
                    "edited": false
 
                },
 
                "page-sidebar-backgroundColor": {
 
                    "value": "#000000",
 
                    "edited": false
 
                },
 
                "group-textColor": {
 
                    "value": "#1162c3",
 
                    "edited": false
 
                },
 
                "group-borderColor": {
 
                    "value": "#555555",
 
                    "edited": false
 
                },
 
                "group-backgroundColor": {
 
                    "value": "#333333",
 
                    "edited": false
 
                },
 
                "widget-textColor": {
 
                    "value": "#eeeeee",
 
                    "edited": false
 
                },
 
                "widget-backgroundColor": {
 
                    "value": "#0b3f7d",
 
                    "edited": false
 
                },
 
                "widget-borderColor": {
 
                    "value": "#333333",
 
                    "edited": false
 
                },
 
                "base-font": {
 
                    "value": "Copperplate,Copperplate Gothic Light,fantasy"
 
                }
 
            },
 
            "angularTheme": {
 
                "primary": "indigo",
 
                "accents": "blue",
 
                "warn": "red",
 
                "background": "grey"
 
            }
 
        },
 
        "site": {
 
            "name": "Node-RED Dashboard",
 
            "hideToolbar": "false",
 
            "allowSwipe": "false",
 
            "lockMenu": "false",
 
            "allowTempTheme": "true",
 
            "dateFormat": "DD/MM/YYYY",
 
            "sizes": {
 
                "sx": 48,
 
                "sy": 48,
 
                "gx": 6,
 
                "gy": 6,
 
                "cx": 6,
 
                "cy": 6,
 
                "px": 0,
 
                "py": 0
 
            }
 
        }
 
    },
 
    {
 
        "id": "73736cc1.367c2c",
 
        "type": "ui_spacer",
 
        "name": "spacer",
 
        "group": "3fbaf987.a5a6f6",
 
        "order": 2,
 
        "width": 12,
 
        "height": 1
 
    },
 
    {
 
        "id": "eff3ead5.cab97",
 
 
         "type": "inject",
 
         "type": "inject",
         "z": "667ca37f.39af9c",
+
         "z": "176a8127.e35c5f",
 
         "name": "",
 
         "name": "",
 
         "topic": "",
 
         "topic": "",
         "payload": "",
+
         "payload": "{\"Temperature\":27}",
 
         "payloadType": "str",
 
         "payloadType": "str",
         "repeat": "300",
+
         "repeat": "",
 
         "crontab": "",
 
         "crontab": "",
 
         "once": false,
 
         "once": false,
         "onceDelay": "",
+
         "onceDelay": 0.1,
        "x": 190,
+
         "x": 150,
        "y": 300,
+
         "y": 200,
        "wires": [
 
            [
 
                "8cd83d4d.d778a"
 
            ]
 
        ]
 
    },
 
    {
 
        "id": "8cd83d4d.d778a",
 
        "type": "http request",
 
        "z": "667ca37f.39af9c",
 
        "name": "Recent Quakes",
 
        "method": "GET",
 
        "paytoqs": false,
 
        "url": "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/significant_week.csv",
 
        "tls": "",
 
        "persist": false,
 
        "proxy": "",
 
        "authType": "",
 
        "x": 360,
 
        "y": 300,
 
        "wires": [
 
            [
 
                "f313061e.b57498"
 
            ]
 
        ]
 
    },
 
    {
 
        "id": "f313061e.b57498",
 
        "type": "csv",
 
        "z": "667ca37f.39af9c",
 
        "name": "",
 
        "sep": ",",
 
        "hdrin": true,
 
        "hdrout": "",
 
        "multi": "one",
 
        "ret": "\\n",
 
        "temp": "",
 
        "skip": 0,
 
        "strings": true,
 
         "x": 530,
 
         "y": 300,
 
 
         "wires": [
 
         "wires": [
 
             [
 
             [
                 "cd545c9b.47f688",
+
                 "be082013.640bb"
                "29043f0a.fc5768"
 
 
             ]
 
             ]
 
         ]
 
         ]
 
     },
 
     },
 
     {
 
     {
         "id": "cd545c9b.47f688",
+
         "id": "92282460.c4e178",
 
         "type": "debug",
 
         "type": "debug",
         "z": "667ca37f.39af9c",
+
         "z": "176a8127.e35c5f",
 
         "name": "",
 
         "name": "",
         "active": false,
+
         "active": true,
 
         "tosidebar": true,
 
         "tosidebar": true,
 
         "console": false,
 
         "console": false,
Riadok 225: Riadok 142:
 
         "complete": "payload",
 
         "complete": "payload",
 
         "targetType": "msg",
 
         "targetType": "msg",
         "x": 690,
+
         "x": 810,
         "y": 300,
+
         "y": 200,
 
         "wires": []
 
         "wires": []
 
     },
 
     },
 
     {
 
     {
         "id": "29043f0a.fc5768",
+
         "id": "be082013.640bb",
         "type": "switch",
+
         "type": "json",
         "z": "667ca37f.39af9c",
+
         "z": "176a8127.e35c5f",
 
         "name": "",
 
         "name": "",
         "property": "payload.mag",
+
         "property": "payload",
         "propertyType": "msg",
+
         "action": "",
         "rules": [
+
         "pretty": false,
            {
+
         "x": 370,
                "t": "gte",
+
         "y": 200,
                "v": "6",
 
                "vt": "num"
 
            }
 
        ],
 
        "checkall": "true",
 
        "repair": false,
 
        "outputs": 1,
 
         "x": 570,
 
         "y": 360,
 
 
         "wires": [
 
         "wires": [
 
             [
 
             [
                 "cb876b20.7e69e8"
+
                 "3a67409b.6b098"
 
             ]
 
             ]
 
         ]
 
         ]
 
     },
 
     },
 
     {
 
     {
         "id": "cb876b20.7e69e8",
+
         "id": "3a67409b.6b098",
         "type": "change",
+
         "type": "function",
         "z": "667ca37f.39af9c",
+
         "z": "176a8127.e35c5f",
         "name": "",
+
         "name": "Temperature",
         "rules": [
+
         "func": "/* extrahujeme len jednu z hodnot */\nmsg.payload =  msg.payload.Temperature;\nreturn msg;",
            {
+
         "outputs": 1,
                "t": "set",
+
         "noerr": 0,
                "p": "payload",
+
         "x": 570,
                "pt": "msg",
+
         "y": 200,
                "to": "PANIC!",
 
                "tot": "str"
 
            }
 
        ],
 
        "action": "",
 
        "property": "",
 
         "from": "",
 
        "to": "",
 
         "reg": false,
 
         "x": 710,
 
         "y": 420,
 
 
         "wires": [
 
         "wires": [
 
             [
 
             [
                 "2acc7858.b3f5"
+
                 "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": "2acc7858.b3f5",
+
         "id": "dd03e979.ca34a8",
         "type": "debug",
+
         "type": "serial in",
         "z": "667ca37f.39af9c",
+
         "z": "5855d622.ab8758",
 
         "name": "",
 
         "name": "",
         "active": false,
+
         "serial": "f73cdcfa.3b1a",
        "complete": false,
+
         "x": 210,
        "x": 810,
+
         "y": 140,
        "y": 360,
 
        "wires": []
 
    },
 
    {
 
        "id": "686552cf.1e648c",
 
        "type": "comment",
 
        "z": "667ca37f.39af9c",
 
        "name": "Poznamka",
 
        "info": "# Poznamocka\n\nTento komentar ma dve casti\n\n## Prva\n\nTu je dolezita **informacia**\n\n## Druha\n\nA tu je tiez nejaka informacia aj s odkazom na\nwebstranku [robotika.sk](http://robotika.sk)",
 
         "x": 180,
 
         "y": 160,
 
        "wires": [],
 
        "icon": "node-red/alert.svg"
 
    },
 
    {
 
        "id": "6edc0476.ff6ae4",
 
        "type": "inject",
 
        "z": "667ca37f.39af9c",
 
        "name": "temperature",
 
        "topic": "temperature",
 
        "payload": "10",
 
        "payloadType": "num",
 
        "repeat": "1",
 
        "crontab": "",
 
        "once": false,
 
        "onceDelay": 0.1,
 
        "x": 140,
 
        "y": 440,
 
 
         "wires": [
 
         "wires": [
 
             [
 
             [
                 "655ff53d.c446a4",
+
                 "82b6fb5f.243848"
                "3c2afec9.d14f4a"
 
 
             ]
 
             ]
 
         ]
 
         ]
 
     },
 
     },
 
     {
 
     {
         "id": "46876adc.ff037c",
+
         "id": "37b2b2a.4c2ab4e",
         "type": "join",
+
         "type": "ui_gauge",
         "z": "667ca37f.39af9c",
+
         "z": "5855d622.ab8758",
         "name": "",
+
         "name": "Temp",
         "mode": "custom",
+
         "group": "8b2bccd7.70966",
         "build": "object",
+
         "order": 1,
         "property": "",
+
         "width": "6",
         "propertyType": "full",
+
         "height": "5",
         "key": "topic",
+
         "gtype": "gage",
         "joiner": "\\n",
+
         "title": "Teplota",
         "joinerType": "str",
+
         "label": "v tieni",
         "accumulate": false,
+
         "format": "{{value}} °C",
         "timeout": "",
+
         "min": "-10",
         "count": "3",
+
         "max": "40",
         "reduceRight": false,
+
         "colors": [
        "reduceExp": "",
+
            "#18ebf5",
        "reduceInit": "",
+
            "#258141",
         "reduceInitType": "",
+
            "#ca3838"
         "reduceFixup": "",
+
        ],
         "x": 570,
+
         "seg1": "10",
         "y": 460,
+
         "seg2": "28",
         "wires": [
+
         "x": 830,
            [
+
         "y": 80,
                "e707a31.e2eb56"
+
         "wires": []
            ]
 
        ]
 
 
     },
 
     },
 
     {
 
     {
         "id": "e707a31.e2eb56",
+
         "id": "eb1afe0.5b288",
 
         "type": "debug",
 
         "type": "debug",
         "z": "667ca37f.39af9c",
+
         "z": "5855d622.ab8758",
 
         "name": "",
 
         "name": "",
 
         "active": false,
 
         "active": false,
Riadok 361: Riadok 243:
 
         "console": false,
 
         "console": false,
 
         "tostatus": false,
 
         "tostatus": false,
         "complete": "true",
+
         "complete": "false",
        "targetType": "full",
+
         "x": 810,
         "x": 870,
+
         "y": 140,
         "y": 500,
 
 
         "wires": []
 
         "wires": []
 
     },
 
     },
 
     {
 
     {
         "id": "397cee7c.3b22e2",
+
         "id": "d8a28ce2.04c82",
 
         "type": "inject",
 
         "type": "inject",
         "z": "667ca37f.39af9c",
+
         "z": "5855d622.ab8758",
         "name": "humidity",
+
         "name": "",
         "topic": "humidity",
+
         "topic": "",
         "payload": "",
+
         "payload": "{\"Temperature\":27}",
         "payloadType": "num",
+
         "payloadType": "str",
         "repeat": "1",
+
         "repeat": "",
 
         "crontab": "",
 
         "crontab": "",
 
         "once": false,
 
         "once": false,
 
         "onceDelay": 0.1,
 
         "onceDelay": 0.1,
         "x": 120,
+
         "x": 190,
         "y": 500,
+
         "y": 80,
 
         "wires": [
 
         "wires": [
 
             [
 
             [
                 "ad5871c6.a407c"
+
                 "82b6fb5f.243848"
 
             ]
 
             ]
 
         ]
 
         ]
 
     },
 
     },
 
     {
 
     {
         "id": "248e3e7b.d21dc2",
+
         "id": "82b6fb5f.243848",
         "type": "inject",
+
         "type": "json",
         "z": "667ca37f.39af9c",
+
         "z": "5855d622.ab8758",
         "name": "pressure",
+
         "name": "",
         "topic": "pressure",
+
         "property": "payload",
        "payload": "999",
+
         "action": "",
        "payloadType": "num",
+
         "pretty": false,
         "repeat": "1",
+
         "x": 410,
         "crontab": "",
+
         "y": 80,
        "once": false,
 
        "onceDelay": 0.1,
 
         "x": 120,
 
         "y": 560,
 
 
         "wires": [
 
         "wires": [
 
             [
 
             [
                 "2be11026.fe49b8"
+
                 "3f55b492.096fcc"
 
             ]
 
             ]
 
         ]
 
         ]
 
     },
 
     },
 
     {
 
     {
         "id": "655ff53d.c446a4",
+
         "id": "3f55b492.096fcc",
 
         "type": "function",
 
         "type": "function",
         "z": "667ca37f.39af9c",
+
         "z": "5855d622.ab8758",
         "name": "nahodne cislo",
+
         "name": "Temperature",
         "func": "msg.payload = Math.round(Math.random()*100);\nreturn msg;",
+
         "func": "/* extrahujeme len jednu z hodnot */\nmsg.payload = msg.payload.Temperature;\nreturn msg;",
 
         "outputs": 1,
 
         "outputs": 1,
 
         "noerr": 0,
 
         "noerr": 0,
         "x": 340,
+
         "x": 610,
         "y": 440,
+
         "y": 80,
 
         "wires": [
 
         "wires": [
 
             [
 
             [
                 "46876adc.ff037c",
+
                 "eb1afe0.5b288",
                 "1d61e023.7b57e8",
+
                 "37b2b2a.4c2ab4e"
                "e4e3aa12.79ac8"
 
 
             ]
 
             ]
 
         ]
 
         ]
 
     },
 
     },
 
     {
 
     {
         "id": "ad5871c6.a407c",
+
         "id": "f73cdcfa.3b1a",
         "type": "function",
+
         "type": "serial-port",
         "z": "667ca37f.39af9c",
+
         "z": "",
         "name": "nahodne cislo",
+
         "serialport": "COM12",
         "func": "msg.payload = Math.round(Math.random()*100);\nreturn msg;",
+
         "serialbaud": "9600",
         "outputs": 1,
+
         "databits": "8",
         "noerr": 0,
+
         "parity": "none",
         "x": 340,
+
         "stopbits": "1",
         "y": 500,
+
         "waitfor": "",
         "wires": [
+
         "newline": "\\n",
            [
+
        "bin": "false",
                "46876adc.ff037c",
+
        "out": "char",
                "1d61e023.7b57e8",
+
        "addchar": "false",
                "775a9045.e6d6c"
+
         "responsetimeout": ""
            ]
 
         ]
 
 
     },
 
     },
 
     {
 
     {
         "id": "2be11026.fe49b8",
+
         "id": "8b2bccd7.70966",
         "type": "function",
+
         "type": "ui_group",
         "z": "667ca37f.39af9c",
+
         "z": "",
         "name": "nahodne cislo",
+
         "name": "Aktuálny stav",
         "func": "msg.payload = Math.round(Math.random()*100);\nreturn msg;",
+
         "tab": "37ac9c98.3fb884",
         "outputs": 1,
+
         "order": 2,
         "noerr": 0,
+
         "disp": true,
         "x": 340,
+
         "width": "12",
        "y": 560,
+
         "collapse": false
         "wires": [
 
            [
 
                "46876adc.ff037c",
 
                "1d61e023.7b57e8",
 
                "e925c588.27715"
 
            ]
 
        ]
 
 
     },
 
     },
 
     {
 
     {
         "id": "1d61e023.7b57e8",
+
         "id": "37ac9c98.3fb884",
         "type": "ui_chart",
+
         "type": "ui_tab",
         "z": "667ca37f.39af9c",
+
         "z": "",
        "name": "",
+
         "name": "Station",
        "group": "3fbaf987.a5a6f6",
+
         "icon": "dashboard",
        "order": 6,
 
        "width": 19,
 
        "height": 5,
 
        "label": "Tri veličiny:",
 
        "chartType": "line",
 
        "legend": "true",
 
        "xformat": "HH:mm:ss",
 
        "interpolate": "linear",
 
        "nodata": "",
 
        "dot": false,
 
        "ymin": "",
 
        "ymax": "",
 
        "removeOlder": 1,
 
        "removeOlderPoints": "100",
 
        "removeOlderUnit": "60",
 
        "cutout": 0,
 
        "useOneColor": false,
 
        "colors": [
 
            "#1f77b4",
 
            "#aec7e8",
 
            "#ff7f0e",
 
            "#2ca02c",
 
            "#98df8a",
 
            "#d62728",
 
            "#ff9896",
 
            "#9467bd",
 
            "#c5b0d5"
 
        ],
 
        "useOldStyle": false,
 
        "outputs": 1,
 
        "x": 630,
 
        "y": 640,
 
        "wires": [
 
            []
 
        ]
 
    },
 
    {
 
        "id": "3c2afec9.d14f4a",
 
        "type": "debug",
 
        "z": "667ca37f.39af9c",
 
        "name": "",
 
        "active": true,
 
        "tosidebar": true,
 
        "console": false,
 
        "tostatus": false,
 
        "complete": "true",
 
        "targetType": "full",
 
        "x": 320,
 
        "y": 380,
 
        "wires": []
 
    },
 
    {
 
        "id": "e4e3aa12.79ac8",
 
        "type": "ui_gauge",
 
        "z": "667ca37f.39af9c",
 
         "name": "",
 
         "group": "3fbaf987.a5a6f6",
 
        "order": 3,
 
        "width": 7,
 
        "height": 4,
 
        "gtype": "gage",
 
        "title": "Teplota",
 
        "label": "&deg; C",
 
        "format": "{{value}} ",
 
        "min": 0,
 
        "max": "100",
 
        "colors": [
 
            "#49c4fe",
 
            "#c927e0",
 
            "#ca3838"
 
        ],
 
        "seg1": "",
 
        "seg2": "",
 
        "x": 620,
 
        "y": 500,
 
        "wires": []
 
    },
 
    {
 
        "id": "775a9045.e6d6c",
 
        "type": "ui_chart",
 
        "z": "667ca37f.39af9c",
 
        "name": "",
 
        "group": "3fbaf987.a5a6f6",
 
        "order": 4,
 
        "width": 4,
 
        "height": 4,
 
        "label": "Vlhkost",
 
        "chartType": "bar",
 
        "legend": "false",
 
        "xformat": "HH:mm:ss",
 
        "interpolate": "linear",
 
        "nodata": "",
 
        "dot": false,
 
        "ymin": "0",
 
        "ymax": "100",
 
        "removeOlder": 1,
 
        "removeOlderPoints": "",
 
        "removeOlderUnit": "3600",
 
        "cutout": 0,
 
        "useOneColor": false,
 
        "colors": [
 
            "#1f77b4",
 
            "#aec7e8",
 
            "#ff7f0e",
 
            "#2ca02c",
 
            "#98df8a",
 
            "#d62728",
 
            "#ff9896",
 
            "#9467bd",
 
            "#c5b0d5"
 
        ],
 
        "useOldStyle": false,
 
        "outputs": 1,
 
        "x": 620,
 
        "y": 540,
 
        "wires": [
 
            []
 
        ]
 
    },
 
    {
 
        "id": "e925c588.27715",
 
        "type": "ui_gauge",
 
        "z": "667ca37f.39af9c",
 
        "name": "",
 
        "group": "3fbaf987.a5a6f6",
 
        "order": 5,
 
        "width": 8,
 
        "height": 4,
 
        "gtype": "donut",
 
        "title": "Tlak",
 
        "label": "kPa",
 
        "format": "{{value}}",
 
        "min": 0,
 
        "max": "100",
 
        "colors": [
 
            "#00b500",
 
            "#e6e600",
 
            "#ca3838"
 
        ],
 
        "seg1": "",
 
        "seg2": "",
 
        "x": 610,
 
        "y": 580,
 
        "wires": []
 
    },
 
    {
 
        "id": "2ed48bea.985704",
 
        "type": "inject",
 
        "z": "667ca37f.39af9c",
 
        "name": "",
 
        "topic": "",
 
        "payload": "",
 
        "payloadType": "date",
 
        "repeat": "1",
 
        "crontab": "",
 
        "once": false,
 
        "onceDelay": 0.1,
 
        "x": 130,
 
        "y": 640,
 
        "wires": [
 
            [
 
                "2567a87a.c4cdb"
 
            ]
 
        ]
 
    },
 
    {
 
        "id": "5541894f.182c98",
 
        "type": "ui_text",
 
        "z": "667ca37f.39af9c",
 
        "group": "3fbaf987.a5a6f6",
 
 
         "order": 1,
 
         "order": 1,
         "width": 7,
+
         "disabled": false,
         "height": 1,
+
         "hidden": false
        "name": "",
 
        "label": "Dátum",
 
        "format": "{{msg.payload}}",
 
        "layout": "row-right",
 
        "x": 620,
 
        "y": 720,
 
        "wires": []
 
    },
 
    {
 
        "id": "2567a87a.c4cdb",
 
        "type": "function",
 
        "z": "667ca37f.39af9c",
 
        "name": "Datum",
 
        "func": "// Create a Date object from the payload\nvar date = new Date(msg.payload);\n// Change the payload to be a formatted Date string\nmsg.payload = date.toString();\n// Return the message so it can be sent on\nreturn msg;\n",
 
        "outputs": 1,
 
        "noerr": 0,
 
        "x": 340,
 
        "y": 660,
 
        "wires": [
 
            [
 
                "5541894f.182c98"
 
            ]
 
        ]
 
 
     }
 
     }
 
]
 
]
 +
</source>
  
</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

  1. Inštalácia: https://nodered.org/docs/getting-started/windows
  2. START http://localhost:1880/
  3. Základy
  4. 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
  5. 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
  6. Koniec: Ctrl+C

Čo ďalej? Podrobnejšie informácie:




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

Node-RED-Example01.png

[
    {
        "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

Node-RED-Example02.png

[
    {
        "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

Node-RED-Example03.png


Download: k niektorým blokom je samostatný stručný návod

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: