update
This commit is contained in:
parent
28cdd733bc
commit
24be9201aa
53
MQTT.py
53
MQTT.py
|
@ -13,31 +13,34 @@ def on_connect(client, userdata, flags, rc):
|
||||||
|
|
||||||
# Message receiving callback
|
# Message receiving callback
|
||||||
def on_message(client, userdata, msg):
|
def on_message(client, userdata, msg):
|
||||||
data = json.loads(msg.payload.decode('utf-8'))["msg"]
|
try:
|
||||||
if data == "push_stream":
|
data = json.loads(msg.payload.decode('utf-8'))["msg"]
|
||||||
# 启动推流视频
|
if data == "push_stream":
|
||||||
push_stream(client)
|
# 启动推流视频
|
||||||
elif data == "close_stream":
|
push_stream(client)
|
||||||
# 关闭推流视频
|
elif data == "close_stream":
|
||||||
close_stream(client)
|
# 关闭推流视频
|
||||||
elif data == "exec":
|
close_stream(client)
|
||||||
# 执行命令
|
elif data == "exec":
|
||||||
exec_sh(msg, client)
|
# 执行命令
|
||||||
elif data == "update":
|
exec_sh(msg, client)
|
||||||
# git更新项目和配置文件
|
elif data == "update":
|
||||||
update(client)
|
# git更新项目和配置文件
|
||||||
elif data == "record_list":
|
update(client)
|
||||||
# 查看录像列表
|
elif data == "record_list":
|
||||||
get_list_record()
|
# 查看录像列表
|
||||||
elif data == "record":
|
get_list_record()
|
||||||
# 获取录像
|
elif data == "record":
|
||||||
get_record(msg, client)
|
# 获取录像
|
||||||
elif data == "status":
|
get_record(msg, client)
|
||||||
# 查看运行状态
|
elif data == "status":
|
||||||
get_status(client)
|
# 查看运行状态
|
||||||
else:
|
get_status(client)
|
||||||
# 错误类型
|
else:
|
||||||
client.publish('success', payload='No Such Type', qos=0)
|
# 错误类型
|
||||||
|
client.publish('success', payload='No Such Type', qos=0)
|
||||||
|
except Exception as e:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
times = 120
|
times = 120
|
||||||
|
|
|
@ -35,158 +35,162 @@ def t():
|
||||||
windspeed_send = bytes.fromhex(windspeed_send)
|
windspeed_send = bytes.fromhex(windspeed_send)
|
||||||
winddirection_send = bytes.fromhex(winddirection_send)
|
winddirection_send = bytes.fromhex(winddirection_send)
|
||||||
while True:
|
while True:
|
||||||
# if ser.is_open:
|
try:
|
||||||
ser.write(temp_send)
|
# if ser.is_open:
|
||||||
time.sleep(1)
|
ser.write(temp_send)
|
||||||
# 获取返回的缓冲data,获取的是buffer_data的长度 9
|
time.sleep(1)
|
||||||
tempbuffer_data = ser.in_waiting
|
# 获取返回的缓冲data,获取的是buffer_data的长度 9
|
||||||
if tempbuffer_data:
|
tempbuffer_data = ser.in_waiting
|
||||||
# 返回的数据为2进制:b'\x01\x03\x04\x01\x08\x022\xfa\xb8'
|
if tempbuffer_data:
|
||||||
return_data = ser.read(tempbuffer_data)
|
# 返回的数据为2进制:b'\x01\x03\x04\x01\x08\x022\xfa\xb8'
|
||||||
# 二进制转换为16进制:010304010802307b79
|
return_data = ser.read(tempbuffer_data)
|
||||||
return_data_hex = str(return_data.hex())
|
# 二进制转换为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
|
airtemp_data = int(return_data_hex[6:10], 16) / 10
|
||||||
time.sleep(5)
|
airhumi_data = int(return_data_hex[10:14], 16) / 10
|
||||||
ser.write(co2_send)
|
time.sleep(5)
|
||||||
time.sleep(1)
|
ser.write(co2_send)
|
||||||
# 获取返回的缓冲data,获取的是buffer_data的长度 9
|
time.sleep(1)
|
||||||
co2buffer_data = ser.in_waiting
|
# 获取返回的缓冲data,获取的是buffer_data的长度 9
|
||||||
if co2buffer_data:
|
co2buffer_data = ser.in_waiting
|
||||||
return_data = ser.read(co2buffer_data)
|
if co2buffer_data:
|
||||||
# 二进制转换为16进制:010304010802307b79
|
return_data = ser.read(co2buffer_data)
|
||||||
return_data_hex = str(return_data.hex())
|
# 二进制转换为16进制:010304010802307b79
|
||||||
# 对返回的数据进行解析,获取温度和湿度数据
|
return_data_hex = str(return_data.hex())
|
||||||
co2_data = int(return_data_hex[6:10], 16)
|
# 对返回的数据进行解析,获取温度和湿度数据
|
||||||
time.sleep(5)
|
co2_data = int(return_data_hex[6:10], 16)
|
||||||
ser.write(pressure_send)
|
time.sleep(5)
|
||||||
time.sleep(1)
|
ser.write(pressure_send)
|
||||||
# 获取返回的缓冲data,获取的是buffer_data的长度 9
|
time.sleep(1)
|
||||||
pressurebuffer_data = ser.in_waiting
|
# 获取返回的缓冲data,获取的是buffer_data的长度 9
|
||||||
if pressurebuffer_data:
|
pressurebuffer_data = ser.in_waiting
|
||||||
# 返回的数据为2进制:b'\x01\x03\x04\x01\x08\x022\xfa\xb8'
|
if pressurebuffer_data:
|
||||||
return_data = ser.read(pressurebuffer_data)
|
# 返回的数据为2进制:b'\x01\x03\x04\x01\x08\x022\xfa\xb8'
|
||||||
# 二进制转换为16进制:010304010802307b79
|
return_data = ser.read(pressurebuffer_data)
|
||||||
return_data_hex = str(return_data.hex())
|
# 二进制转换为16进制:010304010802307b79
|
||||||
# 对返回的数据进行解析,获取温度和湿度数据
|
return_data_hex = str(return_data.hex())
|
||||||
pressure_data = int(return_data_hex[6:10], 16) / 10
|
# 对返回的数据进行解析,获取温度和湿度数据
|
||||||
time.sleep(5)
|
pressure_data = int(return_data_hex[6:10], 16) / 10
|
||||||
ser.write(sun_send)
|
time.sleep(5)
|
||||||
time.sleep(1)
|
ser.write(sun_send)
|
||||||
# 获取返回的缓冲data,获取的是buffer_data的长度 9
|
time.sleep(1)
|
||||||
sunbuffer_data = ser.in_waiting
|
# 获取返回的缓冲data,获取的是buffer_data的长度 9
|
||||||
if sunbuffer_data:
|
sunbuffer_data = ser.in_waiting
|
||||||
# 返回的数据为2进制:b'\x01\x03\x04\x01\x08\x022\xfa\xb8'
|
if sunbuffer_data:
|
||||||
return_data = ser.read(sunbuffer_data)
|
# 返回的数据为2进制:b'\x01\x03\x04\x01\x08\x022\xfa\xb8'
|
||||||
# 二进制转换为16进制:010304010802307b79
|
return_data = ser.read(sunbuffer_data)
|
||||||
return_data_hex = str(return_data.hex())
|
# 二进制转换为16进制:010304010802307b79
|
||||||
sun_data = int(return_data_hex[6:14], 16)
|
return_data_hex = str(return_data.hex())
|
||||||
time.sleep(5)
|
sun_data = int(return_data_hex[6:14], 16)
|
||||||
# print('send soil directives')
|
time.sleep(5)
|
||||||
ser.write(soil_send)
|
# print('send soil directives')
|
||||||
time.sleep(1)
|
ser.write(soil_send)
|
||||||
# 获取返回的缓冲data,获取的是buffer_data的长度 9
|
time.sleep(1)
|
||||||
soilbuffer_data = ser.in_waiting
|
# 获取返回的缓冲data,获取的是buffer_data的长度 9
|
||||||
# print(buffer_data, 'buffer_data')
|
soilbuffer_data = ser.in_waiting
|
||||||
if soilbuffer_data:
|
# print(buffer_data, 'buffer_data')
|
||||||
# 返回的数据为2进制:b'\x01\x03\x04\x01\x08\x022\xfa\xb8'
|
if soilbuffer_data:
|
||||||
return_data = ser.read(soilbuffer_data)
|
# 返回的数据为2进制:b'\x01\x03\x04\x01\x08\x022\xfa\xb8'
|
||||||
# 二进制转换为16进制:010304010802307b79
|
return_data = ser.read(soilbuffer_data)
|
||||||
return_data_hex = str(return_data.hex())
|
# 二进制转换为16进制:010304010802307b79
|
||||||
# 对返回的数据进行解析,获取温度和湿度数据
|
return_data_hex = str(return_data.hex())
|
||||||
humidity_data = int(return_data_hex[6:10], 16) / 10
|
# 对返回的数据进行解析,获取温度和湿度数据
|
||||||
temperature_data = int(return_data_hex[10:14], 16) / 10
|
humidity_data = int(return_data_hex[6:10], 16) / 10
|
||||||
electrical_data = int(return_data_hex[14:18], 16) / 10
|
temperature_data = int(return_data_hex[10:14], 16) / 10
|
||||||
PH_data = int(return_data_hex[18:22], 16) / 10
|
electrical_data = int(return_data_hex[14:18], 16) / 10
|
||||||
time.sleep(5)
|
PH_data = int(return_data_hex[18:22], 16) / 10
|
||||||
# print('send danlinjia directives')
|
time.sleep(5)
|
||||||
ser.write(danlinjia_send)
|
# print('send danlinjia directives')
|
||||||
time.sleep(1)
|
ser.write(danlinjia_send)
|
||||||
# 获取返回的缓冲data,获取的是buffer_data的长度 9
|
time.sleep(1)
|
||||||
danlinjiabuffer_data = ser.in_waiting
|
# 获取返回的缓冲data,获取的是buffer_data的长度 9
|
||||||
# print(buffer_data, 'buffer_data')
|
danlinjiabuffer_data = ser.in_waiting
|
||||||
if danlinjiabuffer_data:
|
# print(buffer_data, 'buffer_data')
|
||||||
# 返回的数据为2进制:b'\x01\x03\x04\x01\x08\x022\xfa\xb8'
|
if danlinjiabuffer_data:
|
||||||
return_data = ser.read(danlinjiabuffer_data)
|
# 返回的数据为2进制:b'\x01\x03\x04\x01\x08\x022\xfa\xb8'
|
||||||
# print('返回的数据2进制:', return_data)
|
return_data = ser.read(danlinjiabuffer_data)
|
||||||
# 二进制转换为16进制:010304010802307b79
|
# print('返回的数据2进制:', return_data)
|
||||||
return_data_hex = str(return_data.hex())
|
# 二进制转换为16进制:010304010802307b79
|
||||||
# # 对返回的数据进行解析,获取温度和湿度数据
|
return_data_hex = str(return_data.hex())
|
||||||
dan_data = int(return_data_hex[6:10], 16) / 10
|
# # 对返回的数据进行解析,获取温度和湿度数据
|
||||||
lin_data = int(return_data_hex[10:14], 16) / 10
|
dan_data = int(return_data_hex[6:10], 16) / 10
|
||||||
jia_data = int(return_data_hex[14:18], 16) / 10
|
lin_data = int(return_data_hex[10:14], 16) / 10
|
||||||
time.sleep(5)
|
jia_data = int(return_data_hex[14:18], 16) / 10
|
||||||
# print('send rainfall directives')
|
time.sleep(5)
|
||||||
ser.write(rainfall_send)
|
# print('send rainfall directives')
|
||||||
time.sleep(1)
|
ser.write(rainfall_send)
|
||||||
# 获取返回的缓冲data,获取的是buffer_data的长度 9
|
time.sleep(1)
|
||||||
rainfallbuffer_data = ser.in_waiting
|
# 获取返回的缓冲data,获取的是buffer_data的长度 9
|
||||||
# print(buffer_data, 'buffer_data')
|
rainfallbuffer_data = ser.in_waiting
|
||||||
if rainfallbuffer_data:
|
# print(buffer_data, 'buffer_data')
|
||||||
# 返回的数据为2进制:b'\x01\x03\x04\x01\x08\x022\xfa\xb8'
|
if rainfallbuffer_data:
|
||||||
return_data = ser.read(rainfallbuffer_data)
|
# 返回的数据为2进制:b'\x01\x03\x04\x01\x08\x022\xfa\xb8'
|
||||||
# print('返回的数据2进制:', return_data)
|
return_data = ser.read(rainfallbuffer_data)
|
||||||
# 二进制转换为16进制:010304010802307b79
|
# print('返回的数据2进制:', return_data)
|
||||||
return_data_hex = str(return_data.hex())
|
# 二进制转换为16进制:010304010802307b79
|
||||||
# print('返回的数据转换为16进制:', return_data_hex)
|
return_data_hex = str(return_data.hex())
|
||||||
# # 对返回的数据进行解析,获取温度和湿度数据
|
# print('返回的数据转换为16进制:', return_data_hex)
|
||||||
# print("当前雨量值为:", int(return_data_hex[6:10], 16)/10)#单位mm
|
# # 对返回的数据进行解析,获取温度和湿度数据
|
||||||
rainfall_data = int(return_data_hex[6:10], 16) / 10
|
# print("当前雨量值为:", int(return_data_hex[6:10], 16)/10)#单位mm
|
||||||
time.sleep(5)
|
rainfall_data = int(return_data_hex[6:10], 16) / 10
|
||||||
ser.write(windspeed_send)
|
time.sleep(5)
|
||||||
time.sleep(1)
|
ser.write(windspeed_send)
|
||||||
# 获取返回的缓冲data,获取的是buffer_data的长度 9
|
time.sleep(1)
|
||||||
windspeedbuffer_data = ser.in_waiting
|
# 获取返回的缓冲data,获取的是buffer_data的长度 9
|
||||||
# print(buffer_data, 'buffer_data')
|
windspeedbuffer_data = ser.in_waiting
|
||||||
if windspeedbuffer_data:
|
# print(buffer_data, 'buffer_data')
|
||||||
# 返回的数据为2进制:b'\x01\x03\x04\x01\x08\x022\xfa\xb8'
|
if windspeedbuffer_data:
|
||||||
return_data = ser.read(windspeedbuffer_data)
|
# 返回的数据为2进制:b'\x01\x03\x04\x01\x08\x022\xfa\xb8'
|
||||||
# print('返回的数据2进制:', return_data)
|
return_data = ser.read(windspeedbuffer_data)
|
||||||
# 二进制转换为16进制:010304010802307b79
|
# print('返回的数据2进制:', return_data)
|
||||||
return_data_hex = str(return_data.hex())
|
# 二进制转换为16进制:010304010802307b79
|
||||||
# print('返回的数据转换为16进制:', return_data_hex)
|
return_data_hex = str(return_data.hex())
|
||||||
# print("当前风速为:", int(return_data_hex[6:10], 16)/10)#单位mm
|
# print('返回的数据转换为16进制:', return_data_hex)
|
||||||
speedwind_data = int(return_data_hex[6:10], 16) / 10
|
# print("当前风速为:", int(return_data_hex[6:10], 16)/10)#单位mm
|
||||||
time.sleep(5)
|
speedwind_data = int(return_data_hex[6:10], 16) / 10
|
||||||
# print('send winddirection directives')
|
time.sleep(5)
|
||||||
ser.write(winddirection_send)
|
# print('send winddirection directives')
|
||||||
time.sleep(1)
|
ser.write(winddirection_send)
|
||||||
# 获取返回的缓冲data,获取的是buffer_data的长度 9
|
time.sleep(1)
|
||||||
winddirectionbuffer_data = ser.in_waiting
|
# 获取返回的缓冲data,获取的是buffer_data的长度 9
|
||||||
# print(buffer_data, 'buffer_data')
|
winddirectionbuffer_data = ser.in_waiting
|
||||||
if winddirectionbuffer_data:
|
# print(buffer_data, 'buffer_data')
|
||||||
# 返回的数据为2进制:b'\x01\x03\x04\x01\x08\x022\xfa\xb8'
|
if winddirectionbuffer_data:
|
||||||
return_data = ser.read(winddirectionbuffer_data)
|
# 返回的数据为2进制:b'\x01\x03\x04\x01\x08\x022\xfa\xb8'
|
||||||
# print('返回的数据2进制:', return_data)
|
return_data = ser.read(winddirectionbuffer_data)
|
||||||
# 二进制转换为16进制:010304010802307b79
|
# print('返回的数据2进制:', return_data)
|
||||||
return_data_hex = str(return_data.hex())
|
# 二进制转换为16进制:010304010802307b79
|
||||||
# print('返回的数据转换为16进制:', return_data_hex)
|
return_data_hex = str(return_data.hex())
|
||||||
# print("当前风向为:", int(return_data_hex[10:14], 16))#单位mm
|
# print('返回的数据转换为16进制:', return_data_hex)
|
||||||
winddirection_data = int(return_data_hex[10:14], 16)
|
# print("当前风向为:", int(return_data_hex[10:14], 16))#单位mm
|
||||||
time.sleep(5)
|
winddirection_data = int(return_data_hex[10:14], 16)
|
||||||
# print('{"name":"%d","name1":"%d"}', 123,456)
|
time.sleep(5)
|
||||||
# data = [{'ngvhgv': airtemp_data}, {'nvjgvjvj':airhumi_data}]
|
# print('{"name":"%d","name1":"%d"}', 123,456)
|
||||||
data = {'ambient_temperature': airtemp_data,
|
# data = [{'ngvhgv': airtemp_data}, {'nvjgvjvj':airhumi_data}]
|
||||||
'ambient_humidity': airhumi_data,
|
data = {'ambient_temperature': airtemp_data,
|
||||||
'carbon_dioxide': co2_data,
|
'ambient_humidity': airhumi_data,
|
||||||
'ambient_air_pressure': pressure_data,
|
'carbon_dioxide': co2_data,
|
||||||
'ambient_lighting': sun_data,
|
'ambient_air_pressure': pressure_data,
|
||||||
'soil_moisture': humidity_data,
|
'ambient_lighting': sun_data,
|
||||||
'soil_temperature': temperature_data,
|
'soil_moisture': humidity_data,
|
||||||
'soil_conductivity': electrical_data,
|
'soil_temperature': temperature_data,
|
||||||
'soil_PH': PH_data,
|
'soil_conductivity': electrical_data,
|
||||||
'soil_potassium_phosphate_nitrogen': dan_data,
|
'soil_PH': PH_data,
|
||||||
'soil_potassium_phosphate_phosphorus': lin_data,
|
'soil_potassium_phosphate_nitrogen': dan_data,
|
||||||
'soil_potassium_phosphate_potassium': jia_data,
|
'soil_potassium_phosphate_phosphorus': lin_data,
|
||||||
'rainfall': rainfall_data,
|
'soil_potassium_phosphate_potassium': jia_data,
|
||||||
'wind_speed': speedwind_data,
|
'rainfall': rainfall_data,
|
||||||
'wind_direction': winddirection_data,
|
'wind_speed': speedwind_data,
|
||||||
'create_time': int(time.time())
|
'wind_direction': winddirection_data,
|
||||||
}
|
'create_time': int(time.time())
|
||||||
t2 = LOT_DATA(**data)
|
}
|
||||||
client.publish('demo', payload=json.dumps(data, ensure_ascii=False), qos=0)
|
t2 = LOT_DATA(**data)
|
||||||
add(t2)
|
client.publish('demo', payload=json.dumps(data, ensure_ascii=False), qos=0)
|
||||||
|
add(t2)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def on_connect(client, userdata, flags, rc):
|
def on_connect(client, userdata, flags, rc):
|
||||||
|
|
Loading…
Reference in New Issue