Restart Node-Red to reset tcp in node connection

Hello I'm working on a prototype project and I have a sensor sending data to Node-Red through a tcp connection. Sometimes I lose connection to the device and cant receive data. The easy thing to do that works is just to restart Node-Red. However, I would like to restart automatically or just restart at 30-60 minute intervals.
Is there a way to automate restarting Node-Red? Until I can fix the serial connection restarting Node-Red would be helpful for now. Thank you in advance.

Assuming it's running on a Linux platform, I'd try an exec node, running "Sudo systemctl restart nodered". It would be interesting to see if that works... If it hangs, you might be forced to SSH into the machine and reboot it, though, as any watchdogs you have running in NR will cease to run.

I just went through this, and found that to make sudo work in the exec node, you have to give nodered the permission to act as sudo...this will reduce security if that's a concern to you.

In Ubuntu, you add the username nodered is running under to /etc/sudoers.d. Some tutorials might indicate that the username is nodered, but it will be whatever you specified, IE, whatever you log in with and ran the NR setup script as.
There's some text and a file to add, but I can't give you the clear details right now. That should be a good start to find it on google, I hope. It might be the same on a Pi, but I haven't tested yet. I vaguely remember sudo just working on a Pi running nodered a long time ago.

I did this on a machine running at my dad's, far from home, to allow Nodered to change the system's default routes and restart VPN in an ISP outage.

1 Like

Just another thought...this solution seems like whacking a nail with a sledgehammer.

Have you dug into the websocket node documentation to see if it can be restarted/reset alone? Or possibly send the connection parameters by a message, so you can periodically send a message that clears the connection path, then restores it. Just a thought as I'm running out the door, but might be more reliable to restart the node alone.

1 Like

TCP request supports msg.reset. Have you tried it?

1 Like

Thank you for the suggestions, they are much better than restarting NR.