import serial from time import sleep import os ser = serial.Serial( port='/dev/ttyUSB0',\ baudrate=9600,\ parity=serial.PARITY_NONE,\ stopbits=serial.STOPBITS_ONE,\ bytesize=serial.EIGHTBITS,\ #timeout=None) #doesn't work timeout=0) print("connected to: " + ser.portstr) substring ="Shutdown" # credit to https://eli.thegreenplace.net/2009/07/30/setting-up-python-to-work-with-the-serial-port # for a working read example while True: data = ser.read(9999) if len(data) > 0: # print 'Got:', data print data #https://www.agnosticdev.com/content/how-find-substring-string-python #boycott s(tack)exchange # if substring in data: # print ("I found the substring") if substring in data: os.system("reboot") #This doesn't work as user sleep(0.5) # print 'not blocked' ser.close()