Skip to content

Instantly share code, notes, and snippets.

@davidcgu
Created December 30, 2017 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidcgu/0591563a8baf507a25e254319291698b to your computer and use it in GitHub Desktop.
Save davidcgu/0591563a8baf507a25e254319291698b to your computer and use it in GitHub Desktop.
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}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment