MightyHat Pi Side Code & serial command shutdown

Started by mattm00700, March 03, 2017, 04:07:07 PM

mattm00700

I see that there is a complete system image for the Raspberry Pi gateway working with the MightyHat.  I'm wondering if there is posted someplace the tiny nugget of code that needs to be constantly running on the Pi to handle the power control functions (force shutdown / system halt when signaled and report BootOK)?

-Matt

Felix

Are you talking about the sketch that should run on the MightyHat? There is this example with code for RFM69.

mattm00700

Thanks for your quick response.  I'm good on code that runs on the mighty hat, Im using that sketch and its working great.  Maybe I'm confused, but I thought the mighty hat was basically warning the Pi to do a proper halt before 5V is turned off in the forced shutdown, waiting a decently long time for the OK to power off signal from the Pi, then removing power.  If I don't use the complete system image for the Pi under the Mightyhat, or even the Iot Gateway Project gatewaysetup.sh, I imagine there is a small script that runs from chron (or something) that halts the Pi when the MightyHat asks and sets BootOK on GPIO.  Unless all that is handled inside the Gateway code?  Basically I'm looking for just the power management part of the Pi side code.  I have something other than a gateway intended for the Pi, code already in place, just need to add the power supervision GPIO monitoring and response to Pi.

Felix

Oh you need to install the shutdowncheck script, which essentially does the exact same thing for ATXRaspi, see this:

github.com/LowPowerLab/atX-Raspi/
And also the ATXRaspi guide is helpful to understand how this works: lowpowerlab.com/atxraspi

mattm00700

Perfect, thanks for your help Felix.

mattm00700

One more question on this topic: There is no current support built in to the MightyHat sketch or the shutdowncheck script for a Pi initiated software shutdown is there?  I see the transistor hardware circuit for ATX, but with MightyHat it seems like something that could be requested over the serial connection if the MightyHat was listening for it.  Implementing this myself seems easy enough, just seems like something to complete the package unless its already there and I'm missing it.  In my ideal case, I could shutdown the Pi any way without doing anything special, and either shutdowncheck would send out power down serial message to MightyHat automatically, or maybe this could be done through BootOK signal.  Thanks again for your support time and dedication.

Felix

It could definitely be done in both ways:

- serial
- with a circuit similar to that shown here

I always prefer the most lean and script/code independent solutions so I would personally opt for #2

I suppose this circuit could be integrated on a future MightyHat revision, although not sure how many people would use it. I could simply add the through holes for a 10K resistor and NPN transistor, which would allow it to be populated easily for those interested in this. Thoughts?

mattm00700

For me personally, although I am a big fan of hardware solutions I think an out of the box serial solution would easily beat the Pi shutting down but staying powered unless it caused new problems.  I'm wondering if there is a compromise involved with using BootOK to perform this signalling that I'm not seeing.  If I understand correctly, at power on the MightyHat turns on power and BootOK goes high after boot is complete, and on Forced shutdown MightyHat is waiting for BootOK to go low before removing power safely.  My thinking is that after BootOK goes high on boot, if it ever went low again without removing power to the Pi, and stayed low for longer than a reboot, it would be safe to assume the Pi had shut itself down and no longer requires power.  The only drawbacks I see are the delay and that the Pi would restart constantly out of the box without shutdowncheck, but its already in bad shape with the BlueTooth and GPIO console stepping on the serial port in Jesse and power management seems like a lot of the point, and you dont get any of it without shutdowncheck anyway.  Also, the MightyHat could see that BootOK never went high at startup, assume no shutdowncheck, and leave power on in that case.  If you dont like the ambiguous delay, the Pi could toggle BootOK before shutdown in a way that would signal for power to be removed.

I will be running from battery and solar, so its important to me to be able to turn off the Pi as soon as it is done with the work, but maybe a lot of folks are always powered and the clean shutdown side of MightyHat is in case of power outage or rare conditions.

MightyHat is an amazing product, I can't thank you enough for doing this work, it is so perfect for my application I'm in awe.  Just trying to make it even better.  If there were a spot for a transistor I would solder it, but if it worked through BootOK or serial I would leave it alone.  These ideas are probably worth exactly what you paid for them or less, but I appreciate your help very much.

Felix

Delays and assumptions can be ambiguous because different Pis can take different delays to do something, and when things don't work quite perfect people start to complain and generate lots of support and ask for changes etc, not keen to opening that door.

If serial works for you I would suggest going in that direction. Basically the HAT listens to serial already. It would simply have to check a special token ("SHUTDOWN_NOW") and then it would execute the shutdown from software as if you pressed the button physically.
I can probably add that pretty quickly if you agree.

mattm00700

Totally with you on the first part, better to not have it than to have it poorly because of support.

The serial solution sounds perfect for me, I would happily be your beta tester if you implement.

Thanks again Felix,
Matt