Node Red Script

imageNow that I’m back in the UK, I’ve left a Raspberry Pi2 in Spain monitoring my solar pergola lighting installation as an ESP8266 measures the state of a solar-charged car battery every 15 minutes and reports minimum and maximum voltages daily by email. The unit also controls lighting and while not actually controlling heating, has a test setup which controls a Nextion display. Meanwhile I have a similar setup here in the UK which is actually connected to a Nextion and which will soon be in charge of the household heating.

But something has been bugging me. Regular readers will know that during the last month or so in Spain I had a lot of WIFI issues, pretty much resolved now thanks to the help of you readers – and in that time until I got to the bottom of it all I spent a lot of time improving my ESP8266 boards to the point where I recently took off the last-ditch reset-the-board option as they are working utterly reliably even in the face of rubbish electricity and the WIFI issues.

In a recent development I decided that in the unlikely event of another power cut (turns out not as unlikely as I’d hoped) I’d have Node-red send me an email on startup.

Well, once a day I was getting these, usually around 11am or so. The unit in the UK was slightly different but still generally resetting in the morning. I wrote off to the guys in the Node-Red Google group – they’re really very helpful and they asked me to check using PM2 some things.

Turns out PM2 (process manager) is a lot more powerful than I’d given it credit for. Anyway I sent the guys a copy of my script or rather the part that starts Node-Red and puts it into a service to run after powerup. It goes like this…

cd /root
pm2 start /usr/bin/node-red -- -v
pm2 save
pm2 startup

The first line is probably irrelevant but I tend to do that a lot to avoid surprises. Anyway, I’ve used this from day 1. I’d sent an example log and one of the things in the log was logging of a LED I toggle off once a second in a simple indicator. I did comment that I thought it was a bit daft logging that every second.

One of the guys in the Google group (Dave) asked me why I was using verbose mode for Node-Red and don’t you know – I spotted the “-v” in my script. How that got in there I’ve no idea.

Anyway to cut a long story short, I needed to scrap that service and create a new one without the –v for verbose.

pm2 list

The above line shows list of services running under PM2 – turns out only one – service 0 so…

pm2 delete 0

got rid of if which allowed me to start again…

cd /root
pm2 start /usr/bin/node-red
pm2 save
pm2 startup

So now I have Mode-red running on both machines (since last night) without the verbose logging. I should stress I made absolutely NO other changes.  Now bearing in mind that my total work on these Pis is using a couple of percent of processor power typically and maybe 50% of the RAM…. let me throw this at you…

Since restarting the services without verbose mode last night – and bearing in mind it is now 4:30 pm the next day – NEITHER of the Node-Red installations has rebooted yet both have sent in their daily battery state email reports.

There is time yet of course – I may be going off on a complete tangent – but it does seem odd that simply removing verbose logging would stop regular Node-Red reboots!

Update 21:00:00 Wednesday – oh, well, I just had an email from the local Pi to say Node-Red has reset itself. Sigh.

Facebooktwittergoogle_pluspinterestlinkedin

5 thoughts on “Node Red Script

  1. Hi Peter,

    Thanks for this. I have been having the same problem. I'm testing out mqtt on the esp12 and also Blynk. To cut a long story short I get an email from Node-Red when Blynk stopped responding. I then created a flow to restart Blynk. But that never came back only a reboot would solve it. I found out this morning that restarting Node-Red brought Blynk back.

    So see this post of yours, I too have the -v option. I can only assume it's part of the setup documented elsewhere.

    Regards

    Paul

    1. Well, still no failures since I stopped the -v option. Mind you I did notice an issue with the BLYNK server, one of the Blynk projects (identified by a unique key) had stopped (I have 2 as I ran out of virtual buttons). Not sure how that is even possible. A reboot of the PI sorted that but I'm disappointed it happened - the Mobile App seemed oblivious. I need to come up with something to monitor Blynk projects... this has only happened once but I'd rather it had not happened at all.

  2. Hi Peter,

    I am just starting with Node-Red...... hadn't heard about it until I loaded up the latest Raspian image.

    What I am after with a very big please !!! Is there any chance of you exporting your flows and making them public so I can work my way through the work you have done in order to gain some understanding. I have watched your YouTube video "https://www.youtube.com/watch?v=xoQ_Fs31xtM&ab_channel=PeterScargill" which has helped a lot but I am sure a read of your function scripts and a look at node parameters would get me a lot further.
    I have done a bit of programming in php and C as well as played around with a few microcontrollers but Javascript is new to me and I think I need a few pointers.

    Kind regards

    Chris Bussey

  3. Hi Peter,
    I'm not sure if this is still a problem but since you originally also had the '-v' in your job it looks like at some point you've read this document: http://nodered.org/docs/getting-started/running.html#starting-node-red-on-boot

    The problem with it is they describe starting on a regular linux box.
    If you experience problems with node resetting itself you should probably try to use the Pi-sanctioned version:

    pm2 start /usr/bin/node-red --node-args="--max-old-space-size=128" --

    It will hint node.js at which point it would be wise to start freeing old/unused memory and not get killed by OOM.

    1. Hi

      I don't think I bothered with the max-old-space because I'm not using a Pi, I'm using a Pi2 which has twice the amount of RAM - i.e. 1 gig. I'm no longer getting node-red restarts but thanks a lot... turns out it was duff code running once a day... just getting the odd BLYNK node failure now and discussing that with the author.

Comments are closed.