print("end_ota count:{}!!!".format(count))
def bt_ota_run(self,event=None,msg=None):#通过串口给蓝牙升级
- EventMesh.publish("wakeup_BT")
+ # EventMesh.publish("wakeup_BT")
+ EventMesh.publish(constants.EVENT.SYSTEM_UP)#唤醒休眠
print("bt_ota_run!!!:url:{}".format(msg))
print("bt_ota_run!!!")
print("bt_ota_run!!!")
EventMesh.subscribe("Power_off",self.pwk_key_Long_Press)
EventMesh.subscribe("wakeup_BT",self.wakeup_BT)
EventMesh.subscribe("sleep_BT",self.sleep_BT)
- EventMesh.subscribe("sys_sleep_cb",self.sys_sleep_cb)
+ EventMesh.subscribe("sys_sleep_cb",self.sys_sleep_cb)#系统休眠前回调
+ EventMesh.subscribe("sys_up_cb",self.sys_up_cb)#系统唤醒后回调
+
EventMesh.subscribe("GET_USB_STATE",self.get_usb_state)
EventMesh.subscribe("SET_TTS_VOLUME",self.set_tts_volume)
+ EventMesh.subscribe("SET_SPEECH_RATE",self.set_speech_rate)
print("AI_dev:2")
self.pk = PowerKey()
self.VC_TTS_volume = msg
self.aud.setVolume(self.VC_TTS_volume //10)
pass
+ def set_speech_rate(self,event,msg):
+ self.speech_rate = msg
+ EventMesh.publish("set_storage_config",["speech_rate",self.speech_rate])
def btnInfo_queue_thread(self):
while True:
data = self.btnInfo_queue.get()
print("sys_sleep_cb!!!!!!!!!!!!!!!")
print("sys_sleep_cb!!!!!!!!!!!!!!!")
self.PIN_wakeup_bt.write(0)
+ def sys_up_cb(self,event=None,msg=None):#休眠前回调
+ print("sys_up_cb!!!!!!!!!!!!!!!")
+ print("sys_up_cb!!!!!!!!!!!!!!!")
+ print("sys_up_cb!!!!!!!!!!!!!!!")
+ self.wakeup_BT()
+
def wakeup_BT(self,event=None,msg=None):#4G唤醒蓝牙
- self.PIN_wakeup_bt.write(0)
+
count = 150
while(True):
count-=1
#if 0:
self.AI_TTS_str = "检测到有新版本需要升级啦!升级时可千万别断电或乱按哦,升级完成后设备会自动重启,重启就代表升级成功"
EventMesh.publish("publish_AI_btnInfo",{"func":self.AI_VC_start})
+ self.Close_flag = 1
# if self.ai_OTA.min_sys_ota()==2:
# self.AI_TTS_str = "检测到有新版本需要升级啦!电量低于40%,无法保证升级正常执行,请充满电后重启设备再次升级!"
# EventMesh.publish("publish_AI_btnInfo",{"func":self.AI_VC_start})
#VC开始
def AI_VC_start(self):
print("AI_VC_start1")
+ EventMesh.publish(constants.EVENT.SYSTEM_UP)#唤醒休眠
self.VC_satrt_flag = 1
if self.VC_Thinking_timerout < 100:
self.VC_Thinking_timerout = 0
#self.aud.aud_tone_play(16,200)#播放按键音
self.LocalRespondingEnded_timerout = 0
self.close_timerout = 0
-
+ EventMesh.publish("system_sleep_rest")#防止黑屏
#
if self.AI_client_VC_isconnect == 0:#没连接的时候请求开始
#utime.sleep_ms(50)
else:
print("self.VC_state :{}".format(self.VC_state ))
-
+ EventMesh.publish("system_sleep_rest")#防止黑屏
if self.AI_client_VC_isconnect == 0:
return
self.AI_client_VC_start_requset()
PLAY_CONTROL_R="player_control_R"
PLAY_CONTROL_S="player_control_S"
+ CHAT_CONFIG_R ="chat_config_R"
+ CHAT_CONFIG_S="chat_config_S"
+
class IOTSendCmdManager(Abstract):
#
def __init__(self):
usys.print_exception(e)
import ai_alarm as _schedule
DEFIEN_HR_REPORT_TIME = 5*60
-DEFIEN_LOCATION_REPORT_TIME = 30
+DEFINE_TIME_COUNT = 5
+DEFIEN_LOCATION_REPORT_TIME = 5
WEB_CONNECT_MAX_COUNT = 10 #默认重连次数
class SockMangager(Abstract):
def __init__(self):
self.resolver = None
self.timerHr = 0
self.timerLocation = 0
- self.timerSOS = 0
+ self.send_device_time = 0
self.vbat_buf = []
self.network_state = 0
self.curr_battery_level = 0
self.start_voice_flag = 0
self.init_send_default=0
self.play_new_voice_state = 0
+ self.get_voice_new_msginit = 0
+ self.voice_id = "0"
+ self.bt_connect_list = []
+ self.new_voice_list = []
EventMesh.subscribe("REPORT_ALARM_TO_IOT",self.report_alarm_to_iot)
def report_alarm_to_iot(self,event,msg):
self.get_voice_new_msginit = 0
self.bt_connect_list = []
self.new_voice_list = []
- self.connect_web_timer.start(5*1000,0,self.iot_web_connect_timerCb)
+ self.connect_web_timer.start(2000,0,self.iot_web_connect_timerCb)
def save_bt_connect_list(self,event,msg):
if len(self.new_voice_list) != 0:
for i,data in enumerate(self.new_voice_list):
- print("play_new_voice_list:{}".format(data))
+ print("data:{}".format(data))
self.voice_index = i
- self.voice_id = data["id"]
- url = data["url"]
+ self.voice_id = str(data["id"])
+ url = str(data["url"])
# url = "http://qipaiai-oss1.tos-cn-beijing.volces.com/qi_pai_ringtone/2025_08_11/742659759219544064test.mp3"
self.play_new_voice_state = 1
EventMesh.publish("play_new_voice",[url,1])
self.connect_iot_websocket()
def add_support_resolver(self, resolver):
self.resolver = resolver
-
- def hr_report_event_cb(self, *args, **kwargs):
+ def hr_report_event(self, *args, **kwargs):
+ EventMesh.publish("publish_AI_btnInfo",{"func":self.hr_report_event_cb}) #self.connect_iot_websocket()
+ def hr_report_event_cb(self):
"""电池平均值"""
temp = Power.getVbatt()
if self.bat_count < 10:
# self.alarm_test()
EventMesh.publish("set_curr_battery_level",bat_total_value)
# EventMesh.publish("publish_AI_btnInfo",{"func":self.hr_report_publish_event,"data":0})
- self.timerHr+=10
+ self.timerHr+=DEFINE_TIME_COUNT
if self.timerHr >= DEFIEN_HR_REPORT_TIME:
self.timerHr= 0
self.reconnect_count = 0
self.timerLocation = 0
else:
if locate_duration_c != 0:
- self.timerLocation+=10
+ self.timerLocation+=DEFINE_TIME_COUNT
if self.timerLocation >= locate_duration_c:
self.timerLocation= 0
print("timerLocation")
self.timerLocation= 0
- if self.timerSOS <= DEFIEN_LOCATION_REPORT_TIME :
- self.timerSOS+=10
+ if self.send_device_time < DEFIEN_LOCATION_REPORT_TIME :
+ self.send_device_time+=DEFINE_TIME_COUNT
else:
if self.get_voice_new_msginit == 0: #开机获取一次语音未读消息
self.get_voice_new_msginit=1
- EventMesh.publish(WEB_CMD_ENUM.GET_NEW_VOICE_MSG_S,None)
+ EventMesh.publish("publish_AI_btnInfo",{"func":self.hr_report_publish_event,"data":0})
+ device_state=EventMesh.publish("GET_IOT_WEB_SEND_CMD",WEB_CMD_ENUM.POST_DEVICE_STATE_S_CMD)
+ print("device_state{}".format(device_state))
+ EventMesh.publish(WEB_CMD_ENUM.POST_DEVICE_STATE_S_CMD,device_state) #上报设备状态
+
+ EventMesh.publish(WEB_CMD_ENUM.GET_NEW_VOICE_MSG_S)
# http://220.160.104.34:30800/ws-bus/test/voice-record/876226211472149?state=1,
print("self.iot_protocol_client %d self.start_voice_flag:%d",self.iot_protocol_client,self.start_voice_flag)
if self.iot_protocol_client != None:
if self.timer_id == 0:
- self.hr_report_timer.start(10000, 1, self.hr_report_event_cb)
- EventMesh.publish("publish_AI_btnInfo",{"func":self.hr_report_publish_event,"data":0})
- device_state=EventMesh.publish("GET_IOT_WEB_SEND_CMD",WEB_CMD_ENUM.POST_DEVICE_STATE_S_CMD)
- print("device_state{}".format(device_state))
- EventMesh.publish(WEB_CMD_ENUM.POST_DEVICE_STATE_S_CMD,device_state) #上报设备状态
+ self.hr_report_timer.start(DEFINE_TIME_COUNT*1000, 1, self.hr_report_event)
self.timer_id=1
except Exception as e:
TYPE = "fence_sos"
def send(self, event, msg):
- print("send fence_sos{}".format(msg))
+ # print("send fence_sos{}".format(msg))
date_tmp = utime.localtime()
time_tmp = utime.mktime(date_tmp)
# 通过websocket发送到服务器端
@param event: 心跳成功
@param msg: 接收到的下行数据
"""
- EventMesh.publish(WEB_CMD_ENUM.FENCE_SOS_S,None)
+ EventMesh.publish(WEB_CMD_ENUM.FENCE_SOS_S)
sos_list = EventMesh.publish("get_storage_config","sos_list")
if sos_list != None:
if len(sos_list) > 0:
TYPE = "find_device"
def send(self, event, msg):
- print("send locafind_devicetion{}".format(msg))
+ # print("send locafind_devicetion{}".format(msg))
# 通过websocket发送到服务器端
date_tmp = utime.localtime()
time_tmp = utime.mktime(date_tmp)
}
send_data = b''
send_data = protocol_send_total_data(find_device)
- print("send_data find_device{}".format(msg))
+ print("send_data find_device{}".format(send_data))
EventMesh.publish("CHANNEL_IOT_WEB_SEND", send_data)
def recv(self, event, msg):
"""
EventMesh.publish("set_sos_info_call")
print("recv find_device{}".format(msg))
- EventMesh.publish(WEB_CMD_ENUM.FIND_DEVCE_S_CMD,None)
+ EventMesh.publish(WEB_CMD_ENUM.FIND_DEVCE_S_CMD)
#立即定位
class IOTWeb_LocateNowProtoCol(ProtoCol):
@param msg: 接收到的下行数据
"""
- EventMesh.publish(WEB_CMD_ENUM.LOCATION_NOW_S_CMD,None)
+ EventMesh.publish(WEB_CMD_ENUM.LOCATION_NOW_S_CMD)
print("recv locate_now{}".format(msg))
EventMesh.publish(constants.EVENT.START_LOCATION,WEB_CMD_ENUM.POST_LOCATION_S_CMD) #开始定位 定位完之后上报定位数据
TYPE = "alarm_config"
def send(self, event, msg):
- print("send locafind_devicetion{}".format(msg))
+ # print("send alarm_config{}".format(msg))
# 通过websocket发送到服务器端
date_tmp = utime.localtime()
time_tmp = utime.mktime(date_tmp)
}
send_data = b''
send_data = protocol_send_total_data(alarm_config)
- print("send_data alarm_config{}".format(msg))
+ print("send_data alarm_config{}".format(send_data))
EventMesh.publish("CHANNEL_IOT_WEB_SEND", send_data)
def recv(self, event, msg):
@param msg: 接收到的下行数据
"""
print("recv alarm_config{}".format(msg))
- EventMesh.publish(WEB_CMD_ENUM.ALARM_CONFIG_S_CMD,None)
+ EventMesh.publish(WEB_CMD_ENUM.ALARM_CONFIG_S_CMD)
#SOS联系人下发
class IOTWeb_sos_listProtoCol(ProtoCol):
EventMesh.publish("set_storage_config",["sos_list",sos_list])
read_soslist = EventMesh.publish("get_storage_config","sos_list")
print(read_soslist)
- EventMesh.publish(WEB_CMD_ENUM.SOS_LIST_S_CMD,None)
+ EventMesh.publish(WEB_CMD_ENUM.SOS_LIST_S_CMD)
#闹钟铃声下发
class IOTWeb_volumeProtoCol(ProtoCol):
r_volume = msg["data"]
print("recv volume{} type:{}".format(r_volume,type(msg)))
EventMesh.publish("SET_TTS_VOLUME",int(r_volume))
- EventMesh.publish(WEB_CMD_ENUM.VOLUME_S_CMD,None)
+ EventMesh.publish(WEB_CMD_ENUM.VOLUME_S_CMD)
#下发SOS配置
class IOTWeb_sos_configProtoCol(ProtoCol):
"""sos_config"""
EventMesh.publish("set_storage_config",["sos_config",sos_config])
sos_config = EventMesh.publish("get_storage_config","sos_config")
print("sos_config:{} type:{}".format(sos_config,sos_config["enable110"]))
- EventMesh.publish(WEB_CMD_ENUM.SOS_CONFIG_S_CMD,None)
+ EventMesh.publish(WEB_CMD_ENUM.SOS_CONFIG_S_CMD)
#闹钟铃声获取
class IOTWeb_get_ringtoneProtoCol(ProtoCol):
print("下发文字留言出错了")
EventMesh.publish(WEB_CMD_ENUM.TEXT_MSG_S_CMD,recv_state)
+#AI对话音色配置
+class IOTWeb_chat_configProtoCol(ProtoCol):
+ """chat_config"""
+ TYPE = "chat_config"
+ def send(self, event, msg):
+ # print("send chat_config{}".format(msg))
+ # 通过websocket发送到服务器端
+ date_tmp = utime.localtime()
+ time_tmp = utime.mktime(date_tmp)
+ chat_config = {
+ "cmd":"dispatch_rest",
+ "ts":time_tmp,
+ "msg":"消息收到响应",
+ "data":{
+ "cmd":"chat_config",
+ "rest":"success",
+ "msg":"收到AI对话配置"
+ }
+ }
+ send_data = b''
+ send_data = protocol_send_total_data(chat_config)
+ print("send_data chat_config{}".format(send_data))
+ EventMesh.publish("CHANNEL_IOT_WEB_SEND", send_data)
+
+ def recv(self, event, msg):
+ """
+
+ @param event:上行下发chat_config
+ @param msg: 接收到的下行数据
+ """
+ print("recv chat_config{}".format(msg))
+ # {
+ # "cmd":"chat_config",
+ # "ts":1738283829,
+ # "msg":"下发AI对话配置",
+ # "data":{
+ # "speed":1.5,
+ # "vadDuration":600,
+ # "voiceId":"音色ID,火山音色或者科大讯飞音色ID"
+ # }
+ # }
+ if "data" in msg:
+ data = msg["data"]
+ speed = data["speed"]
+ vadDuration = data["vadDuration"]
+ voiceId = data["voiceId"]
+ EventMesh.publish("SET_SPEECH_RATE",speed)
+ EventMesh.publish(WEB_CMD_ENUM.CHAT_CONFIG_S)
+#获取AI对话音色配置
+class IOTWeb_get_chat_configProtoCol(ProtoCol):
+ """get_chat_config"""
+ TYPE = "get_chat_config"
+
+ def send(self, event, msg):
+ # print("send chat_config{}".format(msg))
+ # 通过websocket发送到服务器端
+ date_tmp = utime.localtime()
+ time_tmp = utime.mktime(date_tmp)
+ get_chat_config = {
+ "cmd":"get_chat_config",
+ "ts":time_tmp,
+ "msg":"获取AI对话配置",
+ "data":None
+ }
+ send_data = b''
+ send_data = protocol_send_total_data(get_chat_config)
+ print("send_data chat_config{}".format(send_data))
+ EventMesh.publish("CHANNEL_IOT_WEB_SEND", send_data)
+
+ def recv(self, event, msg):
+ """
+
+ @param event:上行下发get_chat_config
+ @param msg: 接收到的下行数据
+ """
+ print("recv get_chat_config{}".format(msg))
#下发日程
class IOTWeb_scheduleProtoCol(ProtoCol):
"""schedule"""
EventMesh.publish("set_storage_config",["schedule",schedule])
schedule = EventMesh.publish("get_storage_config","schedule")
print(schedule)
- EventMesh.publish(WEB_CMD_ENUM.SCHEDULE_S_CMD,None)
+ EventMesh.publish(WEB_CMD_ENUM.SCHEDULE_S_CMD)
#
class IOTWeb_new_voice_msgProtoCol(ProtoCol):
"""new_voice_msg"""
TYPE = "new_voice_msg"
def send(self, event, msg):
- print("send new_voice_msg{}".format(msg))
+ # print("send new_voice_msg{}".format(msg))
# 通过websocket发送到服务器端
date_tmp = utime.localtime()
time_tmp = utime.mktime(date_tmp)
send_data = protocol_send_total_data(new_voice_msg)
print("send send_data{}".format(send_data))
EventMesh.publish("CHANNEL_IOT_WEB_SEND",send_data)
- EventMesh.publish(WEB_CMD_ENUM.GET_NEW_VOICE_MSG_S,None)
+ EventMesh.publish(WEB_CMD_ENUM.GET_NEW_VOICE_MSG_S)
def recv(self, event, msg):
"""
@param event:new_voice_msg
@param msg: 接收到的下行数据
"""
- EventMesh.publish(WEB_CMD_ENUM.NEW_VOICE_MSG_S,None)
+ EventMesh.publish(WEB_CMD_ENUM.NEW_VOICE_MSG_S)
print("recv new_voice_msg{}".format(msg))
@param event:new_voice_msg_list
@param msg: 接收到的下行数据
"""
- # new_voice_msg_list = {
- # "cmd":"new_voice_msg_list",
- # "ts":1738283829,
- # "msg":"请求未读的语音消息列表",
- # "data":[
- # {
- # "id":"语音ID",
- # "url": "音频地址",
- # "size": 0,
- # "from": "user/dev",
- # "duration": 12,
- # "deviceId": "设备ID",
- # "userId": "用户ID",
- # "userReadState": "1",
- # "deviceReadState": "1",
- # "md5": "md5",
- # "fileName": "文件名"
- # }
- # ]
- # }
new_voice_list = []
if "data" in msg:
data = msg["data"]
- for da in enumerate(data):
+ for da in data:
new_voice_list.append(da)
if len(new_voice_list) > 0:
EventMesh.publish("set_play_new_voice_list",new_voice_list)
EventMesh.publish("play_new_voice_list")
- EventMesh.publish(WEB_CMD_ENUM.NEW_VOICE_MSG_LIST_S,None)
+ EventMesh.publish(WEB_CMD_ENUM.NEW_VOICE_MSG_LIST_S)
print("recv new_voice_msg_list{}".format(msg))
class IOTWeb_put_voice_msg_stateProtoCol(ProtoCol):
"""put_voice_msg_state"""
# "data": None
# }
EventMesh.publish("send_get_connect_bt_state")
- EventMesh.publish(WEB_CMD_ENUM.GET_BT_CONNECT_RECORD_LIST_S,None)
+ EventMesh.publish(WEB_CMD_ENUM.GET_BT_CONNECT_RECORD_LIST_S)
print("recv get_bt_connect_record_list{}".format(msg))
#蓝牙开关
TYPE = "switch_bt_state"
def send(self, event, msg):
- print("send schedule{}".format(msg))
+ # print("send switch_bt_state{}".format(msg))
# 通过websocket发送到服务器端
date_tmp = utime.localtime()
time_tmp = utime.mktime(date_tmp)
pass
print("recv switch_bt_state{}".format(msg))
- EventMesh.publish(WEB_CMD_ENUM.SWITCH_BT_STATE_S_CMD,None)
+ EventMesh.publish(WEB_CMD_ENUM.SWITCH_BT_STATE_S_CMD)
#蓝牙扫描
class IOTWeb_bt_scanProtoCol(ProtoCol):
TYPE = "disconnect_bt"
def send(self, event, msg):
- print("send schedule{}".format(msg))
+ # print("send sc/hedule{}".format(msg))
# 通过websocket发送到服务器端
date_tmp = utime.localtime()
time_tmp = utime.mktime(date_tmp)
mac = msg["data"]
EventMesh.publish("send_disconnect_bt_mac",mac)
print("recv disconnect_bt{}".format(msg))
- EventMesh.publish(WEB_CMD_ENUM.DISCONNECT_BT_S,None)
+ EventMesh.publish(WEB_CMD_ENUM.DISCONNECT_BT_S)
class LK_ProtoCol(ProtoCol):
"""链路保持"""