This commit is contained in:
xyj 2023-12-26 17:48:05 +08:00
parent 8fc94c9814
commit cc970c891c
3 changed files with 12 additions and 25 deletions

View File

@ -1,4 +1,5 @@
import json import json
import subprocess
import threading import threading
import time import time
@ -12,7 +13,6 @@ from config import broker, port, subscribe_topic, publish_topic, username, passw
def get_data(): def get_data():
temp_send = '06 03 01 F4 00 02 85 B2 ' # 温湿度查询指令 temp_send = '06 03 01 F4 00 02 85 B2 ' # 温湿度查询指令
co2_send = '06 03 01 F7 00 02 75 B2 ' # 二氧化碳查询指令 co2_send = '06 03 01 F7 00 02 75 B2 ' # 二氧化碳查询指令
pressure_send = '06 03 01 F9 00 02 14 71 ' # 气压查询指令 pressure_send = '06 03 01 F9 00 02 14 71 ' # 气压查询指令
@ -192,6 +192,10 @@ def get_data():
'wind_direction': winddirection_data, 'wind_direction': winddirection_data,
'create_time': int(time.time()) 'create_time': int(time.time())
} }
if sun_data < 6:
subprocess.Popen(['sudo python /home/pi/lot_manager/close_led.py'], shell=True)
else:
subprocess.Popen(['sudo python /home/pi/lot_manager/open_led.py'], shell=True)
t2 = LOT_DATA(**data) t2 = LOT_DATA(**data)
client.publish(publish_topic, payload=json.dumps(data, ensure_ascii=False), qos=0) client.publish(publish_topic, payload=json.dumps(data, ensure_ascii=False), qos=0)
add(t2) add(t2)

View File

@ -1,19 +0,0 @@
'''
实验名称点亮第1个LED
实验平台核桃派
'''
import time
# 导入相关模块
import board
from digitalio import DigitalInOut, Direction
# 构建LED对象和初始化
while True:
led = DigitalInOut(board.LED) # 定义引脚编号
led.direction = Direction.OUTPUT # IO为输出
led.value = 0 # 输出低电平熄灭板载LED蓝灯
print("熄灭")
time.sleep(20)
led.value = 1 # 输出高电平点亮板载LED蓝灯
print("点亮")
time.sleep(20)

10
tool.py
View File

@ -60,10 +60,11 @@ def exec_sh(msg, client):
client.publish(info_topic, payload=publish_payload(code=200, msg='reloading'), qos=0) client.publish(info_topic, payload=publish_payload(code=200, msg='reloading'), qos=0)
subprocess.Popen([cmd], shell=True) subprocess.Popen([cmd], shell=True)
return return
p = subprocess.Popen([cmd], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) subprocess.Popen([cmd], shell=True)
out, err = p.communicate() # p = subprocess.Popen([cmd], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output = out.decode('utf-8').strip() # out, err = p.communicate()
client.publish(info_topic, payload=publish_payload(code=200, msg=output), qos=0) # output = out.decode('utf-8').strip()
# client.publish(info_topic, payload=publish_payload(code=200, msg=output), qos=0)
def get_status(client): def get_status(client):
@ -116,5 +117,6 @@ def up(msg, client):
except: except:
pass pass
def get_record(msg, client): def get_record(msg, client):
threading.Thread(target=up, args=(msg, client)).start() threading.Thread(target=up, args=(msg, client)).start()