global variable example

A global variable example: saving and restore value

[{"id":"303a2bf8.6fce74","type":"tab","label":"Flow 3"},{"id":"137af095.019a0f","type":"inject","z":"303a2bf8.6fce74","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"x":196,"y":148,"wires":[["8e75af69.8d1b1"]]},{"id":"d5a12ddd.ff09e","type":"debug","z":"303a2bf8.6fce74","name":"","active":true,"console":"false","complete":"false","x":529,"y":148,"wires":[]},{"id":"8e75af69.8d1b1","type":"function","z":"303a2bf8.6fce74","name":"I set here","func":"context.global.myrandom = \"prova\";\nmsg.payload = \"local payload \";\nreturn msg;","outputs":1,"noerr":0,"x":363,"y":148,"wires":[["d5a12ddd.ff09e"]]},{"id":"63552289.87793c","type":"inject","z":"303a2bf8.6fce74","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"x":263.9999694824219,"y":278.2221984863281,"wires":[["28a72d11.4d31f2"]]},{"id":"ed285a44.391998","type":"debug","z":"303a2bf8.6fce74","name":"","active":true,"console":"false","complete":"false","x":596.9999694824219,"y":278.2221984863281,"wires":[]},{"id":"28a72d11.4d31f2","type":"function","z":"303a2bf8.6fce74","name":"I show here","func":"msg.payload = \"Global value=\" + context.global.myrandom;\nreturn msg;","outputs":1,"noerr":0,"x":430.9999694824219,"y":278.2221984863281,"wires":[["ed285a44.391998"]]}]
cman2016

Flow Info

created 2 months, 2 weeks ago

Node Types

Core
  • debug (x2)
  • function (x2)
  • inject (x2)
Other
  • tab (x1)

Tags

  • global
  • variables
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option