I've been extending a weather station / webcam we have here at our model flying field. It has now an Arduino gathering the weather data and starting the Pi in a specific time interval (5 or 10 minutes). In normal cases, the Pi just makes a picture, gather the weather data and uploads the whole package to a web site.
The Pi's power supply is provided by 5v GPIO using a MOSFET on the 5v rail. The Arduino can detect as well if the Pi has shut itself down by using the gpio-poweroff overlay, which allows it for turning the 5v supply off after shutdown.
There is as well a shutdown trigger on another GPIO which allows the Pi to be forced down. A python script is watching this trigger, started from within the rc.local.
And last but not least, there is a set of flags that can be set either by serial console on Arduino or by sending a short message to the Pi's 3G modem to enable things like 'maintenance mode', which basically leaves the Pi on and starts a Wifi access point to which we can login. When the Pi shuts down, it automatically leaves this maintenance mode (all flags are written to tmpfs), and on next start triggerd by the Arduino, everything is back to normal.
All this works like charm. But in case we forget to shutdown the Pi, or if, for whatever reason, we are locked out and cannot turn it down, it gets shutdown after 30 minutes.
Now, what if something crashes on the Pi, or whatever reason, and the gpio-poweroff never triggers? I'd like to have a maximum up-time on Arduino that would basically switch off the Pi, now matter what. This is all very easy to code.
But now, how do I detect that the Pi has been just cut from the power supply, rather than normally shutdown? I could, of course, keep this information in the Arduino and try to communicate it to the Pi, which in turn would mail someone, or any other kind of notification (text message would be nice as well).
However, I think this turns rather complex and leaves many points of failure. I'd rather have a simple way on the Pi to detect that it's power supply has been cut without a correct shutdown. The Pi is running raspbian jessie, and the firmware is kept up to date with rpi-update.
I'd be thankful for any pointer in the right direction.