added keyboard interupt handling
This commit is contained in:
6
main.py
6
main.py
@@ -28,7 +28,8 @@ ntfy_token = os.environ['NTFY_Token']
|
|||||||
device_name = os.environ['device_name']
|
device_name = os.environ['device_name']
|
||||||
shutdown_timer = int(os.environ['shutdown_timer'])
|
shutdown_timer = int(os.environ['shutdown_timer'])
|
||||||
|
|
||||||
with serial.Serial(device_name, 115200, timeout=1) as ser:
|
try:
|
||||||
|
with serial.Serial(device_name, 115200, timeout=1) as ser:
|
||||||
inverter_offline_counter = 0
|
inverter_offline_counter = 0
|
||||||
while True:
|
while True:
|
||||||
if ser.readline().decode().strip() == "0":
|
if ser.readline().decode().strip() == "0":
|
||||||
@@ -48,3 +49,6 @@ with serial.Serial(device_name, 115200, timeout=1) as ser:
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
os.system("shutdown now")
|
os.system("shutdown now")
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
logger.info("Exiting gracefully")
|
||||||
|
exit()
|
||||||
Reference in New Issue
Block a user