def poll(ws): while True: # Can't do anything if the websocket closed or the thread # has already been stopped if ws._closed or threading.current_thread().stopped(): print('socket was closed') break #ws.write_message(u'send_input') battery = arduino_com.read_battery() update_ping_sensors() ws.write_message('{"type":"battery", "data":%f}'%battery); ws.write_message('{"type": "ping_sensors", "data": %s}'%json.dumps(ping_sensor_distances)) time.sleep(polling_time) # Thread is dead, remove open_threads.remove(threading.current_thread())
import arduino_com import time arduino_com.init(); while(1): print(str(arduino_com.read_battery()) + 'V') time.sleep(1)