rlsten Posted March 26, 2017 Posted March 26, 2017 (edited) Hi, I am a newbie to Armbian so I apologize if this is a stupid question. I am running Armbian legacy. I think I have successfully programmed a GPIO shutdown button for the Orange Pi Zero by cobbling together information from this and the Orange Pi forum. My script goes like this, in file hw_shutdown.py: #!/usr/bin/env python import os import sys import subprocess if not os.getegid() == 0: sys.exit('Script must be run as root') from time import sleep from subprocess import * from pyA20.gpio import gpio from pyA20.gpio import connector from pyA20.gpio import port button_shutdown = port.PA2 #PIN 20 """Init gpio module""" gpio.init() """Set directions""" gpio.setcfg(button_shutdown, gpio.INPUT) """Enable pullup resistor""" gpio.pullup(button_shutdown, gpio.PULLUP) def delay_milliseconds(milliseconds): seconds = milliseconds / float(1000) sleep(seconds) def run_cmd(cmd): p = Popen(cmd, shell=True, stdout=PIPE, stderr=STDOUT) output = p.communicate()[0] return output shutdown_pressed = 1 while True: value_out = 0 shutdown_pressed = gpio.input(button_shutdown) if (shutdown_pressed == 0): value_out = 1 run_cmd("shutdown now") delay_milliseconds(100) What I would like is to have this script run at boot. I tried adding python /root/hw_shutdown.py before exit 0 in /etc/rc.local, but nothing happened. In arch linux on the raspberry pi I created a service to run this type of script, but I don't know how to do that on Armbian. Any ideas what I should do? Thanks, Rod Edited March 26, 2017 by rlsten errors in code
martinayotte Posted March 27, 2017 Posted March 27, 2017 When adding any thing in /etc/rc.local, you need to make sure it done as a subprocess, not block /etc/rc.local from exiting. So, you should call your script similar to : nohup /usr/bin/python /root/hw_shutdown.py & 2
rlsten Posted March 29, 2017 Author Posted March 29, 2017 On 27.03.2017 at 8:59 PM, martinayotte said: When adding any thing in /etc/rc.local, you need to make sure it done as a subprocess, not block /etc/rc.local from exiting. So, you should call your script similar to : nohup /usr/bin/python /root/hw_shutdown.py & Thanks very much, Rod
fine Posted November 15, 2017 Posted November 15, 2017 Hello Rod, can you please describe how you setup the power button to the different ports? Thanks Fine
Recommended Posts