解绑绑定协议更新
authordxy <1731678236qq.com>
Wed, 20 Aug 2025 11:11:04 +0000 (19:11 +0800)
committerdxy <1731678236qq.com>
Wed, 20 Aug 2025 11:11:04 +0000 (19:11 +0800)
2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/ai_VC.py
2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/protocol.py

index 2771b07..33a379f 100644 (file)
@@ -224,14 +224,17 @@ class AI_UART():
         EventMesh.subscribe("bt_ota_run",self.bt_ota_run)#
         EventMesh.subscribe("start_ota",self.start_ota)
         EventMesh.subscribe("end_ota",self.end_ota)
-        EventMesh.subscribe("send_ble_adv_switch",self.send_ble_adv_switch)
-        EventMesh.subscribe("send_ble_adv_switch_to_ble",self.send_ble_adv_switch_to_ble)
+        EventMesh.subscribe("send_bt_switch_toble",self.send_bt_switch_toble)
+        EventMesh.subscribe("send_ble_switch_toble",self.send_ble_switch_toble)
         EventMesh.subscribe("send_ble_scan",self.send_ble_scan)
         EventMesh.subscribe("send_connect_bt_mac",self.send_connect_bt_mac)
         EventMesh.subscribe("send_disconnect_bt_mac",self.send_disconnect_bt_mac)
         EventMesh.subscribe("send_imei_to_ble",self.send_imei_to_ble)
         EventMesh.subscribe("send_get_connect_bt_state",self.send_get_connect_bt_state)
         EventMesh.subscribe("recv_bt_connect_rest",self.recv_bt_connect_rest)
+        EventMesh.subscribe("AI_send_bt_ble_switch_toble",self.AI_send_bt_ble_switch_toble)
+        self.bt_switch = 0
+        self.ble_switch = 0
         self.uart_timer = osTimer()
         self.get_bt_connect_timer = osTimer()
         self.get_bt_connect_flag = 0
@@ -241,20 +244,11 @@ class AI_UART():
         self.ping_json_str = {}
         self.ping_json_str_tmp =""
         self.read_uart_data = ""
-    def send_ble_adv_switch_to_ble(self,event,msg):
-        json_data = \
-        {
-            
-            "event": "switch_bt_state",
-            "data":{
-                "switch_bt_state":msg
-            }   
-           
-        }
-        json_str  =ujson.dumps(json_data)
-        self.send_data(json_str)
-        pass
+
     def send_imei_to_ble(self,event,msg):
+        EventMesh.publish("publish_AI_btnInfo",{"func":self.send_imei_to_ble_cb})
+
+    def send_imei_to_ble_cb(self):
         imei  = modem.getDevImei()
         json_data = \
         {
@@ -362,7 +356,17 @@ class AI_UART():
                 ack_flag=1
             
             elif jsload_data["event"]=="get_ble_switch":
-                EventMesh.publish("send_ble_adv_switch")
+                ble_switch_flag =  EventMesh.publish("get_storage_config","switch_ble_state")#ble开关
+                if ble_switch_flag == None:
+                    ble_switch_flag = "0"
+                EventMesh.publish("send_ble_switch_toble",str(ble_switch_flag))
+                ack_flag=1
+                pass
+            elif jsload_data["event"]=="get_bt_switch":
+                bt_switch_flag =  EventMesh.publish("get_storage_config","switch_bt_state")#bt开关
+                if bt_switch_flag == None:
+                    bt_switch_flag = "0"
+                EventMesh.publish("send_bt_switch_toble",bt_switch_flag)
                 ack_flag=1
                 pass
             elif jsload_data["event"]=="get_cat1_imei":
@@ -387,40 +391,119 @@ class AI_UART():
         if "data" in msg:
             EventMesh.publish("send_bt_connect_state_to_iot",msg)
             pass
+    def AI_send_bt_ble_switch_toble(self,event,msg):
+        # // {
+        #     //     "event":"switch_bt_state",
+        #     //     "data":{
+        #     //         "switch_bt_state":"0"
+        #     //     }
+        #     // } #格式
+       
+        self.read_ack_flag=0
+        if msg == 1: #AI对话开启蓝牙
+            json_data = \
+            {
+                
+                "event": "switch_ble_state",
+                "data":{
+                    "switch_ble_state":"0"
+                }   
             
+            }
+            json_str  =ujson.dumps(json_data)
+            print("switch_ble_state{}".format(json_str))
+            self.send_data(json_str)
+        elif  msg == 2: #AI对话开启蓝牙
+            json_data = \
+            {
+                
+                "event": "switch_ble_state",
+                "data":{
+                    "switch_ble_state":"1"
+                }   
+            
+            }
+            json_str  =ujson.dumps(json_data)
+            print("switch_ble_state{}".format(json_str))
+            self.send_data(json_str)
+        elif  msg == 3: #AI对话开启蓝牙
+            json_data = \
+            {
+                
+                "event": "switch_bt_state",
+                "data":{
+                    "switch_bt_state":"0"
+                }   
+            
+            }
+            json_str  =ujson.dumps(json_data)
+            print("switch_bt_state{}".format(json_str))
+            self.send_data(json_str)
+        elif  msg == 4: #AI对话开启蓝牙
+            json_data = \
+            {
+                
+                "event": "switch_bt_state",
+                "data":{
+                    "switch_bt_state":"1"
+                }   
+            
+            }
+            json_str  =ujson.dumps(json_data)
+            print("switch_bt_state{}".format(json_str))
+            self.send_data(json_str)
 
-
-    def send_ble_adv_switch(self,event,msg):
+    def send_bt_switch_toble(self,event,msg):
+        EventMesh.publish("publish_AI_btnInfo",{"func":self.send_bt_switch_toble_cb,"data":msg})
+    def send_bt_switch_toble_cb(self,data):
         # // {
         #     //     "event":"switch_bt_state",
         #     //     "data":{
         #     //         "switch_bt_state":"0"
         #     //     }
         #     // } #格式
-        ble_state = EventMesh.publish("get_storage_config","switch_bt_state")
-        if ble_state == None:
-            ble_state = 0
-        self.read_ack_flag=0
+
         json_data = \
         {
             
             "event": "switch_bt_state",
             "data":{
-                "switch_bt_state":str(ble_state)
+                "switch_bt_state":str(data)
             }   
            
         }
         json_str  =ujson.dumps(json_data)
-        print("send_ble_adv_switch{}".format(json_str))
+        print("send_bt_switch_toble{}".format(json_str))
         self.send_data(json_str)
+    def send_ble_switch_toble(self,event,msg):
+        EventMesh.publish("publish_AI_btnInfo",{"func":self.send_ble_switch_toble_cb,"data":msg})
+    def send_ble_switch_toble_cb(self,data):
+        # // {
+        #     //     "event":"switch_ble_state",
+        #     //     "data":{
+        #     //         "switch_ble_state":"0"
+        #     //     }
+        #     // } #格式
+    
+        self.read_ack_flag=0
+        json_data = \
+        {
             
+            "event": "switch_ble_state",
+            "data":{
+                "switch_ble_state":str(data)
+            }   
+           
+        }
+        json_str  =ujson.dumps(json_data)
+        print("send_ble_switch_toble{}".format(json_str))
+        self.send_data(json_str)    
         
     def send_reset_cb(self):
         send_count = 5#最大重发5次,没ack或者返回error重发
         while 1:
             send_count-=1
             self.read_ack_flag = 0
-            EventMesh.publish("send_ble_adv_switch")
             #utime.sleep_ms(100)
             count =100
             while True:
@@ -465,7 +548,7 @@ class AI_UART():
            
         }
         json_str  =ujson.dumps(json_data)
-        print("send_ble_adv_switch{}".format(json_str))
+        print("send_ble_scan{}".format(json_str))
         self.send_data(json_str)
         pass
     def send_data(self,str_data):
@@ -776,15 +859,21 @@ class AI_dev(Abstract):
         self.ai_uart = AI_UART()
         self.Keycall1_press_count = 0
         self.ble_switch_flag_time = osTimer()
-        self.ble_switch_flag_time.start(5000, 0, self.ble_switch_flag_time_cb)
+        self.ble_switch_flag_time.start(10000, 0, self.ble_switch_flag_time_init)
+    def ble_switch_flag_time_init(self,*args):
+        EventMesh.publish("publish_AI_btnInfo",{"func":self.ble_switch_flag_time_cb})
     def ble_switch_flag_time_cb(self,*args):
-        ble_switch_flag =  EventMesh.publish("get_storage_config","switch_bt_state")#ble开关
-        if ble_switch_flag == None:
-            ble_switch_flag = 0
-        EventMesh.publish("send_ble_adv_switch_to_ble",str(ble_switch_flag))
+        bt_switch_flag =  EventMesh.publish("get_storage_config","switch_bt_state")#bt开关
+        if bt_switch_flag == None:
+            bt_switch_flag = "0"
+        EventMesh.publish("send_bt_switch_toble",str(bt_switch_flag))
         EventMesh.publish("send_imei_to_ble")
+        ble_switch_flag =  EventMesh.publish("get_storage_config","switch_ble_state")#ble开关
+        if ble_switch_flag == None:
+            ble_switch_flag = "0"
+        EventMesh.publish("send_ble_switch_toble",str(ble_switch_flag))
         pass
-        print("AI_dev:end")
+        print("ble_switch_flag_time_cb!!!!!!!")
     def ntptime_cb(self):
         #ntptime.settime(8)
         print("timer:{}!!!!!!!!\r\n".format(utime.localtime()))
@@ -3645,12 +3734,13 @@ class AI_VC(Abstract):
                         elif jsload_data["event"] == "canceled" :#打断
                             EventMesh.publish("publish_AI_btnInfo",{"func":self.VC_Speech_Start_now})#开始录音
                             self.VC_state = VC_State_None
-                        elif jsload_data["event"] == "completed" :#会话结束
+                        elif jsload_data["event"] == "completed" :#会话结束 "event":"audio.convert.completed"
                             #EventMesh.publish("open_led_green")#绿色
                             
                             self.LocalRespondingEnded_timerout = 8
                             self.VC_state = VC_State_End
                             pass
+
                         elif jsload_data["event"] == "command" :#命令匹配
                             ret = -1
                             try:
@@ -3691,6 +3781,8 @@ class AI_VC(Abstract):
                             pass
                            
                         elif jsload_data["event"] == "audio.convert.completed":#音频转成完成没有出错 接口
+                            self.LocalRespondingEnded_timerout = 8
+                            self.VC_state = VC_State_End
                             if EventMesh.publish("get_play_new_voice_state")== 1:
                                 EventMesh.publish("set_play_new_voice_state",1)
                                 EventMesh.publish("update_play_new_voice_info")
@@ -4290,6 +4382,34 @@ class AI_VC(Abstract):
 
                     print("语音留言!!!!!!!!!!")
                     return 0
+                if text.find("开广播") != -1 or text.find("开蓝牙广播") != -1:
+                    
+                    self.AI_TTS_str = "正在开蓝牙广播" 
+                    EventMesh.publish("AI_send_bt_ble_switch_toble",1)
+
+                    print("正在开蓝牙广播")
+                    return 0
+                if text.find("关广播") != -1 or text.find("关蓝牙广播") != -1:
+                    
+                    self.AI_TTS_str = "正在关蓝牙广播" 
+                    EventMesh.publish("AI_send_bt_ble_switch_toble",2)
+
+                    print("正在关蓝牙广播")
+                    return 0
+                if text.find("开经典蓝牙") != -1:
+                    
+                    self.AI_TTS_str = "正在开经典蓝牙" 
+                    EventMesh.publish("AI_send_bt_ble_switch_toble",3)
+                    print("正在开经典蓝牙")
+                    return 0
+                if text.find("关闭经典蓝牙") != -1 or text.find("关经典蓝牙") != -1:
+                    
+                    self.AI_TTS_str = "正在关经典蓝牙" 
+                    EventMesh.publish("AI_send_bt_ble_switch_toble",4)
+                    print("正在关经典蓝牙")
+                    return 0
+                    
+                
                 if text.find("解绑设备") != -1 or text.find("设备解绑") != -1:
                     self.AI_TTS_str = "设备解绑中...." 
                     self.Close_flag = 1
@@ -4798,7 +4918,7 @@ class AI_VC(Abstract):
             # EventMesh.publish("publish_AI_btnInfo",{"func":self.websocket_deconnect_VC}) 
             # EventMesh.publish("publish_AI_btnInfo",{"func":self.AI_VC_start}) 
         except Exception as e:
-                usys.print_exception(e)   
+            usys.print_exception(e)   
         pass
     def AI_client_new_voice(self): #上传未读的语音地址
         json_data = \
index bfbbbff..bfb1c34 100644 (file)
@@ -1858,6 +1858,8 @@ class ProtoCol(Abstract):
     #PID = "qAELPTKmFanR4RHe"
     md5_key = ''
     PID = ''
+    btstate = 0
+    blestate = 0
 
     def __init__(self):
         pass
@@ -1944,7 +1946,7 @@ class IOTWeb_fence_sosProtoCol(ProtoCol):
 class IOTWeb_HRProtoCol(ProtoCol):
     """post_heart_beat"""
     TYPE = "post_heart_beat"
-
+    
     def send(self, event, msg):
         print("send hr{}".format(msg))
         # 通过websocket发送到服务器端
@@ -1972,11 +1974,22 @@ class IOTWeb_HRProtoCol(ProtoCol):
         if "data" in msg:
             data = msg["data"]
             rest = data["rest"]
-            if rest == "unbind": #解绑需要开启蓝牙开关
-                if EventMesh.publish("get_storage_config","switch_bt_state") != None:
-                    if EventMesh.publish("get_storage_config","switch_bt_state") == 1:
-                        EventMesh.publish("set_storage_config",["switch_bt_state","0"])
-                        EventMesh.publish("send_ble_adv_switch","0")
+            if rest == "unbind": #解绑需要开启蓝牙广播
+                self.btstate = 0
+                if self.blestate == 0:
+                    EventMesh.publish("set_storage_config",["switch_ble_state","0"])
+                    EventMesh.publish("send_ble_switch_toble","0")
+
+                    EventMesh.publish("set_storage_config",["switch_bt_state","0"])
+                    EventMesh.publish("send_bt_switch_toble","0")
+                    self.blestate=1
+
+            elif rest == "bind": #绑定需要关闭蓝牙广播
+                self.blestate =0
+                if self.btstate == 0:
+                    EventMesh.publish("set_storage_config",["switch_ble_state","1"])
+                    EventMesh.publish("send_ble_switch_toble","1")
+                    self.btstate=1
 
 #定位周期
 class IOTWeb_locatedurationProtoCol(ProtoCol):
@@ -2614,6 +2627,8 @@ class IOTWeb_unbind_devProtoCol(ProtoCol):
         #         "msg":"收到主动解绑设备指令"
         #     }
         # }
+        self.btstate = 0
+        self.blestate = 0
         self.unbind_devtimer.stop()
         self.init_flag=0
         if "data" in msg:
@@ -2621,6 +2636,12 @@ class IOTWeb_unbind_devProtoCol(ProtoCol):
             rest = data["rest"]
             if rest == "success":
                 play_str = "设备解绑成功"
+                EventMesh.publish("set_storage_config",["switch_ble_state","0"])
+                EventMesh.publish("send_ble_switch_toble","0")
+
+  
+                EventMesh.publish("set_storage_config",["switch_bt_state","0"])
+                EventMesh.publish("send_bt_switch_toble","0")
                 EventMesh.publish("play_tts",[play_str,1])
                 pass
             else:
@@ -2668,8 +2689,13 @@ class IOTWeb_user_unbind_devProtoCol(ProtoCol):
         #         "msg":"收到主动解绑设备指令"
         #     }
         # }
+        self.btstate = 0
+        self.blestate = 0
+        EventMesh.publish("set_storage_config",["switch_ble_state","0"]) #用户解绑设备需要开启广播 开启经典蓝牙
+        EventMesh.publish("send_ble_switch_toble","0")
+
         EventMesh.publish("set_storage_config",["switch_bt_state","0"])
-        EventMesh.publish("send_ble_adv_switch","0")
+        EventMesh.publish("send_bt_switch_toble","0")
         EventMesh.publish(WEB_CMD_ENUM.USER_UNBIND_DEV_S)
         print("recv user_unbind_dev{}".format(msg))    
 #下发位子留言
@@ -3163,11 +3189,11 @@ class IOTWeb_switch_bt_stateProtoCol(ProtoCol):
             data = msg["data"]
             if data == "0":
                 EventMesh.publish("set_storage_config",["switch_bt_state","0"])
-                EventMesh.publish("send_ble_adv_switch","0")
+                EventMesh.publish("send_bt_switch_toble","0")
                 pass
             elif data == "1":
                 EventMesh.publish("set_storage_config",["switch_bt_state","1"])
-                EventMesh.publish("send_ble_adv_switch","1")
+                EventMesh.publish("send_bt_switch_toble","1")
                 pass
         print("recv switch_bt_state{}".format(msg))
         
@@ -3220,9 +3246,7 @@ class IOTWeb_bt_scanProtoCol(ProtoCol):
             data = msg["data"]
             if data == "1":
                 s_ret = "1"
-                
                 EventMesh.publish("send_ble_scan","1")
-                # EventMesh.publish("send_ble_adv_switch","1")
             elif data == "0":
                 s_ret = "0"
                 EventMesh.publish("send_ble_scan","0")