修复一段时间内语音控制出现挂起;新增新设备

This commit is contained in:
sityliu 2024-05-23 00:23:26 +08:00
parent f3cbb2082b
commit 43aa1ec665
17 changed files with 67 additions and 46 deletions

View File

@ -31,6 +31,16 @@ gedit config.py
**加入系统自启动方法:**
将`start_system.service`文件复制到`/etc/systemd/system/`下,然后使用 `systemctl enable start_system.service`设置开机启动服务
设置USB设备绑定
将`ttyUSBLink.rules`文件复制到`/etc/udev/rules.d/`下然后重新插拔USB设备即可刷新
### 目结构:

Binary file not shown.

Binary file not shown.

View File

@ -21,9 +21,10 @@ class Config:
EQUIPMENT_TEMPERATURE_UP = '/python/mqtt/equipment_temperature'
LOCAL_STATUS_UP = '/python/mqtt/local_status'
# 订阅话题
# 发布/订阅话题
VOICE_CMD_SUB = '/python/mqtt/voice_cmd'
ACTION_CMD_SUB = 'dc4f224c4ebe'
ACTION_socket = 'dc4f224c4ebe'
ACTION_water_heater = '08f9e07db383'
# 程序变量
RUN_FLAG = 1

View File

@ -20,6 +20,14 @@
校验语音模块AA 55 03 55 AA 返回=> aa 19不播放语音
电蚊香:
打开AA DF
关闭BB DF
热水器:
打开CC AF
关闭DD BF
485 红外2
第一组68 08 00 FF 12 00 11 16
第二组68 08 00 FF 12 01 12 16

View File

@ -109,3 +109,4 @@
2024-05-12 01:59:03,325 - voice_processing.pyw - ERROR - Instruction error; error command: ffffffffff
2024-05-12 02:04:57,694 - voice_processing.pyw - ERROR - Instruction error; error command: ffffffffff
2024-05-12 02:05:00,083 - main.py1 - ERROR - Thread died, restarting
2024-05-16 22:50:18,123 - master_control.pyw - ERROR - 请检查/dev/control_usb1串口是否被占用或者串口出现异常

17
main.py
View File

@ -73,7 +73,7 @@ def run_local_status(mqtt_client):
def run_start_main(mqtt_client):
voice = master_control.open_serial(Config.VOICE_OPEN_SERIAL, 9600, 0.3)
voice = master_control.open_serial(Config.VOICE_OPEN_SERIAL, 115200, 0.3)
while True:
ser_cmd = voice_processing.get_voice_data(voice)
@ -103,10 +103,18 @@ def run_start_main(mqtt_client):
client.callback_result = 'xxx'
# WIFI插座
elif (ser_cmd == 'bba1') or (client.callback_result == 'bba1'):
action_cmd.action(client, Config.ACTION_CMD_SUB, 'a1')
action_cmd.action(client, Config.ACTION_socket, 'a1')
client.callback_result = 'xxx'
elif (ser_cmd == 'bbb1') or (client.callback_result == 'bbb1'):
action_cmd.action(client, Config.ACTION_CMD_SUB, 'b1')
action_cmd.action(client, Config.ACTION_socket, 'b1')
client.callback_result = 'xxx'
# 打开热水器
elif (ser_cmd == 'ccaf') or (client.callback_result == 'ccaf'):
action_cmd.action(client, Config.ACTION_water_heater, 'a1')
client.callback_result = 'xxx'
# 关闭热水器
elif (ser_cmd == 'ddbf') or (client.callback_result == 'ddbf'):
action_cmd.action(client, Config.ACTION_water_heater, 'b1')
client.callback_result = 'xxx'
# 校验语音模块串口是否运行异常
@ -139,7 +147,8 @@ if __name__ == '__main__':
run_start_main_thread.start()
client.subscribe(Config.VOICE_CMD_SUB)
client.subscribe(Config.ACTION_CMD_SUB)
client.subscribe(Config.ACTION_socket)
client.subscribe(Config.ACTION_water_heater)
while True:
time.sleep(20)

