Skip to content

Instantly share code, notes, and snippets.

@dceejay
Created December 12, 2016 22:02
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dceejay/92920b4fd450bf92a3035e061947daa0 to your computer and use it in GitHub Desktop.
Save dceejay/92920b4fd450bf92a3035e061947daa0 to your computer and use it in GitHub Desktop.
Simple save and restore for node-red-dashboard chart

The Node-RED Dashboard chart has an output that outputs the state of the current chart.

This can then be saved to permanent storage, and restored at will.

This flow has three buttons

  • The first injects random numbers to create a chart.
  • The second does a simple save to a file - currently set to /tmp/chart.log
  • The third does a restore of the saved file.

More typically the file out node would be replaced by a save to a database, and the file in node would be a database query.

[{"id":"4679091.0341ff8","type":"ui_button","z":"89b47660.0ba428","name":"","group":"212b7f06.b4731","order":2,"width":"2","height":"1","label":"Inject","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"","x":90,"y":60,"wires":[["63911393.d1513c"]]},{"id":"fa4f25b6.ea4048","type":"ui_button","z":"89b47660.0ba428","name":"","group":"212b7f06.b4731","order":4,"width":"2","height":"1","label":"restore","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"","x":90,"y":360,"wires":[["9b9cfb63.2f50f8"]]},{"id":"63911393.d1513c","type":"random","z":"89b47660.0ba428","name":"","low":"0","high":"10","inte":"true","x":240,"y":60,"wires":[["9e4c2fd0.aac16"]]},{"id":"9e4c2fd0.aac16","type":"ui_chart","z":"89b47660.0ba428","name":"","group":"212b7f06.b4731","order":1,"width":0,"height":0,"label":"chart","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"bezier","nodata":"","ymin":"","ymax":"","removeOlder":"15","removeOlderPoints":"100","removeOlderUnit":"60","cutout":0,"x":390,"y":60,"wires":[["ef3ff83b.aa5008"],[]]},{"id":"8f316ad0.85cdd8","type":"file","z":"89b47660.0ba428","name":"","filename":"/tmp/chart.log","appendNewline":true,"createDir":false,"overwriteFile":"true","x":540,"y":220,"wires":[]},{"id":"9b9cfb63.2f50f8","type":"file in","z":"89b47660.0ba428","name":"","filename":"/tmp/chart.log","format":"utf8","x":240,"y":360,"wires":[["b13ea0c3.a7955"]]},{"id":"ef3ff83b.aa5008","type":"json","z":"89b47660.0ba428","name":"","x":530,"y":60,"wires":[["ef80c15e.8dbc3"]]},{"id":"b13ea0c3.a7955","type":"json","z":"89b47660.0ba428","name":"","x":390,"y":360,"wires":[["9e4c2fd0.aac16"]]},{"id":"ef80c15e.8dbc3","type":"function","z":"89b47660.0ba428","name":"","func":"if (msg.topic === \"save\") {\n msg.payload = context.last;\n return msg;\n}\nelse {\n context.last = msg.payload;\n}\nreturn null;","outputs":1,"noerr":0,"x":270,"y":220,"wires":[["8f316ad0.85cdd8"]]},{"id":"87cc5e2e.b0836","type":"ui_button","z":"89b47660.0ba428","name":"","group":"212b7f06.b4731","order":3,"width":"2","height":"1","label":"save","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"save","x":90,"y":220,"wires":[["ef80c15e.8dbc3"]]},{"id":"212b7f06.b4731","type":"ui_group","z":"","name":"Gauge","tab":"e7f7ff66.2de07","order":2,"disp":true,"width":"6"},{"id":"e7f7ff66.2de07","type":"ui_tab","z":"","name":"Restore","icon":"dashboard"}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment