IOT断线重连功能实现,5S检测一次
authorazao <821478748@qq.com>
Fri, 19 Sep 2025 02:37:37 +0000 (10:37 +0800)
committerazao <821478748@qq.com>
Fri, 19 Sep 2025 02:37:37 +0000 (10:37 +0800)
2.sdk/project/K8/sdk/services/microPython/ports/quectel/core/protocol.py

index 1125690..b5e566e 100644 (file)
@@ -535,6 +535,7 @@ class SockMangager(Abstract):
         self.timer_id = 0
         self.start_voice_flag = 0
         self.IOT_sock = None
+        self.login_statu = 0#登陆状态
         self.sock_lock = _thread.allocate_lock()  # 初始化锁
         #对话状态,一秒检查一次
         self.last_data = None  # 保存上一次的数据状态
@@ -570,7 +571,7 @@ class SockMangager(Abstract):
     def send_unbind_dev_to_iot(self,event,msg):
         self._5S_timer.start(30000,1,self._1M_timer_cb)
         self._1S_timer.start(1000,1,self._1S_timer_cb)
-        # self._10Stimer.start(60000,1,self._10S_timer_cb)
+        # self._10Stimer.start(50000,1,self._10S_timer_cb)
     def _1M_timer_cb(self,*argc):
         EventMesh.publish("heart_IOT")#开启IOT心跳包
         EventMesh.publish("send_device_information")#发送设备信息
@@ -764,11 +765,13 @@ class SockMangager(Abstract):
             if self.IOT_sock is not None:
                 if self.IOT_sock.getsocketsta() != 4:
                     print("iot断线重连")
+                    self.login_statu = 0
                     self.iot_close_therad()
                     EventMesh.publish("publish_AI_btnInfo",{"func":self.connect_iot_socket})
                     EventMesh.publish("login_IOT")#登录IOT
                 else:
-                    EventMesh.publish("login_IOT")#登录IOT
+                    if self.login_statu == 0:
+                        EventMesh.publish("login_IOT")#登录IOT
             self._1scnt = 0
             
 
@@ -808,7 +811,11 @@ class SockMangager(Abstract):
                     data = self.IOT_sock.recv(256)
                     if isinstance(data, bytes) and len(data)>10:
                         playload_data(data)
-                    
+                    #fffe00010001xxxx
+                    if isinstance(data, bytes) and len(data) == 8:#登录成功
+                        target_bytes = b'\xff\xfe\x00\x01\x00\x01'
+                        if data[:6] == target_bytes:
+                            self.login_statu = 1#登录成功标志位修改
                     socket_log.info("IOT_recv = {} ,len = {}".format(self.bytes_to_hex(data),len(data)))
                     #检查socket是否已关闭
                     if self.IOT_sock == None: