Restore graph data from file

This is just an example how to recover data on a bar graph series in case of system restart.

The data coming from the graph is saved on a file as plane text overwriting the file each time some data comes in, after deploy/restart a inject node pull the data out from the file as a single utf8 string, this is converted on a comprehensible json format with a json node in order to be injected back as input on the grafh.

[{"id":"36376376.60e15c","type":"file in","z":"672f86c.9361b78","name":"consumo_diario","filename":"/home/pi/.node-red/datalog/consumo_diario","format":"utf8","chunk":false,"sendError":false,"x":900,"y":1680,"wires":[["a8965144.7220d"]]},{"id":"d909fcca.65a81","type":"inject","z":"672f86c.9361b78","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":true,"x":730,"y":1680,"wires":[["36376376.60e15c"]]},{"id":"15d62950.8cae67","type":"inject","z":"672f86c.9361b78","name":"delete","topic":"","payload":"[]","payloadType":"json","repeat":"","crontab":"","once":false,"x":1070,"y":1740,"wires":[["9225d2ed.92e52"]]},{"id":"f2947442.120f78","type":"file","z":"672f86c.9361b78","name":"consumo_diario","filename":"/home/pi/.node-red/datalog/consumo_diario","appendNewline":true,"createDir":true,"overwriteFile":"true","x":1440,"y":1640,"wires":[]},{"id":"9225d2ed.92e52","type":"ui_chart","z":"672f86c.9361b78","name":"KwhxD","group":"2ebc9347.9cd16c","order":12,"width":0,"height":0,"label":"Kwh x Dia","chartType":"bar","legend":"false","xformat":"D/M","interpolate":"step","nodata":"iddle","dot":false,"ymin":"","ymax":"","removeOlder":"60","removeOlderPoints":"","removeOlderUnit":"604800","cutout":0,"useOneColor":true,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":1280,"y":1640,"wires":[["f2947442.120f78"],[]]},{"id":"a8965144.7220d","type":"json","z":"672f86c.9361b78","name":"","pretty":false,"x":1090,"y":1680,"wires":[["9225d2ed.92e52"]]},{"id":"42ddb124.b6f4a","type":"inject","z":"672f86c.9361b78","name":"","topic":"","payload":"10","payloadType":"num","repeat":"","crontab":"","once":false,"x":910,"y":1600,"wires":[["2f09b266.d62cee"]]},{"id":"f4b8e15c.3929","type":"inject","z":"672f86c.9361b78","name":"","topic":"","payload":"20","payloadType":"num","repeat":"","crontab":"","once":false,"x":910,"y":1640,"wires":[["e264b92.bdba048"]]},{"id":"2f09b266.d62cee","type":"change","z":"672f86c.9361b78","name":"","rules":[{"t":"set","p":"label","pt":"msg","to":"Jan","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1050,"y":1600,"wires":[["9225d2ed.92e52"]]},{"id":"e264b92.bdba048","type":"change","z":"672f86c.9361b78","name":"","rules":[{"t":"set","p":"label","pt":"msg","to":"Feb","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1050,"y":1640,"wires":[["9225d2ed.92e52"]]},{"id":"2ebc9347.9cd16c","type":"ui_group","z":"","name":"Consumo","tab":"49f882f0.c51aec","order":1,"disp":true,"width":"6"},{"id":"49f882f0.c51aec","type":"ui_tab","z":"","name":"CONSUMO","icon":"fa-plug","order":10}]
davidcgu

Flow Info

created 10 months, 2 weeks ago

Node Types

Core
  • change (x2)
  • file (x1)
  • file in (x1)
  • inject (x4)
  • json (x1)
Other
  • ui_chart (x1)
  • ui_group (x1)
  • ui_tab (x1)

Tags

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