Operácie

Node-RED: Rozdiel medzi revíziami

Zo stránky SensorWiki

Balogh (diskusia | príspevky)
Balogh (diskusia | príspevky)
Riadok 182: Riadok 182:
== '''Príklad 2''' ==
== '''Príklad 2''' ==


[[Súbor:Node-RED-Example02.png]]
[[Súbor:Node-RED-Example02.png|600px]]


<source lang="json">
<source lang="json">
Riadok 339: Riadok 339:
]
]
</source>
</source>


== '''Príklad 3''' ==
== '''Príklad 3''' ==

Verzia z 17:22, 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
   node-red-dashboard
 

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


K niektorým blokom je samostatný stručný návod

  • e-mail node
  • mqtt node
  • serial-in node

Celý komplexný príklad je k dispozícii na stiahnutie tu: Médiá:Node-RED-Example03.json

Kto by potreboval, tu je aj zdroják pre snímač teploty a vlhkosti DHT11 k Arduinu



Vo vyššie uvedených prikladoch sme použili okrem iného: