OpenMarine
Global variables in node red - Printable Version

+- OpenMarine (https://forum.openmarine.net)
+-- Forum: OpenPlotter (https://forum.openmarine.net/forumdisplay.php?fid=1)
+--- Forum: Node Red (https://forum.openmarine.net/forumdisplay.php?fid=15)
+--- Thread: Global variables in node red (/showthread.php?tid=929)



Global variables in node red - PaddyB - 2018-01-06

Maybe everyone else knows all this already, but I've just been digging deeper into global variables in node red. 
There's a node for seeing what they contain, search for 'node-red-contrib-contextbrowser' in the managepalette-install. also you can initialise them with any value on startup with a config node - node-red-contrib-config and view them straight in a browser.
http://10.10.10.1:1880/contextbrowser/global

So rather than parse through nmea 0r signalk messages it seems much easier to grab the messages once as they come in and assign the values to global variables, the change node makes this easy. 
For instance I have an ESP32 with various sensors sending data to the Pi over mqtt, this node puts the pressure into global.pressure where it's easier to get at for other flows to put it into a graph or database.
Hope this helps.

SOme more here - https://tech.scargill.net/node-red-global-flow-and-context/

Code:
[
   {
       "id": "6f1e8f4b.0d7e6",
       "type": "change",
       "z": "3f30ea31.da3756",
       "name": "",
       "rules": [
           {
               "t": "set",
               "p": "pressure",
               "pt": "global",
               "to": "payload",
               "tot": "msg"
           }
       ],
       "action": "",
       "property": "",
       "from": "",
       "to": "",
       "reg": false,
       "x": 411,
       "y": 1605,
       "wires": [
           []
       ]
   },
   {
       "id": "9a48ef5e.a7d12",
       "type": "mqtt in",
       "z": "3f30ea31.da3756",
       "name": "",
       "topic": "Esp1BMP280Pressure",
       "qos": "2",
       "broker": "c2e0624.6088ea",
       "x": 161,
       "y": 1605,
       "wires": [
           [
               "6f1e8f4b.0d7e6"
           ]
       ]
   },
   {
       "id": "c2e0624.6088ea",
       "type": "mqtt-broker",
       "z": "",
       "broker": "10.10.10.1",
       "port": "1883",
       "clientid": "",
       "usetls": false,
       "compatmode": true,
       "keepalive": "60",
       "cleansession": true,
       "willTopic": "",
       "willQos": "0",
       "willPayload": "",
       "birthTopic": "",
       "birthQos": "0",
       "birthPayload": ""
   }
]