count = 1 if os.path.isfile('settings.txt'): with open('settings.txt', 'r') as f: settings = eval(f.read()) while True: if settings['ssid'] is None or settings['psw'] is None: break else: ret = wifi_connect(settings['ssid'], settings['psw']) count += 1 if ret: os.system('sh ./route.sh') break elif count == 3: break l.t = 2 ## while True: ## ret = p.connect(115200) ## if ret: ## 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:
return True return False return True # 启动flask的web服务器 def configure(): if platform.system() == 'Linux': app.run(host='0.0.0.0', port=80) # Linux的local else: app.run(host='127.0.0.1', port=80) # Windows的localhost,测试用 if __name__ == '__main__': l = LED() # 实例化led对象 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: