def run(self): led = LED() sensor_reader = SensorReader(self.device_port, self.baudrate) sensor_reader.start_reading() # database = Database(self.db_file) light_controller = Controller(sensor_reader, led) try: log.startLogging(sys.stdout) factory = WebSocketServerFactory() factory.protocol = RPiServerProtocol factory.protocol.controller = light_controller light_controller._init_read_thread() broadcast_task = task.LoopingCall(self.broadcast, factory) broadcast_task.start(self.broadcast_frequency) reactor.listenTCP(self.port, factory) reactor.run() except CannotListenError: print "Another server already opened at port: ", self.port finally: sensor_reader.close() light_controller.stop() # database.close_connection() led.stop()
## break ## ret = p.connect(250000) ## if ret: ## break ## time.sleep(5) l.t = 1 # s = 0 # b = os.popen('iwconfig wlan0') os.system('bash /root/3DP2/3DP2/eth0_0.sh') # c = os.popen('ifconfig eth0:0') l.t = 0.1 ## while True: ## ret = u.connect(settings['ip'], settings['eid'], settings['pw']) ## if ret: ## break l.stop() ## aps.add_job(check,'interval',seconds=30) # l.t = 0.1 ## aps.start() # l.t = 2 # timer = Timer(30,check) # timer.start() # time_out10 = time.time() + 60 # while(time_out10 > time.time()): # if(m == 1): # global n # n = threading.Timer(30.0,check) # n.start() # while(time_out10 < time.time()): # if(m == 0):
l.t = 1.5 # 闪灯间隔为1.5s t = threading.Thread(target=configure) t.start() # 开启启动flask的web服务器的线程,不然主函数无法向下运行 if os.path.isfile('settings.txt'): # 有配置文件则读取配置文件 with open('settings.txt', 'r') as f: settings = eval(f.read()) while True: # 连接wifi并自动重连 ret = wifi_connect(settings['ssid'], settings['psw']) if ret: os.system('sh ./route.sh') # 网络配置脚本 break l.t = 0.8 # 闪灯变快以示完成 while True: # 连接打印机并自动重连,同时自动判定波特率 ret = p.connect(115200) if ret: break ret = p.connect(250000) if ret: break time.sleep(5) l.t = 0.1 # 闪灯变快以示完成 while True: # 连接服务器并自动重连 ret = u.connect(settings['ip'], settings['eid'], settings['pw']) if ret: break time.sleep(5) l.stop() # 灯常亮以示全部完成
controller.single_measure_led(100, 255) elif arg == "colors": print "colors stairs mode" controller.stairs_colors() elif arg == "3": print "3 channel pid model" # TODO pid 3 channel else: print "starting 3 channel pid" # rgb_tuple = controller.get_temp_rgb_lux(6000) # controller.update_rgb_pid_point(rgb_tuple[0], rgb_tuple[1], rgb_tuple[2], test_mode=True) controller.update_red_pid_point(30, True) controller.update_green_pid_point(8, True) controller.update_blue_pid_point(30, True) # controller.update_pid_point(80, True) # somehow this works while True: print "sleep" time.sleep(100) except Exception as e: print e finally: print "done" out_file.close() controller.stop() database.close_connection() led.stop() sr.close() print "all closed"