This commit is contained in:
xyj 2023-12-14 09:26:35 +08:00
parent 1c441b0d0a
commit 82ff013919
6 changed files with 22 additions and 5 deletions

View File

@ -1,4 +1,6 @@
#!/bin/bash
# 这里千万不要使用set -e
sleep 5
supervisorctl stop sensor_to_local
sleep 5
supervisorctl start sensor_to_server

View File

@ -1,3 +1,5 @@
#!/bin/bash
sleep 5
supervisorctl stop sensor_to_server
sleep 5
supervisorctl start sensor_to_local

2
conf/zhanguan/topic.conf Normal file
View File

@ -0,0 +1,2 @@
[device]
name=lihai_lot_walnutpi_dev_6

View File

@ -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")

View File

@ -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}]

View File

@ -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