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
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
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):
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 = ""
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":#柒牌
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):
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
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
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''
# 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):
"""
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()
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"""
@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"""
@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)
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:
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"""
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)
#