parent
126f74a23e
commit
991230f81c
14
test.py
14
test.py
|
@ -12,19 +12,12 @@ def error_print(message: str):
|
||||||
current_time = now.strftime("%H:%M:%S")
|
current_time = now.strftime("%H:%M:%S")
|
||||||
print('[ERROR]['+current_time+'] '+message)
|
print('[ERROR]['+current_time+'] '+message)
|
||||||
|
|
||||||
|
|
||||||
relay_channels = ["19", "16", "26", "20"]
|
|
||||||
for channel in relay_channels:
|
|
||||||
os.system('echo "'+channel+'" /sys/class/gpio/export')
|
|
||||||
os.system('echo "out" > /sys/class/gpio/gpio'+channel+'/direction')
|
|
||||||
|
|
||||||
|
|
||||||
def relay_controller(pin: int, state: str):
|
def relay_controller(pin: int, state: str):
|
||||||
if state == "True":
|
if state == "True":
|
||||||
os.system('echo "1" > /sys/class/gpio/gpio'+str(pin)+'/value')
|
os.system('raspi-gpio set '+str(pin)+' op')
|
||||||
debug_print("Set relay-pin "+str(pin)+" to state True")
|
debug_print("Set relay-pin "+str(pin)+" to state True")
|
||||||
elif state == "False":
|
elif state == "False":
|
||||||
os.system('echo "0" > /sys/class/gpio/gpio'+str(pin)+'/value')
|
os.system('raspi-gpio set '+str(pin)+' ip')
|
||||||
debug_print("Set relay-pin "+str(pin)+" to state False")
|
debug_print("Set relay-pin "+str(pin)+" to state False")
|
||||||
else:
|
else:
|
||||||
error_print("Unknown state ("+state+") for relay channel "+str(pin))
|
error_print("Unknown state ("+state+") for relay channel "+str(pin))
|
||||||
|
@ -39,5 +32,6 @@ time.sleep(2)
|
||||||
relay_controller(channel_1, "False")
|
relay_controller(channel_1, "False")
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
|
|
||||||
|
relay_channels = ["19", "16", "26", "20"]
|
||||||
for channel in relay_channels:
|
for channel in relay_channels:
|
||||||
os.system('echo "'+channel+'" > /sys/class/gpio/unexport')
|
os.system('raspi-gpio set '+channel+' ip')
|
Loading…
Reference in New Issue