How to reboot raspi from NR

Hi!
I have a raspi (Raspberry Pi 3 Model B Plus Rev 1.3, Debian Linux 12 says webmin) in my greenhouse running NR 4 locally. The pi is on my network using wifi. From time to time the pi loses the connection. I also have shellies in the greenhouse, they just work all the time.
I could (and should) figure out why the wifi connection drops occasionally with the pi (but not with the shellies) but in the meantime I could just restart the raspi.
I am not that of a linux guy, there seems nothing related to be in the forum.

  • NR can ping the remote server, this may fail
  • NR can detect the change of availability of the remote MQTT server, how does one detect that?
  • NR should gracefully reboot the pi - how can this be done? Doesn't that need root/admin power?
    Any idea how to find out why wifi drops? (btw: I tried powerline/cable, this was too flaky)
    Thanks in advance!
    Cheers, Uwe

You can try it with the exec node.

sudo reboot in the exec node did it.

1 Like

The Raspberry Pi has a hardware watchdog which can be setup to reboot the Pi if network access is lost or other services are unavailable.

There is a write-up at https://diode.io/blog/running-forever-with-the-raspberry-pi-hardware-watchdog

1 Like

Just attach whatever you need to trigger it to this node.

[{"id":"5beb96fc1c9e261b","type":"exec","z":"edce5f4c305a1484","g":"ed28e8ce3fc4343a","command":"node-red-restart","addpay":"payload","append":"","useSpawn":"true","timer":"","winHide":false,"oldrc":false,"name":"","x":800,"y":760,"wires":[["45e59a0a450bfdd5"],["45e59a0a450bfdd5"],["45e59a0a450bfdd5"]]}]

If you try it with other Linux distributions you will likely need to do:

sudo visudo
# add after the last line of the file (#includedir /etc/sudoers.d):
YourUserName ALL=(ALL) NOPASSWD:ALL

The Pi has come with this as the default from the beginning unless it has been changed in the newer versions. Generally a very bad idea to have this set on a system that is used with the external Internet.

Don't do that, that allows node red (or any user) to run sudo with any command, without entering a password. Limit it to only the user and command that you want to allow, so if the user is, for example, pi then use
pi ALL=(ALL) NOPASSWD: /sbin/reboot

1 Like

That would seem to be a much better option, but the Raspbian OS has come setup as I'd described by default pretty much since day one. Maybe they have changed it in newer releases for the more powerful systems that people might use as actual desktops, but I've not done anything with a Pi for a couple of years now.

Can you add multiple commands to the list or add multiple lines? Being able to Power Down as well as reboot is useful for headless systems.

Both. You can add multiple lines, and/or allow multiple commands
pi ALL=(ALL) NOPASSWD: /sbin/reboot, sbin/shutdown

2 Likes

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