ATXRaspi shutdowncheck script with interrupts: shutdownirq.py

Started by tonyp7, November 12, 2016, 01:55:06 AM

tonyp7

EDIT: FINAL WORKING VERSION

What is shutdownirq.py?
shutdownirq.py is a drop in replacement for shutdowncheck.sh.

Instead of polling for the shutdown signal from the ATXRaspi to go high, it will simply register an interrupt on that pin. shutdownirq.py frees about 1% of your CPU processing time, and that's a lot.

Once the button is pressed, and due to quirks with the ATXRaspi (no falling edge sent back once the button press is released), I had to resort to polling to detect a button press longer than 2s. Interestingly, during my trials and errors I've found out that the ATXRaspi will kill the power no matter what after 50s. It basically leave you 48s to issue the sudo poweroff or die on you.

Next steps:
This is a nice and working replacement, but more could be done, such as converting this small Python script to C and making the whole solution a lot lighter on your system. To be continued!

tonyp7

Updated final working version that behaves exactly like shutdowncheck.sh  :)

Felix

Awesome, I have to check this out :)
I already posted to your other topic before I read this, but thanks a lot!

Felix

This script seems to work great. 0% CPU :)

I decreased this setting to 1s:
REBOOTPULSEMAXIMUM = 1.0	#reboot pulse signal should be at most this long (seconds)


Did you have a reason to have it as 2s instead?

I may add this script as an alternate to the existing polling one.
Do you know if this will run on OpenELEC and other distributions?

tonyp7

>Did you have a reason to have it as 2s instead?

Not sure, I was under the impression you had to press the button for 2s to trigger a shutdown. 1s is fine!

Do you know if this will run on OpenELEC and other distributions?

Unfortunately no, it will not run on OpenELEC out of the box because it seems like they removed RPi.GPIO library from their distro. You'd have to manually install the lib first. Probably the best way to circumvent with would be to package the script with it or just convert this script to C (not sure if asking users to make binaries is any simpler!)

I believe ALL distros supported by the Raspberry foundation come with the GPIO Python lib (like Librelec). Openelec might be a special snowflake.

Felix

Well anyway I updated my setup script and now the default is the python script with adjustments.
Checkout the readme and try it out, let me know what you think.

tonyp7

Hey Felix,

Just an error here:
         print "            REBOOT request from GPIO", SHUTDOWN, ", recycling Rpi ..."
Should be BOOT instead of SHUTDOWN.

but yeah looking good!

Felix

Quote from: tonyp7 on November 18, 2016, 07:38:24 AM
Just an error here:
         print "            REBOOT request from GPIO", SHUTDOWN, ", recycling Rpi ..."
Should be BOOT instead of SHUTDOWN.
Actually that's the SHUTDOWN signal, used in both cases (HIGH pulse for reboot, or permanent HIGH for shutdown).
Thanks for the feedback and contributions!

tonyp7

My bad you're right. All good then! Happy to contribute a small bit!

Felix

Someone reported this issue but I don't see it:

https://github.com/LowPowerLab/ATX-Raspi/issues/3

Is it possible because they're using sh and not bash?

tonyp7

Sorry Felix haven't had time to troubleshoot this --I'll get to it this weekend.

Felix

No worries, I think it's because the person was using sh, when the setup script is intended for bash.

tonyp7

Hey Felix,

I confirm:  bash installs it correctly. sh recreates the issue.

Tested on Ubuntu 16.04.1 LTS.

Felix

Thanks,
Are there instances where a user is forced to use sh or bash is not even available? I don't know of any such case on raspbian/debian.

tonyp7

Hey Felix,

Sorry I was off a few days. "sh" does not exist per say. On most distro sh is a symlink to bash. On debian sh symlinks to dash, another shell.

Bash is installed on all distros as far as I know.