Restart Node Red if no data received from NCD modem

Hello,
I am using Node-Red with a network of NCD sensors which communicate with a NCD Wireless to Ethernet modem. All works well except when our plant experiences a power outage. Node-Red is on a virtual machine and remains running even when the power goes down.

After a power outage the only way to start receiving data again is to restart Node-Red.

The only thing I can guess is happening is there must be a few milliseconds between the power going out and the battery kicking in for the Wireless to Ethernet modem which causes a timeout error. Everything including the modem is plugged into a battery backup.

Is there a way I can reset the Node-Red gateway after data is not received for a period of time, say 15 minutes? I've spent quite a bit of time searching for a similar issue in the forums and haven't been able to find anything.

Thank you!

You should first determine what exactly is not restarting. If you don't know then it may well be an issue with your flows not coping with the situation.

However if you don't want to do that then you can use a Trigger node fed by the data being received. Set it to Send Nothing then after 15 minutes to trigger the reset. Also select Extend Timeout. The result is that it will send nothing unless there is a 15 minute gap in the data.

Thanks for the advice, Colin. I'll try that out.

Hello, I was taken off of this for a few days. Here is where I currently am:

The flow:

This is the 'watchdog' trigger set up as Colin suggested. It does work.

My question is what do I send to the Exec node and get it to reboot the PC?

EXECNODE

I have also tried sending the string 'shutdown /r' from the trigger, leaving the command blank on the exec node and checking the Append msg.payload checkbox.

Many thanks!

I thought you wanted to restart node-red. That has been discussed a number of times so a forum search should help. Similarly rebooting has been discussed before so a forum search should find that too. Basically in either case you have to use whatever command you use in a terminal to restart or reboot. Depending on what OS you are using there may be permission issues to get it to run from within node-red.

If you want to use shutdown -r then you need to use sudo, probably. And will then need to use visudo to allow the user running node-red to execute that command without entering a password.

OK thanks. The pc is set up to autologin and then launch node-red using a batch file. So if I'm understanding you correctly I should enter sudo shutdown -r in the Command box of the exec node? Sorry for being so dense. I've been searching on here and Google all day and just haven't found anything that fits what I'm hoping to accomplish.

So any message that the trigger node sends to the exec node will fire the shutdown -r command?

Thanks for your help, it is appreciated.

Provided that if you login as the user running node-red and run that command then it does what you want. But if it asks for a password when you do that then you will need to sort that before node-red will be able to run it (as node red can't enter the password).

1 Like

Thanks for bearing with me Colin, it seems to be working now. Couldn't have done it without you. Thanks again!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.