1.修改日程 闹钟协议下发不提醒问题
authordxy <1731678236qq.com>
Tue, 19 Aug 2025 08:05:24 +0000 (16:05 +0800)
committerdxy <1731678236qq.com>
Tue, 19 Aug 2025 08:05:24 +0000 (16:05 +0800)
2.新增链接蓝牙耳机的更新状态
3.新增设备解绑 用户解绑 心跳增加解绑

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/ai_alarm.py
2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/main_init.py
2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/protocol.py

index 04d84fa..291cfae 100644 (file)
@@ -231,6 +231,7 @@ class AI_UART():
         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)
         self.uart_timer = osTimer()
         self.get_bt_connect_timer = osTimer()
         self.get_bt_connect_flag = 0
@@ -368,6 +369,9 @@ class AI_UART():
                 EventMesh.publish("send_imei_to_ble")
                 ack_flag=1
                 pass
+            elif jsload_data["event"] == "post_bt_connect_rest":
+                EventMesh.publish("recv_bt_connect_rest",jsload_data)
+                ack_flag=1
 
             elif jsload_data["event"] == "ack" :#电源按键按下
                 self.read_ack_flag = 1
@@ -377,6 +381,13 @@ class AI_UART():
         except Exception as e:
             usys.print_exception(e)
             self.read_uart_data = ""
+    def recv_bt_connect_rest(self,event,msg):
+        date_tmp = utime.localtime()
+        time_tmp = utime.mktime(date_tmp)
+        if "data" in msg:
+            EventMesh.publish("send_bt_connect_state_to_iot",msg)
+            pass
+            
 
 
     def send_ble_adv_switch(self,event,msg):
@@ -1947,7 +1958,7 @@ class AI_VC(Abstract):
         EventMesh.subscribe("play_new_voice",self.play_new_voice)
         EventMesh.subscribe("set_vad_silence",self.set_vad_silence)
             
-        self.AI_alarm = _ai_alarm.AI_alarm()
+        
         self.error_data = []
         self.asr_taskid  = ""
         self.VC_taskid  = ""
@@ -4274,6 +4285,12 @@ class AI_VC(Abstract):
 
                     print("语音留言!!!!!!!!!!")
                     return 0
+                if text.find("解绑设备") != -1 or text.find("设备解绑") != -1:
+                    self.AI_TTS_str = "设备解绑中...." 
+                    self.Close_flag = 1
+                    EventMesh.publish("send_unbind_dev_to_iot")
+                    print("解绑设备!!!!!!!!!!!!!!")
+                    return 0
                 if len(text)<16 and (text.find("再见") != -1 or text.find("拜拜") != -1 or text.find("关闭对话") != -1):
                     #EventMesh.publish("publish_AI_btnInfo",{"func":self.Close}) 
                     if dev_type != "7PIN" and dev_type != "7PIN_coze":#柒牌
index fab81ca..8eb67a3 100644 (file)
@@ -5,7 +5,8 @@ import ujson
 import osTimer
 import utime
 import request
