Think of it as sawing off the branch you're sitting on. There are USB output boards (like SunControl) that can be directed via GPIO pins to switch off the USB load. However that would result in a power cut, not a clean shutdown. And since the "off" command came from the client that is now, eh, off, there is no real way to "on" it again, ever.
Which leaves the battery voltage monitoring. SunControl can cut the USB power when the voltage is going somewhere below 3.43V - unfortunately the exact value is dependent on a lot of external conditions.
So let's say you decide to do an orderly shutdown of the Raspberry Pi at 3.50V. So far so good. Technically the Pi will still draw power even in that state, eventually draining the battery below 3.43V and triggering the Hysteresis circuit on the SunControl and cutting the USB. Given enough charge at some point that circuit will trigger again, re-enable the USB and start up the Pi.
But you can already see the dilemma - What if you shut down the Pi at 3.5V and then all of a sudden the sun comes blasting and the battery voltage recovers. USB power will stay on , hysteresis will not trigger, and the Pi will continue to be in the shutdown state.
I think what this calls for is a Real Time Clock (RTC) addition to the Pi. PaPiRus have ePaper hats that have a RTC and a pogo pin to revive the Pi host at a given time, assuming the Pi is in shutdown state and that it still has power.
So you would modify your routine to shutdown the Pi at 3.5V, but before that you set a timer for , let's say 1 hour (basically enough time to drain the battery for another 70 mV) to reset the Pi. If the battery did recover during that time the Pi will wake up again. If the battery drained, the hysteresis will have kicked in, cut the USB power, and the RTC circuit would have no target to revive.
One more thing - I don't think a watchdog timer plays a big role here - it is only useful when the Pi crashes, not when needs to be woken up from sleep.
Last Edit: Jan 16, 2019 10:39:42 GMT -8 by lbendlin
You are quite correct about how we use the USB PowerControl to shutdown on a low voltage condition. The Watchdog timer does handle your other situation.
The WatchDog timer handles the situation where the Pi has shutdown and the sun kicks up by turning off the USB PowerControl which then the Hysterisis on the USB PowerControl keeps the Pi off until the battery has recovered.
Ah, that makes so much more sense. I always thought that the watchdog would initiate a power cycle of a (supposedly crashed) Pi. But if the watchdog can be made to only switch off the load after the Pi had completed its shutdown and is no longer patting the dog, then that is indeed safe.
I guess this then moves closer to my other topic ("Give hysteresis another chance") as you might be wasting valuable operating time by waiting for the battery to reach 3.9V. I still haven't figured out the full impact of "sun pressure" on the battery voltage reading but from my data it looks like roughly 0.15V difference between no sun and full sun.
It will do that also! Either way. If the Pi crashes above the battery 3.9V, it will just reboot.
You need hysteresis in this system. What happens is say your battery gets to 3.6V and the Pi turns on. The voltage on the LiPo will go down (the pi is now running), and will take the voltage down below the 3.4V and you get into this up and down cycle. On / Off On / Off and bye-bye SD card.
The "sun pressure voltage" makes sense to me. The voltage on the battery will be a little higher when it is charging.
Not perfect, but relatively close to what I think the real voltage is.
The chart shows the participating components as a zero sum game (incoming energy = outgoing energy) for a day period. O is output wattage, W is waste wattage, loadc is the corrected voltage on the battery. Idle consumption (overnight) is about 500 mW.
Last Edit: Jan 18, 2019 18:26:38 GMT -8 by lbendlin