I have tried all the software watchdog solutions and they helped, but there was still scenarios that could stop it from running. My first solution was a Wifi controlled USB relay connected to the pi power so I could switch it off and on remotely using the smartlife app. but this still required me to notice that something was wrong usually when i couldnt log in.
So this got me thinking on how I could use a esp32 chip to reboot the pi if it stopped responding, to implement it I knew I needed to do some kind of command and response system. first idea was to just use a esp32 to ping the pi, so if it stops responding it reboots but it could reply to pings without being operational.
So the next idea was to make a switch on domoticz, change it and then check for the change, if its not in the position its supposed to be in then it reboots. this worked but there wasnt a direct connection from the pi to the esp32, any network issues would cause it to reboot the pi constantly as it would block the response.
the next idea was to wire it directly to the pi GPIO, this way it wont be effected by network issues. I used the domoticz guide https://www.domoticz.com/wiki/GPIOto set one pin and an input and another pin as an output. I used gpio 17 and 27 for in and out.
I then made a basic blockly script that sets the output pin high if the input pin is high
I then made a script using the espeasy rule set that changes a switch, checks that its moved, if it has then it resets and tries again in 10 minutes if not then it reboots.
you could easily just use any arduino board to do this, i just used esp32 and espeasy because i had it there, but it doesnt need network access to work as its just checking pin states.
pin 5 is connected to the PI4 Global_En pin to reset
pin 7 is connected to gpio 17 on the pi
pin 6 is connected to gpio 27 on the pi
Code: Select all
On System#Boot do //When the ESP boots, out low and reset high
gpio,7,0
gpio,5,1
timerSet,1,600 //wait for 10 minutes after boot to check startup
endon
On Rules#Timer=1 do //send pulse to PI
gpio,7,1
gpio,8,0 //turn on esp32 led
timerSet,2,10 //wait 10 seconds for reply
endon
On Rules#Timer=2 do
if [receivepulsepin#State]=1 //if response is correct
gpio,5,1
gpio,7,0
gpio,8,1 //turn off esp32 led
timerSet,1,600 //wait for 10 minutes
else //if response incorrect
gpio,5,0 //reset pi
gpio,7,0
timerSet,3,5 //wait 5 seconds
endon
On Rules#Timer=3 do //restart counter
gpio,7,0
gpio,5,1
timerSet,1,600 //wait for 10 minutes
endon