ソースを参照

更新 'system/v1.2/main.py'

hk 3 ヶ月 前
コミット
647937ef87
1 ファイル変更11 行追加4 行削除
  1. 11 4
      system/v1.2/main.py

+ 11 - 4
system/v1.2/main.py

@@ -15,6 +15,7 @@ def taskCheck():
     """
     time_sleep = 10
     count = 0
+    config = getConfig()
     while True:
         if getConfig().runTask:
             try:
@@ -24,9 +25,16 @@ def taskCheck():
                         print('MQTT 正常', getConfig().mqtt.host, getConfig().mqtt.port,getConfig().mqtt.subTopic)
                         if getConfig().mqtt.clientId is "":
                             print("设备未绑定")
-                        utils.send_ping()
+                            utils.send_ping()
+                        else:
+                            # 有变化就上报一次
+                            if config != getConfig():
+                                print("上报数据")
+                                utils.reportConfig()
+                                config = getConfig()
+                            else:
+                                utils.send_ping()
                         count = 0
-                        # time_sleep = 60
                     else:
                         print('MQTT 未连接', getConfig().mqtt.host, getConfig().mqtt.port,getConfig().mqtt.subTopic)
                         utils.connectMQTT(time_sleep)
@@ -38,7 +46,6 @@ def taskCheck():
                 # 没有客户的id表示没被绑定
                 if not utils.getStatus() or not getConfig().mqttStatus or getConfig().mqtt.clientId is "":
                     count += 1
-                    time_sleep = 10
                     # 连接失败开启热点
                     utils.openAp()
                     startHttpServer()
@@ -46,7 +53,7 @@ def taskCheck():
                     closeHttpServer()
                     utils.closeAp()
 
-                if count > 20:
+                if count > 60:
                     machine.reset()
             except Exception as e:
                 print(f"连接失败:未知错误 - {e}")