修复一段时间内语音控制出现挂起;新增新设备
This commit is contained in:
parent
f3cbb2082b
commit
43aa1ec665
10
README.md
10
README.md
@ -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.
BIN
__pycache__/main.cpython-38.pyc
Normal file
BIN
__pycache__/main.cpython-38.pyc
Normal file
Binary file not shown.
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
17
main.py
@ -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.
BIN
src/__pycache__/action_cmd.cpython-38.pyc
Normal file
BIN
src/__pycache__/action_cmd.cpython-38.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
src/__pycache__/local_status.cpython-38.pyc
Normal file
BIN
src/__pycache__/local_status.cpython-38.pyc
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -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)
|
||||
|
||||
@ -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()
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
sleep 1
|
||||
sleep 30
|
||||
|
||||
echo *********start python_scripts success*******
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user