MightyHat power outage alert and auto restart?

Started by Tony Weil, April 20, 2018, 01:20:43 AM

Tony Weil

I'll give your suggestion a try.

Do I really care why the Pi was shut down? I was thinking all I needed to do was have the Pi startup whenever the 328p starts up. Your solution is more elegant.

Felix

Tony,
You mean an unconditional Pi-power-ON when USB power is available?
If I was able to run the Pi up to 2-3 hours on a small LiPo battery, I don't see why you can't do the same or more on your UPS, assuming the power outage will not last for days.
I always take the easy route. I don't have any fancy startup algorithm on my MHat, it's the stock firmware, the LiPo backup is enough to keep it going through any regular outage.

Tony Weil

Felix,

To keep it simple, I was suggesting unconditional Pi Power On whenever the Pi Hat (Atmel 328p) boots up, regardless of how it is powered, Lipo or USB.

As you suggested, to keep it even simpler, I just ordered a UPS (900VA for Pi and other small equipment) and already have 2 hours worth of 2000mAh Lipo backup on the PI Gateway.

This will also help solve an additional silly failure mode other than power outage. I like to keep my Pi Gateway in my funky "Michigan" basement lab that is run by a number of extension cords strung across the basement ceiling. Very occasionally, the cords get accidentally disconnected without my realizing it. Now, the UPS should start beeping if that happens and I'll know to check the power. cords. I suppose I could have added a beep to the Pi Gateway if there was no USB power. Maybe it is time to move the Pi Gateway to a safer place or add some real electrical outlets?? ;)

Thanks a lot,

Tony

Felix

Unconditional power ON is fine, I think most people might not prefer that though. Does your TV, PC or some other device automatically turn ON when plugged in? Maybe a router or simple device would, but not a PC for instance. I think for that reason the stock firmware will stay as is and will require user intervention to power back on.

The LiPo backup provides a means to keep it ON and it's only limited by the LiPo capacity. An external UPS will further limit the case where it reaches power off.

Inherently the design was made so that the MHat keeps going, and only shuts off if the backup power is depleted, which I've never encoutered since I use mine, and I only have the 1 LiPo backup attached to it without external UPS. I also live in Michigan, just east of you I believe ;)

But the change to power ON when 328 starts is pretty easy (not tested pseudo code):

Add this code at the end of setup:

PowerState = ON;
POWER(PowerState);

Tony Weil

Thank for all the good info, Felix. I'll try a few things.

Tony

HeneryH

There is code in the sketch that looks like an initial thought, but it must not be fleshed out in the various if/if/else/if paths.  It will take some study...

  //artificial power ON after a low battery shutdown
  if (PowerState == OFF && batteryLowShutdown && systemVoltage >= CHARGINGTHRESHOLD) 
    reading = HIGH;
 


My system will be in a remote location so anything I can do to prevent me from making a 3 hr one-way drive just to push a button is worth my effort.