TL;DR: I am looking for options that will allow me to detect whether an app of the pi and/or the pi itself has been crashed or frozen; And if so, reboot the pi.
I'm working on a hobby project where my goal is to automate the watering of my garden. The water tubing is connected to 12v magnet valves; who then are connected to some relays that i can trigger via the GPIO ports of the raspberry pi. So basically sending a signal on a given time; the relay will power the 12v valve to allow the flow of water.
I wrote a proof of concept program so far in Python that checks every 60 seconds if there is a task in the daily schedule it should execute. The task is basically only a ON statement on a given time, and an OFF statement somewhere later in time (to power GPIO ON/OFF). Additionally im running a small Flask web-server in case i want to sent some manual overwrite commands via my mobile phone. So this is basically the whole concept.
But now it came to mind: what would happen if 1 or more GPIO's are ON and then my program or even the whole Pi would freeze up or crash. In that case the valve would stay open until i would manually reboot the pi. Most likely i would notice once my garden has been turned into some wetlands after some hours... not to think how it will look after some holidays.
So this is where i am thinking what are my options to somehow monitor/detect if the program or the whole Pi has been crashed/frozen, and how could i then force it to reboot.
2 options that i thought of:
A. Get an second device and run the power of the pi trough this device. This device would "ask" to the pi once per hour "are you still alive?" and then the pi should send a response. when there is no response it would kill power for like a minute or so and this way force the pi to reboot. i assume something like this could be done by simply sending a request to the flask webservice im running, but i would need to buy and setup a second device.
B. get a cheap programmable power plug and just switch off power every night at like 00:00 and switch back on at 00:01
So far i am thinking of option B as it is very easy and cheap to setup. But this also brings me here on this page: Are there any other options someone can advice i should consider that i might not be aware off ? I couldn't think of any other myself, but i am hoping someone here may know another option to take into account ?