From 82ff01391913ffc22ebf335463f6dd1defe9edf4 Mon Sep 17 00:00:00 2001 From: xyj <10908227994@qq.com> Date: Thu, 14 Dec 2023 09:26:35 +0800 Subject: [PATCH] update --- bash/start_data_upload.sh | 2 ++ bash/stop_data_upload.sh | 2 ++ conf/zhanguan/topic.conf | 2 ++ config.py | 5 +++++ sensor_to_local.py | 11 ++++++++--- sensor_to_server.py | 5 +++-- 6 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 conf/zhanguan/topic.conf diff --git a/bash/start_data_upload.sh b/bash/start_data_upload.sh index 4e67da3..cf6fd57 100644 --- a/bash/start_data_upload.sh +++ b/bash/start_data_upload.sh @@ -1,4 +1,6 @@ #!/bin/bash # 这里千万不要使用set -e +sleep 5 supervisorctl stop sensor_to_local +sleep 5 supervisorctl start sensor_to_server diff --git a/bash/stop_data_upload.sh b/bash/stop_data_upload.sh index 8f8b2ea..b9334a7 100644 --- a/bash/stop_data_upload.sh +++ b/bash/stop_data_upload.sh @@ -1,3 +1,5 @@ #!/bin/bash +sleep 5 supervisorctl stop sensor_to_server +sleep 5 supervisorctl start sensor_to_local diff --git a/conf/zhanguan/topic.conf b/conf/zhanguan/topic.conf new file mode 100644 index 0000000..6a97eeb --- /dev/null +++ b/conf/zhanguan/topic.conf @@ -0,0 +1,2 @@ +[device] +name=lihai_lot_walnutpi_dev_6 \ No newline at end of file diff --git a/config.py b/config.py index c364faa..e9b4e85 100644 --- a/config.py +++ b/config.py @@ -26,3 +26,8 @@ publish_topic = config.get(device_name, "publish_topic") username = config.get(device_name, "username") # 密码 password = config.get(device_name, "password") + + +# 特殊配置 +config.read('conf/zhanguan/topic.conf') +zhanguan_device_name = config.get("device", "name") diff --git a/sensor_to_local.py b/sensor_to_local.py index 835748f..b1905d6 100755 --- a/sensor_to_local.py +++ b/sensor_to_local.py @@ -3,6 +3,7 @@ import time import serial +from config import subscribe_topic, zhanguan_device_name from db.models.lot_data_model import LOT_DATA from api import add @@ -45,8 +46,8 @@ def local(): # 二进制转换为16进制:010304010802307b79 return_data_hex = str(return_data.hex()) # 对返回的数据进行解析,获取温度和湿度数据 - airtemp_data = int(return_data_hex[6:10], 16) / 10 - airhumi_data = int(return_data_hex[10:14], 16) / 10 + airhumi_data = int(return_data_hex[6:10], 16) / 10 + airtemp_data= int(return_data_hex[10:14], 16) / 10 time.sleep(5) ser.write(co2_send) time.sleep(1) @@ -162,7 +163,11 @@ def local(): return_data_hex = str(return_data.hex()) # print('返回的数据转换为16进制:', return_data_hex) # print("当前风向为:", int(return_data_hex[10:14], 16))#单位mm - winddirection_data = int(return_data_hex[10:14], 16) + # 6号设备是8方位 + if subscribe_topic == zhanguan_device_name: + winddirection_data = int(return_data_hex[10:14], 16) + else: + winddirection_data = int(return_data_hex[6:10], 16) / 10 time.sleep(5) # print('{"name":"%d","name1":"%d"}', 123,456) # data = [{'ngvhgv': airtemp_data}, {'nvjgvjvj':airhumi_data}] diff --git a/sensor_to_server.py b/sensor_to_server.py index 3dee444..d2cb242 100755 --- a/sensor_to_server.py +++ b/sensor_to_server.py @@ -8,10 +8,11 @@ import paho.mqtt.client as mqtt from api import add from db.models.lot_data_model import LOT_DATA -from config import broker, port, subscribe_topic, publish_topic, username, password +from config import broker, port, subscribe_topic, publish_topic, username, password, zhanguan_device_name def get_data(): + temp_send = '06 03 01 F4 00 02 85 B2 ' # 温湿度查询指令 co2_send = '06 03 01 F7 00 02 75 B2 ' # 二氧化碳查询指令 pressure_send = '06 03 01 F9 00 02 14 71 ' # 气压查询指令 @@ -167,7 +168,7 @@ def get_data(): # print('返回的数据转换为16进制:', return_data_hex) # print("当前风向为:", int(return_data_hex[10:14], 16) ) #单位mm # 6号设备是8方位 - if subscribe_topic == 'lihai_lot_walnutpi_dev_6': + if subscribe_topic == zhanguan_device_name: winddirection_data = int(return_data_hex[10:14], 16) else: winddirection_data = int(return_data_hex[6:10], 16) / 10