diff --git a/README.md b/README.md index 07b7c85..a0e0f8a 100644 --- a/README.md +++ b/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设备即可刷新 + ### 目结构: diff --git a/__pycache__/config.cpython-38.pyc b/__pycache__/config.cpython-38.pyc index 14117c1..c357e54 100644 Binary files a/__pycache__/config.cpython-38.pyc and b/__pycache__/config.cpython-38.pyc differ diff --git a/__pycache__/main.cpython-38.pyc b/__pycache__/main.cpython-38.pyc new file mode 100644 index 0000000..0bec78d Binary files /dev/null and b/__pycache__/main.cpython-38.pyc differ diff --git a/config.py b/config.py index fd6ee42..afc998b 100644 --- a/config.py +++ b/config.py @@ -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 diff --git a/docs/控制指令表.txt b/docs/控制指令表.txt index 0615f04..51ab603 100644 --- a/docs/控制指令表.txt +++ b/docs/控制指令表.txt @@ -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 diff --git a/logs/Error.log b/logs/Error.log index c6e9f6a..61338fe 100644 --- a/logs/Error.log +++ b/logs/Error.log @@ -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串口是否被占用;或者串口出现异常! diff --git a/main.py b/main.py index 0914615..e80b5d6 100755 --- a/main.py +++ b/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) diff --git a/src/__pycache__/__init__.cpython-38.pyc b/src/__pycache__/__init__.cpython-38.pyc index 955a739..1bc1e83 100644 Binary files a/src/__pycache__/__init__.cpython-38.pyc and b/src/__pycache__/__init__.cpython-38.pyc differ diff --git a/src/__pycache__/action_cmd.cpython-38.pyc b/src/__pycache__/action_cmd.cpython-38.pyc new file mode 100644 index 0000000..f6ba500 Binary files /dev/null and b/src/__pycache__/action_cmd.cpython-38.pyc differ diff --git a/src/__pycache__/data_up.cpython-38.pyc b/src/__pycache__/data_up.cpython-38.pyc index 90ffb30..5bec899 100644 Binary files a/src/__pycache__/data_up.cpython-38.pyc and b/src/__pycache__/data_up.cpython-38.pyc differ diff --git a/src/__pycache__/local_status.cpython-38.pyc b/src/__pycache__/local_status.cpython-38.pyc new file mode 100644 index 0000000..4661e65 Binary files /dev/null and b/src/__pycache__/local_status.cpython-38.pyc differ diff --git a/src/__pycache__/master_control.cpython-38.pyc b/src/__pycache__/master_control.cpython-38.pyc index 8c3a39e..151ea78 100644 Binary files a/src/__pycache__/master_control.cpython-38.pyc and b/src/__pycache__/master_control.cpython-38.pyc differ diff --git a/src/__pycache__/python_mqtt.cpython-38.pyc b/src/__pycache__/python_mqtt.cpython-38.pyc index 0f314fd..209f0f4 100644 Binary files a/src/__pycache__/python_mqtt.cpython-38.pyc and b/src/__pycache__/python_mqtt.cpython-38.pyc differ diff --git a/src/__pycache__/voice_processing.cpython-38.pyc b/src/__pycache__/voice_processing.cpython-38.pyc index 627b005..2768ae4 100644 Binary files a/src/__pycache__/voice_processing.cpython-38.pyc and b/src/__pycache__/voice_processing.cpython-38.pyc differ diff --git a/src/action_cmd.py b/src/action_cmd.py index 6fc26df..8e00885 100644 --- a/src/action_cmd.py +++ b/src/action_cmd.py @@ -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) \ No newline at end of file + save_log.info(topic + " => " + "发布的信息:" + data_msg) diff --git a/src/voice_processing.py b/src/voice_processing.py index bf1edb0..47b0a23 100644 --- a/src/voice_processing.py +++ b/src/voice_processing.py @@ -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() diff --git a/start_all.sh b/start_all.sh index a89cf02..fbcebca 100755 --- a/start_all.sh +++ b/start_all.sh @@ -1,7 +1,7 @@ #!/bin/bash -sleep 1 +sleep 30 echo *********start python_scripts success*******