Non-Volatile memory/storage

#1

Been having good success working with Node Red, implementing our prototype.

One of the last obstacle is the data storage.
We have some User Inputs that are periodically updated.
The data is then used to update the User Interface.

During power down/and power up, the data is lost. ( no surprise)

What is the simplest way to store the data into non-volatile memory and read back in the data after re-powering? SD card has plenty of space and we don’t read/write too often.

The size of the data is very small less than 1KB.

perrused the forum and found these 2 as reference. Any suggestions based on past experience?
1.node-red-contrib-persist
2.sql lite

#2

Well … one is file based and one is a database… Both work fine. For simple objects the persist is probably simpler to use - the database has the advantage that you could potentially do more query like readback of the data.

Also as part of 0.19 (next) release we are looking to add context persistence to the core. The work in progress is here https://github.com/node-red/node-red/wiki/Design:-Persistable-Context

#3

If you are using MQTT then another option is to save it in retained topics there.

#4

Colin - only if you set up persistent storage for MQTT and send all your message QOS1 etc… - maybe fine if MQTT is already part of the equation - but probably not worth adding just to do this.

#5

I agree, that’s why I said it would be an option if he was already using MQTT.

#6

Thank you.
I did look at an ‘example’ flow that stored example data to a file.
SAVE to file
RESTORE from file.
THis works.
However, the data /file is lost once the Raspberry Pi is re-powered.
What I am seeking is for the data to be stored in non-volatile memory so the data is recovered after power cycling.

THe sample flow referenced is here:

[{“id”:“21659e97.4c6f92”,“type”:“ui_button”,“z”:“6a1ea64e.004278”,“name”:"",“group”:“11c99bf.8379964”,“order”:2,“width”:“2”,“height”:“1”,“passthru”:false,“label”:“Inject”,“color”:"",“bgcolor”:"",“icon”:"",“payload”:"",“payloadType”:“str”,“topic”:"",“x”:370,“y”:180,“wires”:[[“e4f211c1.bd8b2”]]},{“id”:“20d44cd4.b8dd34”,“type”:“ui_button”,“z”:“6a1ea64e.004278”,“name”:"",“group”:“11c99bf.8379964”,“order”:4,“width”:“2”,“height”:“1”,“label”:“restore”,“color”:"",“bgcolor”:"",“icon”:"",“payload”:"",“payloadType”:“str”,“topic”:"",“x”:370,“y”:480,“wires”:[[“266496d9.4d8b5a”]]},{“id”:“e4f211c1.bd8b2”,“type”:“random”,“z”:“6a1ea64e.004278”,“name”:"",“low”:“0”,“high”:“10”,“inte”:“true”,“x”:520,“y”:180,“wires”:[[“c200a003.17cd3”]]},{“id”:“c200a003.17cd3”,“type”:“ui_chart”,“z”:“6a1ea64e.004278”,“name”:"",“group”:“11c99bf.8379964”,“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”:670,“y”:180,“wires”:[[“38d76785.2f7f78”],[]]},{“id”:“ac834461.3265a8”,“type”:“file”,“z”:“6a1ea64e.004278”,“name”:"",“filename”:"/tmp/chart.log",“appendNewline”:true,“createDir”:false,“overwriteFile”:“true”,“x”:820,“y”:340,“wires”:[]},{“id”:“266496d9.4d8b5a”,“type”:“file in”,“z”:“6a1ea64e.004278”,“name”:"",“filename”:"/tmp/chart.log",“format”:“utf8”,“sendError”:true,“x”:520,“y”:480,“wires”:[[“d35e5595.a7f9e8”]]},{“id”:“38d76785.2f7f78”,“type”:“json”,“z”:“6a1ea64e.004278”,“name”:"",“property”:“payload”,“action”:"",“pretty”:false,“x”:810,“y”:180,“wires”:[[“27a29310.f3cf8c”]]},{“id”:“d35e5595.a7f9e8”,“type”:“json”,“z”:“6a1ea64e.004278”,“name”:"",“property”:“payload”,“action”:"",“pretty”:false,“x”:670,“y”:480,“wires”:[[“c200a003.17cd3”]]},{“id”:“27a29310.f3cf8c”,“type”:“function”,“z”:“6a1ea64e.004278”,“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”:550,“y”:340,“wires”:[[“ac834461.3265a8”]]},{“id”:“be7b76c5.eacf58”,“type”:“ui_button”,“z”:“6a1ea64e.004278”,“name”:"",“group”:“11c99bf.8379964”,“order”:3,“width”:“2”,“height”:“1”,“label”:“save”,“color”:"",“bgcolor”:"",“icon”:"",“payload”:"",“payloadType”:“str”,“topic”:“save”,“x”:370,“y”:340,“wires”:[[“27a29310.f3cf8c”]]},{“id”:“11c99bf.8379964”,“type”:“ui_group”,“z”:"",“name”:“Gauge”,“tab”:“52c8e093.d2037”,“order”:2,“disp”:true,“width”:“6”},{“id”:“52c8e093.d2037”,“type”:“ui_tab”,“z”:"",“name”:“Restore”,“icon”:“dashboard”}]

#7

Well yes. As the example only saved things in /tmp/ directory as I didn’t want to mess up people’s disks. And that is actually in memory so is wiped on boot. Just pint it somewhere on your sd card

#8

HI Thank you and that makes sense.
How do I go about writing the data Onto the SD card?

I imagine you create the file in the /.node-red directory
myData.log

any examples?

#9

well better not in the .node-red directory - keep them separate - maybe /home/pi/backup/myData.log
(create the directory first outside of node-red.

mkdir -p ~/backup
#10

THank you. That did work.
Hope this will help others that are trying to log and save some data to SD card for non-volatile storage.