-class AI_alarm():
+from common import Abstract
+class AI_alarm(Abstract):
     """
     """""" {
     "alarm_type":"间隔闹钟", #闹钟类型。示例值:间隔闹钟(喝水提醒,重复每天闹钟)、单次闹钟(会议提醒)
@@ -66,6 +67,7 @@ class AI_alarm():
         EventMesh.subscribe("read_alarm_list",self.read_alarm_list)
         EventMesh.subscribe("AI_alarm_start",self.AI_alarm_start) 
         EventMesh.subscribe("GET_NEED_ALARM_REPORT_INFO",self.get_need_alarm_report_info)#读取闹钟数组
+        EventMesh.subscribe("set_alarm_info",self.set_alarm_info)
     def alarm_get_statu(self,event=None,msg=None):
         print("alarm_get_statu = {}".format(self.alarm_timer_sta))
         return self.alarm_timer_sta
@@ -98,9 +100,12 @@ class AI_alarm():
             return 1
     def AI_alarm_poll(self):#轮询调用
         pass
-
+    def set_alarm_info(self,event=None,msg=None):
+        self.alarm_array=msg
+        EventMesh.publish("AI_alarm_start")#
     def AI_alarm_start(self,event,msg):#轮询调用
-       
+        if self.alarm_array == None:
+            return
         
         alarm_TTS_str ={}#闹钟播放tts字符串
         repeat_day_flag = 0
@@ -798,7 +803,7 @@ class AI_alarm():
         
 
 #日程提醒
-class schedule():
+class schedule(Abstract):
     """
     sjon格式{
         # {
@@ -832,7 +837,13 @@ class schedule():
         self.is_schedule = 0
         self.old_minute = 0
         EventMesh.subscribe("AI_schedule_open",self.AI_schedule_open)#
-        
+        EventMesh.subscribe("set_schedule_info",self.set_schedule_info)#
+
+    def set_schedule_info(self,event=None,msg=None):
+        print("msg:{}".format(msg))
+        self.schedule_array=msg
+        EventMesh.publish("AI_schedule_open")#
+        pass
 
     def AI_schedule_open(self,event=None,msg=None):
         if self.schedule_array == None:
index f275a74..0097f34 100644 (file)
@@ -245,6 +245,9 @@ def main_init():
             pcr.add_support(pro.IOTWeb_player_controlProtoCol())
             pcr.add_support(pro.IOTWeb_chat_configProtoCol())
             pcr.add_support(pro.IOTWeb_get_chat_configProtoCol())
+            pcr.add_support(pro.IOTWeb_post_bt_connect_restProtoCol())
+            pcr.add_support(pro.IOTWeb_unbind_devProtoCol())
+            pcr.add_support(pro.IOTWeb_user_unbind_devProtoCol())
             sm = pro.SockMangager()
 
             sm.add_support_resolver(pcr)
@@ -258,6 +261,14 @@ def main_init():
             app.append_manager(_ai.AI_VC())
         except Exception as e:
             usys.print_exception(e) 
+
+        try:
+            import ai_alarm
+            app.append_manager(ai_alarm.AI_alarm())
+            app.append_manager(ai_alarm.schedule())
+        except Exception as e:
+            usys.print_exception(e) 
+
         try:
             EventMesh.publish("connect_iot_websocket_cb")
         except Exception as e:
index beac9ba..71add71 100644 (file)
@@ -671,6 +671,15 @@ class WEB_CMD_ENUM:
     CHAT_CONFIG_R = "chat_config_R"
     CHAT_CONFIG_S = "chat_config_S"
 
+    POST_BT_CONNECT_REST_R = "post_bt_connect_rest_R"
+    POST_BT_CONNECT_REST_S = "post_bt_connect_rest_S"
+
+    UNBIND_DEV_R="unbind_dev_R"
+    UNBIND_DEV_S="unbind_dev_S"
+
+    USER_UNBIND_DEV_R="user_unbind_dev_R"
+    USER_UNBIND_DEV_S="user_unbind_dev_S"
+
 class IOTSendCmdManager(Abstract):
     #
     def __init__(self):
@@ -1179,6 +1188,7 @@ class SockMangager(Abstract):
         self.reconnect_count = 0 #连续重连次数 默认十次 不过就不重连了 等下一个心跳重连
         self.schedule = _schedule.schedule()
         self._1S_timer = osTimer()
+        self._5S_timer = osTimer()
         self.timer_id = 0
         self.start_voice_flag = 0
         self.init_send_default=0
@@ -1216,6 +1226,8 @@ class SockMangager(Abstract):
         EventMesh.subscribe("send_bt_connect_list",self.send_bt_connect_list)
         EventMesh.subscribe("set_play_new_voice_state",self.set_play_new_voice_state)
         EventMesh.subscribe("get_play_new_voice_state",self.get_play_new_voice_state)
+        EventMesh.subscribe("send_bt_connect_state_to_iot",self.send_bt_connect_state_to_iot)
+        EventMesh.subscribe("send_unbind_dev_to_iot",self.send_unbind_dev_to_iot)
         # count = 0
         # while True:
         #     count += 1
@@ -1352,6 +1364,47 @@ class SockMangager(Abstract):
         except Exception as e:
             usys.print_exception(e)
         pass
+    def send_unbind_dev_to_iot(self,event,msg):
+        self._5S_timer.start(7000,0,self._5S_timer_cb)
+    def _5S_timer_cb(self,*argc):
+        EventMesh.publish("publish_AI_btnInfo",{"func":self.send_unbind_dev_to_iot_cb})
+        pass
+    def send_unbind_dev_to_iot_cb(self):
+        EventMesh.publish(WEB_CMD_ENUM.UNBIND_DEV_S)
+        pass
+    def send_bt_connect_state_to_iot(self,event,msg):
+        date_tmp = utime.localtime()
+        time_tmp = utime.mktime(date_tmp)
+        
+        try:
+            # {
+            #     "cmd":"post_bt_connect_rest",
+            #     "ts":1738283829,
+            #     "msg":"上报蓝牙连接结果",
+            #     "data":{
+            #         "mac":"mac地址",
+            #         "state":"connected/disconnected/connecting/failed"
+            #     }
+            # }
+            event = msg["event"]
+            mac = msg["data"]["mac"]
+            state = msg["data"]["state"]
+            json_data = \
+            {
+                
+                "cmd": event,
+                "ts":time_tmp,
+                "msg":"上报蓝牙连接结果",
+                "data":{
+                    "mac":mac,
+                    "state":state
+                }   
+            
+            }
+            EventMesh.publish(WEB_CMD_ENUM.POST_BT_CONNECT_REST_S,json_data)
+        except Exception as e:
+            usys.print_exception(e)
+        pass
     
     def send_jm_audio_to_iot(self,event,msg):
         send_data = b''
@@ -1366,32 +1419,6 @@ class SockMangager(Abstract):
         # print("yuyin:{}".format(msg[2]))
         EventMesh.publish("CHANNEL_IOT_WEB_SEND",send_data)
         pass
-    
-    def all_states_zero(self,lst):
-
-        """检查列表中所有字典的state是否全为0"""
-        for item in lst:
-            # 检查是否存在state键且其值严格等于0(数字类型)
-            if 'state' not in item or item['state'] != 0:
-                return False
-        return True
-    def get_week_str(self,week):
-        week_str = ""
-        if week == 7:
-            week_str = "周日"
-        elif week == 1:
-            week_str = "周一"
-        elif week == 2:
-            week_str = "周二"
-        elif week == 3:
-            week_str = "周三"
-        elif week == 4:
-            week_str = "周四"
-        elif week == 5:
-            week_str = "周五"
-        elif week == 6:
-            week_str = "周六"
-        return week_str
 
     def get_battery(self, event=None, msg=None):
             """
@@ -1469,6 +1496,7 @@ class SockMangager(Abstract):
             bat_total_value += self.vbat_buf[i]
         bat_total_value = bat_total_value//curr_count#一分钟更新一次电量 10个平均值
         # EventMesh.publish("AI_schedule_open")#读取闹钟数组
+        # print("AI_schedule_open!!!")
         EventMesh.publish("AI_alarm_start") #检查是否有闹钟需要提醒
         EventMesh.publish("AI_schedule_open")#检查日程是否需要提醒
         # self.alarm_test()
@@ -1811,7 +1839,25 @@ class ProtoCol(Abstract):
 
     def recv(self, event, msg):
         pass
+#上报蓝牙连接状态
+class IOTWeb_post_bt_connect_restProtoCol(ProtoCol):
+    """post_bt_connect_rest"""
+    TYPE = "post_bt_connect_rest"
+
+    def send(self, event, msg):
+        # print("send post_bt_connect_rest{}".format(msg))
+        send_data = b''
+        send_data = protocol_send_total_data(msg)
+        print("send post_bt_connect_rest{}".format(send_data))
+        EventMesh.publish("CHANNEL_IOT_WEB_SEND", send_data)
 
+    def recv(self, event, msg):
+        """
+
+        @param event: 心跳成功
+        @param msg: 接收到的下行数据
+        """
+        print("recv post_bt_connect_rest{}".format(msg))
 #电子围栏触发SOS警告
 class IOTWeb_fence_sosProtoCol(ProtoCol):
     """fence_sos"""
@@ -1871,7 +1917,24 @@ class IOTWeb_HRProtoCol(ProtoCol):
         @param event: 心跳成功
         @param msg: 接收到的下行数据
         """
+        # {
+        #     "cmd":"post_rest",
+        #     "ts":1738283829,
+        #     "msg":"消息收到响应",
+        #     "data":{
+        #         "cmd":"post_heart_beat",
+        #         "rest":"bind/unbind",
+        #         "msg":"上报成功/格式错误"
+        #     }
+        # }
         print("recv hr{}".format(msg))
+        if "data" in msg:
+            data = msg["data"]
+            rest = data["rest"]
+            if rest == "unbind": #解绑需要开启蓝牙开关
+                EventMesh.publish("set_storage_config",["switch_bt_state","0"])
+                EventMesh.publish("send_ble_adv_switch","0")
+
 #定位周期
 class IOTWeb_locatedurationProtoCol(ProtoCol):
     """locate_duration"""
@@ -2021,7 +2084,12 @@ class IOTWeb_FindDeviceProtoCol(ProtoCol):
         @param event:定位信息下发
         @param msg: 接收到的下行数据
         """
-        EventMesh.publish("set_sos_info_call")
+        alarm_TTS_str="在这呢"
+        base_sentence = "{}".format(alarm_TTS_str)
+        repeat_sentence = (base_sentence + ",") * 3  # 重复5次并加逗号分隔
+        final_sentence = repeat_sentence.rstrip(",")
+        
+        EventMesh.publish("play_tts",[final_sentence,1])  #播放tts闹钟文本内容
         print("recv find_device{}".format(msg))
         EventMesh.publish(WEB_CMD_ENUM.FIND_DEVCE_S_CMD)
 
@@ -2145,6 +2213,7 @@ class IOTWeb_alarm_listProtoCol(ProtoCol):
                     alarm_list.append(data_list)
                 alarm_list.sort(key=lambda x: x['index'])
                 EventMesh.publish("set_storage_config",["alarm_list",alarm_list])
+                EventMesh.publish("set_alarm_info",alarm_list)
                 alarm_list = EventMesh.publish("get_storage_config","alarm_list")
                 print("alarm_list:{}".format(alarm_list))
             else:
@@ -2456,8 +2525,108 @@ class IOTWeb_voice_recordProtoCol(ProtoCol):
                 
                 print("开始录音")
         
-            
+#设备解绑
+class IOTWeb_unbind_devProtoCol(ProtoCol):
+    """unbind_dev"""
+    TYPE = "unbind_dev"
+    unbind_devtimer = osTimer()
+    init_flag = 0
+    def send(self, event, msg):
+        print("send unbind_dev{}".format(msg))
+        # 通过websocket发送到服务器端
+        date_tmp = utime.localtime()
+        time_tmp = utime.mktime(date_tmp)
+        unbind_dev={
+            "cmd":"unbind_dev",
+            "ts":time_tmp,
+            "msg":"主动解绑设备",
+            "data":None
+        }
+        send_data = b''
+        send_data = protocol_send_total_data(unbind_dev)
+        print("unbind_dev{}".format(send_data))
+        EventMesh.publish("CHANNEL_IOT_WEB_SEND", send_data)
+        self.init_flag=1
+        self.unbind_devtimer.start(2000,0,self.unbind_devtimer_cb)
+    def unbind_devtimer_cb(self,*argc):
+        if self.init_flag == 1:
+            play_str = "设备解绑失败"
+            EventMesh.publish("play_tts",[play_str,1])
 
+    def recv(self, event, msg):
+        """
+
+        @param event:上行下发unbind_dev
+        @param msg: 接收到的下行数据
+        """
+        # {
+        #     "cmd":"post_rest",
+        #     "ts":1738283829,
+        #     "msg":"消息收到响应",
+        #     "data":{
+        #         "cmd":"unbind_dev",
+        #         "rest":"success|error",
+        #         "msg":"收到主动解绑设备指令"
+        #     }
+        # }
+        self.unbind_devtimer.stop()
+        self.init_flag=0
+        if "data" in msg:
+            data = msg["data"]
+            rest = data["rest"]
+            if rest == "success":
+                play_str = "设备解绑成功"
+                EventMesh.publish("play_tts",[play_str,1])
+                pass
+            else:
+                play_str = "设备解绑失败"
+                EventMesh.publish("play_tts",[play_str,1])
+                pass
+        print("recv unbind_dev{}".format(msg))        
+#用户解绑
+class IOTWeb_user_unbind_devProtoCol(ProtoCol):
+    """user_unbind_dev"""
+    TYPE = "user_unbind_dev"
+    def send(self, event, msg):
+        print("send user_unbind_dev{}".format(msg))
+        # 通过websocket发送到服务器端
+        date_tmp = utime.localtime()
+        time_tmp = utime.mktime(date_tmp)
+        user_unbind_dev={
+            "cmd":"dispatch_rest",
+            "ts":time_tmp,
+            "msg":"消息收到响应",
+            "data":{
+                "cmd":"user_unbind_dev",
+                "rest":"success",
+                "msg":"收到用户解绑设备指令"
+            }
+        }
+        send_data = b''
+        send_data = protocol_send_total_data(user_unbind_dev)
+        print("user_unbind_dev{}".format(send_data))
+        EventMesh.publish("CHANNEL_IOT_WEB_SEND", send_data)
+
+    def recv(self, event, msg):
+        """
+
+        @param event:上行下发user_unbind_dev
+        @param msg: 接收到的下行数据
+        """
+        # {
+        #     "cmd":"post_rest",
+        #     "ts":1738283829,
+        #     "msg":"消息收到响应",
+        #     "data":{
+        #         "cmd":"user_unbind_dev",
+        #         "rest":"success|error",
+        #         "msg":"收到主动解绑设备指令"
+        #     }
+        # }
+        EventMesh.publish("set_storage_config",["switch_bt_state","0"])
+        EventMesh.publish("send_ble_adv_switch","0")
+        EventMesh.publish(WEB_CMD_ENUM.USER_UNBIND_DEV_S)
+        print("recv user_unbind_dev{}".format(msg))    
 #下发位子留言
 class IOTWeb_text_msgProtoCol(ProtoCol):
     """text_msg"""
@@ -2639,11 +2808,12 @@ class IOTWeb_scheduleProtoCol(ProtoCol):
             data = msg["data"]
             for i,sh in enumerate(data):
                 sh["index"] = i
-                schedule.ap
                 schedule.append(sh)
             schedule.sort(key=lambda x: x['index'])
             EventMesh.publish("set_storage_config",["schedule",schedule])
+            
             schedule = EventMesh.publish("get_storage_config","schedule")
+            EventMesh.publish("set_schedule_info",schedule)#
             print(schedule)
         EventMesh.publish(WEB_CMD_ENUM.SCHEDULE_S_CMD)
 #