Made a basic watchdog system for Pico
This commit is contained in:
44
main.py
44
main.py
@@ -1,12 +1,44 @@
|
||||
import serial
|
||||
import threading
|
||||
|
||||
pishock = serial.Serial('/dev/tty.usbserial-120')
|
||||
def listen(keep_alive_event, pi):
|
||||
while True:
|
||||
message = pi.readline().decode()
|
||||
if '\n' in message:
|
||||
if "keep-alive" in message:
|
||||
keep_alive_event.set()
|
||||
else:
|
||||
print("Other stuff is happening")
|
||||
else:
|
||||
print("No newline found")
|
||||
|
||||
pishock.baudrate = 115200
|
||||
pishock.timeout = 15
|
||||
|
||||
print(pishock)
|
||||
def watchdog(keep_alive_event):
|
||||
while True:
|
||||
alive = keep_alive_event.wait(1.0)
|
||||
|
||||
pishock.write(b'{"cmd": "info"}\n')
|
||||
if alive:
|
||||
print("Yay!")
|
||||
keep_alive_event.clear()
|
||||
else:
|
||||
print("Nay!")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
pi = serial.Serial('/dev/tty.usbmodem2101')
|
||||
|
||||
pi.baudrate = 115200
|
||||
pi.timeout = 0.1
|
||||
|
||||
print(pi)
|
||||
|
||||
keep_alive = threading.Event()
|
||||
|
||||
listen_thread = threading.Thread(target=listen, args=(keep_alive, pi))
|
||||
|
||||
watchdog_thread= threading.Thread(target=watchdog, args=(keep_alive,))
|
||||
|
||||
listen_thread.start()
|
||||
watchdog_thread.start()
|
||||
|
||||
print(pishock.readlines())
|
||||
|
||||
Reference in New Issue
Block a user