|
@@ -0,0 +1,41 @@
|
|
|
+import time
|
|
|
+
|
|
|
+import utils
|
|
|
+from config import getConfig
|
|
|
+from httpServer import startHttpServer,closeHttpServer
|
|
|
+# 硬重启
|
|
|
+#import machine;machine.reset()
|
|
|
+
|
|
|
+def taskCheck():
|
|
|
+ """
|
|
|
+ 定时检查连接
|
|
|
+ :return:
|
|
|
+ """
|
|
|
+ while True:
|
|
|
+ try:
|
|
|
+ if utils.getStatus():
|
|
|
+ print('WiFi 正常', utils.getWifiConnectInfo())
|
|
|
+ if getConfig().mqttStatus:
|
|
|
+ print('MQTT 正常', getConfig().mqtt.clientId, getConfig().mqtt.host, getConfig().mqtt.port,getConfig().mqtt.subTopic)
|
|
|
+ utils.reportStatus()
|
|
|
+ else:
|
|
|
+ print('MQTT 未连接', getConfig().mqtt.clientId, getConfig().mqtt.host, getConfig().mqtt.port,getConfig().mqtt.subTopic)
|
|
|
+ utils.connectMQTT()
|
|
|
+ else:
|
|
|
+ print('WiFi 未连接')
|
|
|
+ if utils.autoConnectWifi():
|
|
|
+ utils.connectMQTT()
|
|
|
+
|
|
|
+ if not getConfig().mqttStatus:
|
|
|
+ # 连接失败开启热点
|
|
|
+ utils.openAp()
|
|
|
+ startHttpServer()
|
|
|
+ else:
|
|
|
+ closeHttpServer()
|
|
|
+ utils.closeAp()
|
|
|
+
|
|
|
+ except Exception as e:
|
|
|
+ print(e)
|
|
|
+
|
|
|
+ time.sleep(10)
|
|
|
+taskCheck()
|