Binary file not shown.

Binary file not shown.

View File

@ -1,10 +1,4 @@
import os
from src import SaveLogger
@ -14,4 +8,4 @@ save_log = SaveLogger(os.path.basename(__file__), log_file=log_file_path)
def action(client, topic, data_msg) -> None:
client.publish(topic, data_msg)
save_log.info(topic + " => " + "发布的信息:" + data_msg)
save_log.info(topic + " => " + "发布的信息:" + data_msg)

View File

@ -20,37 +20,35 @@ save_log_error = SaveLogger('voice_processing.pyw', log_file=log_file_path1)
def get_voice_data(ser_data):
com_input1 = None # 初始化为None避免后续引用前未定义的问题
try:
com_input1 = ser_data.readline()
except Exception as e:
save_log_error.error(f'get_voice_data(); com_input = ser_data.readline(); Error: {e}')
return # 或者根据需要处理异常后继续或终止函数执行
com_input = ser_data.readline()
# 确保com_input1有值后再进行后续判断
if com_input1:
com_input1_hex = com_input1.hex()
# 开灯
if com_input1_hex == 'a487':
save_log.info(f'开灯指令处理完返回,command:{com_input1_hex}')
# 关灯
elif com_input1_hex == 'a488':
save_log.info(f'关灯指令处理完返回,command:{com_input1_hex}')
# 暖色灯
elif com_input1_hex == 'd366':
save_log.info(f'打开暖色灯指令处理完返回,command:{com_input1_hex}')
# 关暖色灯
elif com_input1_hex == 'd388':
save_log.info(f'关闭暖色灯指令处理完返回,command:{com_input1_hex}')
# 打开WIFI插座01
elif com_input1_hex == 'bba1':
save_log.info(f'打开WIFI插座指令处理完返回,command:{com_input1_hex}')
# 关闭WIFI插座01
elif com_input1_hex == 'bbb1':
save_log.info(f'关闭WIFI插座指令处理完返回,command:{com_input1_hex}')
elif com_input1_hex in ('aa15', 'aa19', 'aa12', 'ffffffffff'):
pass
else:
save_log_error.error(f'Instruction error; error command: {com_input1_hex}')
# 开灯
if com_input.hex() == 'a487':
save_log.info(f'开灯指令处理完返回,command:{com_input.hex()}')
# 关灯
elif com_input.hex() == 'a488':
save_log.info(f'关灯指令处理完返回,command:{com_input.hex()}')
# 暖色灯
elif com_input.hex() == 'd366':
save_log.info(f'打开暖色灯指令处理完返回,command:{com_input.hex()}')
# 关暖色灯
elif com_input.hex() == 'd388':
save_log.info(f'关闭暖色灯指令处理完返回,command:{com_input.hex()}')
# 打开WIFI插座01
elif com_input.hex() == 'bba1':
save_log.info(f'打开WIFI插座指令处理完返回,command:{com_input.hex()}')
# 关闭WIFI插座01
elif com_input.hex() == 'bbb1':
save_log.info(f'关闭WIFI插座指令处理完返回,command:{com_input.hex()}')
# 打开热水器
elif com_input.hex() == 'ccaf':
save_log.info(f'打开热水器指令处理完返回,command:{com_input.hex()}')
# 关闭热水器
elif com_input.hex() == 'ddbf':
save_log.info(f'关闭热水器指令处理完返回,command:{com_input.hex()}')
elif com_input.hex() in ('', 'aa15', 'aa19', 'aa12', 'ffffffffff'):
pass
else:
save_log_error.error(f'Instruction error; error command: {com_input.hex()}')
return com_input1_hex
return com_input.hex()

View File

@ -1,7 +1,7 @@
#!/bin/bash
sleep 1
sleep 30
echo *********start python_scripts success*******