This commit is contained in:
xyj 2023-12-07 16:35:05 +08:00
parent 23affef16d
commit 76fd93c002
7 changed files with 20 additions and 12 deletions

View File

@ -74,7 +74,7 @@ def exec_shutdown():
if __name__ == '__main__': if __name__ == '__main__':
while True: while True:
try: try:
client = mqtt.Client(client_id='device1') client = mqtt.Client(client_id=os.getenv('device_name'))
client.username_pw_set("demo", "123456") client.username_pw_set("demo", "123456")
# Specify callback function # Specify callback function
client.on_connect = on_connect client.on_connect = on_connect

View File

@ -1,3 +1,2 @@
0 0 * * * /usr/bin/bash /home/pi/lot_manager/delete_than.sh 0 0 * * * /usr/bin/bash /home/pi/lot_manager/bash/delete_than.sh
*/15 * * * * /usr/bin/bash /home/pi/lot_manager/cron_delete_mp4.sh */15 * * * * /usr/bin/bash /home/pi/lot_manager/bash/cron_delete_mp4.sh

View File

@ -4,6 +4,7 @@ from db.base import Base
class LOT_DATA(BaseModel): class LOT_DATA(BaseModel):
device_name: str = Field(None, description='设备编号')
create_time: int = Field(None, description='创建时间(时间戳) ') create_time: int = Field(None, description='创建时间(时间戳) ')
wind_speed: float = Field(None, description='风速:(0到30)m/s ') wind_speed: float = Field(None, description='风速:(0到30)m/s ')
wind_direction: float = Field(None, description='风向:0360°') wind_direction: float = Field(None, description='风向:0360°')
@ -28,6 +29,7 @@ class LOT_DATA_MODEL(Base):
""" """
__tablename__ = 'LOT_DATA_MODEL' __tablename__ = 'LOT_DATA_MODEL'
id = Column(Integer, primary_key=True, autoincrement=True, comment='ID') id = Column(Integer, primary_key=True, autoincrement=True, comment='ID')
device_name = Column(String(50), comment="设备编号")
create_time = Column(Integer, comment="创建时间") create_time = Column(Integer, comment="创建时间")
wind_speed = Column(Float, comment='风速:(0到30)m/s ') wind_speed = Column(Float, comment='风速:(0到30)m/s ')
wind_direction = Column(Float, comment='风向:0360°') wind_direction = Column(Float, comment='风向:0360°')

View File

@ -1,3 +1,4 @@
import os
import subprocess import subprocess
import time import time
import paho.mqtt.client as mqtt import paho.mqtt.client as mqtt
@ -20,7 +21,7 @@ times = 3
if __name__ == '__main__': if __name__ == '__main__':
while True: while True:
try: try:
client = mqtt.Client() client = mqtt.Client(client_id=os.getenv('device_name'))
client.username_pw_set("demo", "123456") client.username_pw_set("demo", "123456")
# Specify callback function # Specify callback function
client.on_connect = on_connect client.on_connect = on_connect

View File

@ -1,3 +1,4 @@
import os
import time import time
import serial import serial
@ -179,7 +180,8 @@ if __name__ == '__main__':
'rainfall': rainfall_data, 'rainfall': rainfall_data,
'wind_speed': speedwind_data, 'wind_speed': speedwind_data,
'wind_direction': winddirection_data, 'wind_direction': winddirection_data,
'create_time': int(time.time()) 'create_time': int(time.time()),
'device_name': os.getenv('device_name')
} }
t = LOT_DATA(**data) t = LOT_DATA(**data)
add(t) add(t)

View File

@ -1,4 +1,5 @@
import json import json
import os
import threading import threading
import time import time
@ -183,7 +184,8 @@ def t():
'rainfall': rainfall_data, 'rainfall': rainfall_data,
'wind_speed': speedwind_data, 'wind_speed': speedwind_data,
'wind_direction': winddirection_data, 'wind_direction': winddirection_data,
'create_time': int(time.time()) 'create_time': int(time.time()),
'device_name': os.getenv('device_name')
} }
t2 = LOT_DATA(**data) t2 = LOT_DATA(**data)
client.publish('demo', payload=json.dumps(data, ensure_ascii=False), qos=0) client.publish('demo', payload=json.dumps(data, ensure_ascii=False), qos=0)
@ -198,7 +200,7 @@ def on_connect(client, userdata, flags, rc):
if __name__ == '__main__': if __name__ == '__main__':
client = mqtt.Client() client = mqtt.Client(client_id=os.getenv('device_name'))
client.username_pw_set("demo", "123456") client.username_pw_set("demo", "123456")
# Specify callback function # Specify callback function
client.on_connect = on_connect client.on_connect = on_connect

View File

@ -8,7 +8,8 @@ mp4_path = '/home/pi/mp4'
def push_stream(client): def push_stream(client):
p = subprocess.Popen(['/bin/bash /home/pi/lot_manager/bash/start_push_stream.sh'], shell=True, stdout=subprocess.PIPE, p = subprocess.Popen(['/bin/bash /home/pi/lot_manager/bash/start_push_stream.sh'], shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE) stderr=subprocess.PIPE)
out, err = p.communicate() out, err = p.communicate()
output = out.decode('utf-8') output = out.decode('utf-8')
@ -16,7 +17,8 @@ def push_stream(client):
def close_stream(client): def close_stream(client):
p = subprocess.Popen(['/bin/bash /home/pi/lot_manager/bash/stop_push_stream.sh'], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) p = subprocess.Popen(['/bin/bash /home/pi/lot_manager/bash/stop_push_stream.sh'], shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate() out, err = p.communicate()
output = out.decode('utf-8') output = out.decode('utf-8')
client.publish('success', payload=json.dumps(output, ensure_ascii=False), qos=0) client.publish('success', payload=json.dumps(output, ensure_ascii=False), qos=0)
@ -55,8 +57,8 @@ def update(client):
def get_list_record(): def get_list_record():
data = { data = {
"data": os.listdir(mp4_path) "data": os.listdir(mp4_path),
"device_name": os.getenv("device_name")
} }
requests.post("http://shop.lihaink.cn/api/index/file_list", json=data) requests.post("http://shop.lihaink.cn/api/index/file_list", json=data)