Recently I had an issue with NodeRed that caused the NodeRed process to sometimes crash.
Actually it's not that bad since it restarts automatically. On the other hand, it annoyed me at some point because the data in the dashboard view was lost and status messages were sent every time.
Es war also an der Zeit der Sache auf den Grund zu gehen. Dabei habe ich zunächst das journal des NodeRed services vai „sudo journal -f -u nodered“ geprüft.
This command displays all status messages stored in the service's journal. But I was actually only interested in the last reports before NodeRed was restarted.
Dazu habe ich mir den unten gezeigten Flow erstellt. Dieser speichert jedes Mal nach dem Neustart von NodeRed den Inhalt des Journals im Ordner „/home/pi/nodeRedLogFiles“.
If you are looking for an error that leads to a restart, you should find it quickly. 🙂
Safety instructions
I know the following notes are always kind of annoying and seem unnecessary. Unfortunately, many people who knew "better" have lost eyes, fingers or other things due to carelessness or injured themselves. Data loss is almost negligible in comparison, but even these can be really annoying. Therefore, please take five minutes to read the safety instructions. Because even the coolest project is not worth injury or other trouble.
https://www.nerdiy.de/sicherheitshinweise/
Affiliate links/advertising links
The links to online shops listed here are so-called affiliate links. If you click on such an affiliate link and make a purchase via this link, Nerdiy.de will receive a commission from the relevant online shop or provider. The price does not change for you. If you make your purchases via these links, you support Nerdiy.de in being able to offer other useful projects in the future. 🙂
Requirements
Helpful articles:
So that you can install new nodes, NodeRed should of course already be installed.
How to prepare a RaspberryPi and then install NodeRed on it is described in the following articles.
The following three articles describe what needs to be done to prepare the RaspberryPi:
RaspberryPi – setup for nerdiys!
RaspberryPi – The first configuration!
RaspberryPi – Control the RaspberryPi via SSH
NodeRed – Installing NodeRed on the RaspberryPi
Required tool:
-no-
Required material:
In the following list you will find all the parts you need to implement this article.
Log into the NodeRed configuration interface
Before you can edit your NodeRed configuration, you must - if activated - first log into the NodeRed configuration interface.
Import node code
To test this code you can simply import the code below into your NodeRed installation. You can find tips on this in the article NodeRed - import and export node code.
[{"id":"185f8c16.a86d64","type":"exec","z":"2dcf0cc0.aeb894","command":"journalctl -u nodered -all","addpay":false,"append":"","useSpawn":"true","timer":"","oldrc":false,"name":"last","x":410,"y":3480,"wires":[["30e6e36b.45d3fc"],[],[]]},{"id":"30e6e36b.45d3fc","type":"function","z":"2dcf0cc0.aeb894","name":"prepare filename","func":" var d = new Date(); var t = d.getTime(); var year = d.getFullYear(); var month = d.getMonth()+1; var day = d.getDate(); var hour = d.getHours(); var minute = d.getMinutes(); if(month.toString().length == 1) { month = '0'+month; } msg.filename = "/home/pi/nodeRedLogFiles/nodeRedLog_"+day+"-"+month+"-"+year+"-"+hour+":"+minute+".csv"; return msg;","outputs":1,"noerr":0,"x":610,"y":3480,"wires":[["9f916f6c.d00cb"]]},{"id":"519cb1ab.0032b","type":"inject","z":"2dcf0cc0.aeb894","name":"save last nodered-journal","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":210,"y":3480,"wires":[["185f8c16.a86d64"]]},{"id":"9f916f6c.d00cb","type":"file","z":"2dcf0cc0.aeb894","name":"","filename":"","appendNewline":true,"createDir":true,"overwriteFile":"false","encoding":"none","x":810,"y":3480,"wires":[[]]},{"id":"510d4143.de0cb","type":"comment","z":"2dcf0cc0.aeb894","name":"Save last journal nodered","info":"","x":170,"y":3420,"wires":[]}]
Dashboard view
View of collected NodeRed journals
Im Ordner „/home/pi/nodeRedLogFiles“ auf Eurem RaspberryPi findet Ihr nach einem Neu Start von NodeRed dann die gespeicherten NodeRed-Logs.
Have fun with the project
I hope everything worked as described for you. If not or you have questions or suggestions please let me know in the comments. I will then add this to the article if necessary.
Ideas for new projects are always welcome. 🙂
PS Many of these projects - especially the hardware projects - cost a lot of time and money. Of course I do this because I enjoy it, but if you think it's cool that I share the information with you, I would be happy about a small donation to the coffee fund. 🙂