diff --git a/sensor_to_server.py b/sensor_to_server.py index 3b26dc8..db947f9 100755 --- a/sensor_to_server.py +++ b/sensor_to_server.py @@ -1,4 +1,5 @@ import json +import subprocess import threading import time @@ -12,7 +13,6 @@ from config import broker, port, subscribe_topic, publish_topic, username, passw 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 ' # 气压查询指令 @@ -192,6 +192,10 @@ def get_data(): 'wind_direction': winddirection_data, '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) client.publish(publish_topic, payload=json.dumps(data, ensure_ascii=False), qos=0) add(t2) @@ -246,4 +250,4 @@ if __name__ == '__main__': client.on_connect = on_connect # Establish a connection client.connect(broker, port) - client.loop_forever() \ No newline at end of file + client.loop_forever() diff --git a/test_led.py b/test_led.py deleted file mode 100644 index 4eecac1..0000000 --- a/test_led.py +++ /dev/null @@ -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) diff --git a/tool.py b/tool.py index 7e64090..702a6ba 100755 --- a/tool.py +++ b/tool.py @@ -60,10 +60,11 @@ def exec_sh(msg, client): client.publish(info_topic, payload=publish_payload(code=200, msg='reloading'), qos=0) subprocess.Popen([cmd], shell=True) return - p = subprocess.Popen([cmd], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - out, err = p.communicate() - output = out.decode('utf-8').strip() - client.publish(info_topic, payload=publish_payload(code=200, msg=output), qos=0) + subprocess.Popen([cmd], shell=True) + # p = subprocess.Popen([cmd], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + # out, err = p.communicate() + # output = out.decode('utf-8').strip() + # client.publish(info_topic, payload=publish_payload(code=200, msg=output), qos=0) def get_status(client): @@ -116,5 +117,6 @@ def up(msg, client): except: pass + def get_record(msg, client): threading.Thread(target=up, args=(msg, client)).start()