voice_record_satrt_flag = EventMesh.publish("get_voice_record_flag")#获取静默或者语音留言是否在运行
if voice_record_satrt_flag == None:
voice_record_satrt_flag = 0
- if VC_satrt_flag == 0 or voice_record_satrt_flag == 0:
+ if VC_satrt_flag == 0 and voice_record_satrt_flag == 0:
self.aud.stop()
#EventMesh.publish("flicker_led_red")#充电闪灯
#self.aud.play(1,1,'U:/static/R_CHARGE_IN.mp3')
voice_record_satrt_flag = EventMesh.publish("get_voice_record_flag")#获取静默或者语音留言是否在运行
if voice_record_satrt_flag == None:
voice_record_satrt_flag = 0
- if VC_satrt_flag == 0 or voice_record_satrt_flag == 0:
+ if VC_satrt_flag == 0 and voice_record_satrt_flag == 0:
self.aud.stop()
EventMesh.publish("close_led")
EventMesh.publish("audio_montage_play",["R_CHARGE_OUT.mp3"])
VC_satrt_flag = EventMesh.publish("get_VC_satrt_flag")#获取vc是否在运行
if VC_satrt_flag == None:
VC_satrt_flag = 0
+ voice_record_satrt_flag = EventMesh.publish("get_voice_record_flag")#获取静默或者语音留言是否在运行
+ if voice_record_satrt_flag == None:
+ voice_record_satrt_flag = 0
Vbatt = Power.getVbatt()
- if self.usb_status == 1 and VC_satrt_flag == 0:
+ if self.usb_status == 1 and VC_satrt_flag == 0 and voice_record_satrt_flag == 0:
EventMesh.publish("open_led_red")#充电红灯常亮
- if self.usb_status == 1 and Vbatt>=self.VBATT_tab["charge_full"]and VC_satrt_flag == 0:#充电充满
+ if self.usb_status == 1 and Vbatt>=self.VBATT_tab["charge_full"]and VC_satrt_flag == 0 and voice_record_satrt_flag == 0:#充电充满
EventMesh.publish("open_led_green")
if self.usb_charge_flag == 0 :
EventMesh.publish("audio_montage_play",["R_CHARGE_FULL.mp3"])
#self.aud.play(1,0,'U:/static/R_CHARGE_FULL.mp3')#充电已满
self.usb_charge_flag = 1
- if self.usb_status == 0 and Vbatt<self.VBATT_tab["20"]and VC_satrt_flag == 0 and self.Low_power_warning_flag ==0:#低电报警
+ if self.usb_status == 0 and Vbatt<self.VBATT_tab["20"]and VC_satrt_flag == 0 and self.Low_power_warning_flag ==0 and voice_record_satrt_flag == 0:#低电报警
self.Low_power_warning_flag = 1
EventMesh.publish("flicker_led_red")
#self.aud.play(1,0,'Low_power_warning.mp3')
VC_satrt_flag = EventMesh.publish("get_VC_satrt_flag")#获取vc是否在运行
if VC_satrt_flag == None:
VC_satrt_flag = 0
- if VC_satrt_flag == 0 or count<=0:
+ voice_record_satrt_flag = EventMesh.publish("get_voice_record_flag")#获取静默或者语音留言是否在运行
+ if voice_record_satrt_flag == None:
+ voice_record_satrt_flag = 0
+ if VC_satrt_flag == 0 or count<=0 or voice_record_satrt_flag == 0:
break
utime.sleep_ms(100)
else:
EventMesh.publish("publish_AI_btnInfo",{"func":self.websocket_error,"data":jsload_data["payload"]["message"]})
pass
- if self.play_new_voice_flag == 1:
- self.play_new_voice_flag=0
+ if EventMesh.publish("get_play_new_voice_state")== 1:
+ EventMesh.publish("set_play_new_voice_state",1)
EventMesh.publish("update_play_new_voice_info")
EventMesh.publish("play_new_voice_list")
pass
elif jsload_data["event"] == "audio.convert.completed":#接口
- if self.play_new_voice_flag == 1:
- self.play_new_voice_flag=0
+ if EventMesh.publish("get_play_new_voice_state")== 1:
+ EventMesh.publish("set_play_new_voice_state",1)
EventMesh.publish("update_play_new_voice_info")
EventMesh.publish("play_new_voice_list")
except Exception as e:
usys.print_exception(e)
EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位
+ utime.sleep_ms(1000)
wifiScan.control(0)
BT_CONNECT_RECORD_LIST_R="bt_connect_record_list_R"
BT_CONNECT_RECORD_LIST_S="bt_connect_record_list_S"
+ FENCE_SOS_R="fence_sos_R"
+ FENCE_SOS_S="fence_sos_S"
+
+ PLAY_CONTROL_R="player_control_R"
+ PLAY_CONTROL_S="player_control_S"
+
class IOTSendCmdManager(Abstract):
#
def __init__(self):
if EventMesh.publish("get_storage_config","sos_config") != None:
self.sos_config= EventMesh.publish("get_storage_config","sos_config")
- self.sos_list=[{"index":0,"phone":"15521469561","name":"dengxueying0"}, {"name":"dengxueying1","index":0,"phone":"15692025051"},{"name":"dengxueying2","index":0,"phone":"15521469561"}]
+ # self.sos_list=[{"index":0,"phone":"15521469561","name":"dengxueying0"}, {"name":"dengxueying1","index":0,"phone":"15692025051"},{"name":"dengxueying2","index":0,"phone":"15521469561"}]
EventMesh.subscribe("call_out_cb", self.call_out_cb)
EventMesh.subscribe("get_sos_flag", self.get_sos_flag)
if self.call_state == 0:
ret = voiceCall.callStart(self.sos_phone_num)
if ret == -1:
- self.call_state = 0
- self.num=0 #不管有没有拨打sos都清除
- self.num_len = 0
- self.sos_flag = 0
+
tts_str = "请确认卡支持语音拨号及余额充足"
EventMesh.publish("stop_voice_record") #电话优先级最高
EventMesh.publish("stop_AI_record")
EventMesh.publish("play_tts",[tts_str,1]) #播放tts闹钟文本内容
-
- return
+ self.call_state = 0
+ self.num=0 #不管有没有拨打sos都清除
+ self.num_len = 0
+ self.sos_flag = 0
+ return -1
+ else:
+ EventMesh.publish(constants.EVENT.START_LOCATION,WEB_CMD_ENUM.POST_SOS_S_CMD) #开始AL定位
+ self.sos_timer2.start(30000, 0, self.sos_time_out_phone)
+ return 1
def phone110112_cb(self,*argc):
if self.call_state == 0:
if self.call_state == 0:
self.sos_phone_num = phonenumber
- self.sos_timer1.start(4000, 0, self.sos_call_out_phone)
- self.sos_timer2.start(30000, 0, self.sos_time_out_phone)
- EventMesh.publish(constants.EVENT.START_LOCATION,WEB_CMD_ENUM.POST_SOS_S_CMD) #开始AL定位
+ self.sos_timer1.start(2000, 0, self.sos_call_out_phone)
+
+
def sos_time_out_phone(self, msg):#30s超时未打通或者信号不好则重新拨打
if self.sos_flag == 1:
if self.call_state == 0 or self.call_state == 3 or self.call_state == 4:
voiceCall.callEnd() #挂断
- self.set_sos_info_call(1,1)
+ EventMesh.publish("set_sos_info_call") #电话优先级最高
pass #再次拨打
def set_sos_info_call(self,event,msg):
if sim.getStatus() != 1:#网络正常
+ tts_str = "无SIM卡"
+ EventMesh.publish("stop_voice_record") #电话优先级最高
+ EventMesh.publish("stop_AI_record")
+ EventMesh.publish("play_tts",[tts_str,1]) #播放tts闹钟文本内容
self.sos_flag = 0
self.num = 0
self.call_state = 0
self.num=0 #不管有没有拨打sos都清除
self.num_len = 0
self.sos_flag = 0
- tts_str = "无SIM卡"
- EventMesh.publish("stop_voice_record") #电话优先级最高
- EventMesh.publish("stop_AI_record")
- EventMesh.publish("play_tts",[tts_str,1]) #播放tts闹钟文本内容
return
if self.call_state != 0:
return
usys.print_exception(e)
import ai_alarm as _schedule
DEFIEN_HR_REPORT_TIME = 5*60
-DEFIEN_LOCATION_REPORT_TIME = 60
+DEFIEN_LOCATION_REPORT_TIME = 30
WEB_CONNECT_MAX_COUNT = 10 #默认重连次数
class SockMangager(Abstract):
def __init__(self):
self.timer_id = 0
self.start_voice_flag = 0
self.init_send_default=0
+ self.play_new_voice_state = 0
EventMesh.subscribe("REPORT_ALARM_TO_IOT",self.report_alarm_to_iot)
def report_alarm_to_iot(self,event,msg):
EventMesh.subscribe("send_bt_scan_list",self.send_bt_scan_list)
EventMesh.subscribe("save_bt_connect_list",self.save_bt_connect_list)
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)
# count = 0
# while True:
# count += 1
# self.network_state = 1
# break
# print("web等待网络 {}...".format(count))
+
# utime.sleep_ms(500)
- self.connect_web_timer.start(5*1000,0,self.iot_web_connect_timerCb)
self.timerHr = 0
self.reconnect_count = 0
self.voice_id = "0"
self.deviceReadState = ""
- self.reconnect_count = 0
- self.test_id = 0
+ 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)
+
def save_bt_connect_list(self,event,msg):
print("msg:{}".format(msg))
self.new_voice_list = msg
pass
+ def set_play_new_voice_state(self,event,msg):
+ self.play_new_voice_state = msg
+ pass
+
+ def get_play_new_voice_state(self,event,msg):
+ return self.play_new_voice_state
+
def play_new_voice_list(self,event,msg):
print("play_new_voice_list:{}".format(len(self.new_voice_list)))
if len(self.new_voice_list) != 0:
self.voice_id = data["id"]
url = 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])
break
def send_jm_audio_to_iot(self,event,msg):
send_data = b''
send_data = protocol_audio_ji_playload_data(msg[0],msg[1],msg[2])
- print("jm:{}".format(send_data[9]))
+ # print("jm:{}".format(msg[2]))
EventMesh.publish("CHANNEL_IOT_WEB_SEND",send_data)
pass
def send_yuyin_audio_to_iot(self,event,msg):
send_data = b''
send_data = protocol_yuyin_voice_playload_data(msg[0],msg[1],msg[2])
- print("yuyin:{}".format(msg[2]))
+ # print("yuyin:{}".format(msg[2]))
EventMesh.publish("CHANNEL_IOT_WEB_SEND",send_data)
pass
self.timerLocation= 0
print("timerLocation")
EventMesh.publish(constants.EVENT.START_LOCATION,WEB_CMD_ENUM.POST_LOCATION_S_CMD) #定位上报
+ else:
+ self.timerLocation= 0
- self.timerSOS+=1
- if self.timerSOS >= DEFIEN_LOCATION_REPORT_TIME:
- self.timerSOS= 0
- print("timerSOS")
- date_tmp = utime.localtime()
- time_tmp = utime.mktime(date_tmp)
- get_new_voice_msg = {
- "cmd":"get_new_voice_msg",
- "ts":time_tmp,
- "msg":"请求未读的语音消息列表",
- "data":None
- }
-
- send_data = b''
- send_data = protocol_send_total_data(get_new_voice_msg)
- print("send send_data{}".format(send_data))
- EventMesh.publish(WEB_CMD_ENUM.GET_NEW_VOICE_MSG_S,send_data)
+
+ if self.timerSOS <= DEFIEN_LOCATION_REPORT_TIME :
+ self.timerSOS+=10
+ 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)
- # alarm_config=EventMesh.publish("GET_IOT_WEB_SEND_CMD",WEB_CMD_ENUM.POST_ALARM_S_CMD)
- # print("alarm_config{}".format(alarm_config))
- # EventMesh.publish(WEB_CMD_ENUM.POST_ALARM_S_CMD,alarm_config)
-
- # HR_DATA=EventMesh.publish("GET_IOT_WEB_SEND_CMD",WEB_CMD_ENUM.POST_DEVICE_STATE_S_CMD)
- # print("HR_DATA{}".format(HR_DATA))
- # EventMesh.publish(WEB_CMD_ENUM.POST_DEVICE_STATE_S_CMD,HR_DATA) #上报设备状态
-
- # EventMesh.publish(constants.EVENT.START_LOCATION,WEB_CMD_ENUM.POST_SOS_S_CMD) #sos上报
-
+
# http://220.160.104.34:30800/ws-bus/test/voice-record/876226211472149?state=1,
# http://220.160.104.34:30800/ws-bus/test/876226211472149?testType=alarmList
def hr_report_publish_event(self,data):
if sim.getStatus() != 1 or self.start_voice_flag == 1:#网络正常
return
-
+
if self.reconnect_count >= WEB_CONNECT_MAX_COUNT: #重连次数大于10次不在进重连只有下发心跳才重新连接
return
token = EventMesh.publish("get_dev_token")
def socket_send_queue_thread(self):
while True:
data = self.iot_web_send_queue.get()
- EventMesh.debug_log("websocket:send data1 len:{}".format(len(data)))
+
if data != None:
+ # EventMesh.debug_log("websocket:send data1 len:{}".format(len(data)))
try:
- EventMesh.debug_log("websocket:send data1 len:{} {}".format(len(data),self.iot_protocol_client))
+ # EventMesh.debug_log("websocket:send data1 len:{} {}".format(len(data),self.iot_protocol_client))
if self.iot_protocol_client != None:
self.iot_protocol_client.send(data)
self.reconnect_count = 0
else:
- self.reconnect_count+=1
# EventMesh.publish("connect_iot_websocket_cb")
EventMesh.publish("publish_AI_btnInfo",{"func":self.connect_iot_websocket})
- EventMesh.debug_log("websocket:send data2 len:{}".format(len(data)))
+ EventMesh.debug_log("websocket:send data2 len:{}".format(len(data),self.iot_protocol_client))
except Exception as e:
EventMesh.debug_log("websocket:send error")
- self.reconnect_count+=1
# EventMesh.publish("connect_iot_websocket_cb")
EventMesh.publish("publish_AI_btnInfo",{"func":self.connect_iot_websocket})
break
- utime.sleep_ms(10)
def iot_protocol_recv(self):
if recv_data == "websocket close":
# 服务器关闭连接或客户端关闭连接
print("对端 服务器强制关闭 cli close")
- self.reconnect_count+=1
# EventMesh.publish("connect_iot_websocket_cb")
EventMesh.publish("publish_AI_btnInfo",{"func":self.connect_iot_websocket})
break
except Exception as e:
print("cli break")
- self.reconnect_count+=1
# EventMesh.publish("connect_iot_websocket_cb")
EventMesh.publish("publish_AI_btnInfo",{"func":self.connect_iot_websocket})
break
- utime.sleep_ms(10)
self.iot_web_protoclo_recv_id =None
def iot_web_send_queue_close(self):
def iot_close_web_therad(self):
try:
self.iot_web_send_queue_close()
- print("iot_web_send_queue_close sucess!!!!!!!!")
except Exception as e:
print("iot_web_send_queue_close error!!!!!!!!")
try:
self.iot_web_protoclo_recv_close_therad()
- print("iot_web_protoclo_recv_close_therad sucess!!!!!!!!")
except Exception as e:
print("iot_web_protoclo_recv_close_therad error!!!!!!!!")
self.start_voice_flag = 0
else :
try:
if self.start_voice_flag == 0: #如果关闭了就需要重新再
- self.reconnect_count+=1
EventMesh.publish("publish_AI_btnInfo",{"func":self.connect_iot_websocket})
return
-
- self.iot_web_send_queue.put(data)
- EventMesh.debug_log("self.socket_send_queue.put:success:{}".format(len(data)))
+ if data != None:
+ if len(data) != 0:
+ self.iot_web_send_queue.put(data)
+ # EventMesh.debug_log("self.socket_send_queue.put:success:{}".format(len(data)))
except Exception as e:
EventMesh.debug_log("self.socket_send_queue.put:ERROR:")
usys.print_exception(e)
def recv(self, event, msg):
pass
-#上报心跳
+#电子围栏触发SOS警告
class IOTWeb_fence_sosProtoCol(ProtoCol):
"""fence_sos"""
TYPE = "fence_sos"
def send(self, event, msg):
print("send fence_sos{}".format(msg))
+ date_tmp = utime.localtime()
+ time_tmp = utime.mktime(date_tmp)
# 通过websocket发送到服务器端
+ fence_sos = {
+ "cmd":"dispatch_rest",
+ "ts":time_tmp,
+ "msg":"消息收到响应",
+ "data":{
+ "cmd":"fence_sos",
+ "rest":"success",
+ "msg":"收到紧急呼叫指令"
+ }
+ }
send_data = b''
- send_data = protocol_send_total_data(msg)
+ send_data = protocol_send_total_data(fence_sos)
+ print("send fence_sos{}".format(send_data))
EventMesh.publish("CHANNEL_IOT_WEB_SEND", send_data)
def recv(self, event, msg):
@param event: 心跳成功
@param msg: 接收到的下行数据
"""
+ EventMesh.publish(WEB_CMD_ENUM.FENCE_SOS_S,None)
sos_list = EventMesh.publish("get_storage_config","sos_list")
if sos_list != None:
if len(sos_list) > 0:
if get_sos_flag == 0:
EventMesh.publish("set_sos_info_call")
pass
+
print("recv fence_sos{}".format(msg))
#上报心跳
class IOTWeb_HRProtoCol(ProtoCol):
send_data = b''
send_data = protocol_send_total_data(get_new_voice_msg)
print("send get_new_voice_msg{}".format(send_data))
- EventMesh.publish("CHANNEL_IOT_WEB_SEND",msg)
+ EventMesh.publish("CHANNEL_IOT_WEB_SEND",send_data)
def recv(self, event, msg):
"""
# "msg":"收到请求新语音列表."
# }
# }
- print("recv send_data{}".format(msg))
+ print("recv get_new_voice_msg{}".format(msg))
+# 1播放 0暂停 2上一首 3下一首
+class IOTWeb_player_controlProtoCol(ProtoCol):
+ """player_control"""
+ TYPE = "player_control"
+ def send(self, event, msg):
+ # 通过websocket发送到服务器端
+ date_tmp = utime.localtime()
+ time_tmp = utime.mktime(date_tmp)
+ paly_str = "停止"
+ paly_data = "stop"
+ if msg == 1:
+ paly_str = "播放"
+ paly_data = "play"
+ pass
+ elif msg == 0:
+ paly_str = "停止"
+ paly_data = "stop"
+ pass
+ elif msg == 2:
+ paly_str = "上一首"
+ paly_data = "pre"
+ pass
+ elif msg == 3:
+ paly_str = "下一首"
+ paly_data = "next"
+ pass
+ player_control = {
+ "cmd":"player_control",
+ "ts":time_tmp,
+ "msg":paly_str,
+ "data":paly_data
+ }
+
+ send_data = b''
+ send_data = protocol_send_total_data(player_control)
+ print("send player_control{}".format(send_data))
+ EventMesh.publish("CHANNEL_IOT_WEB_SEND",msg)
+
+ def recv(self, event, msg):
+ """
+
+ @param event:get_new_voice_msg
+ @param msg: 接收到的下行数据
+ """
+ # {
+ # "cmd":"post_rest",
+ # "ts":1738283829,
+ # "msg":"消息收到响应",
+ # "data":{
+ # "cmd":"player_control",
+ # "rest":"success|error",
+ # "msg":"收到播放/停止/暂停指令/下一首/上一首"
+ # }
+ # }
+ paly_state = 0
+ if "data" in msg:
+ data = msg["data"]
+ msg_str = data["msg"]
+ if msg_str.find("播放") != -1:
+ paly_state=1
+ pass
+ elif msg_str.find("停止") != -1:
+ paly_state=0
+ pass
+ elif msg_str.find("下一首") != -1:
+ paly_state = 3
+ pass
+ elif msg_str.find("上一首") != -1:
+ paly_state = 2
+ pass
+
+ EventMesh.publish(WEB_CMD_ENUM.PLAY_CONTROL_S,paly_state)
+ print("recv send_data{}".format(msg))
class IOTWeb_new_voice_msg_listProtoCol(ProtoCol):
"""new_voice_msg_list"""
TYPE = "new_voice_msg_list"