test
This commit is contained in:
parent
83e70e8508
commit
f80f71e3a2
6
MQTT.py
6
MQTT.py
|
@ -9,21 +9,26 @@ class MQTT:
|
|||
def on_connect(self, client, userdata, flags, rc):
|
||||
if rc == 0:
|
||||
client.subscribe('lot_stream')
|
||||
|
||||
# Message receiving callback
|
||||
def on_message(self, client, userdata, msg):
|
||||
data = json.loads(msg.payload.decode('utf-8'))["msg"]
|
||||
if data == "push_stream":
|
||||
# 启动推流视频
|
||||
push_stream()
|
||||
client.publish('success', payload='push_stream success', qos=0)
|
||||
elif data == "close_stream":
|
||||
# 关闭推流视频
|
||||
close_stream()
|
||||
client.publish('success', payload='close_stream success', qos=0)
|
||||
elif data == "exec":
|
||||
# 执行命令
|
||||
exec_sh(msg)
|
||||
client.publish('success', payload='exec_sh success', qos=0)
|
||||
elif data == "update":
|
||||
# git更新项目和配置文件
|
||||
update()
|
||||
client.publish('success', payload='update success', qos=0)
|
||||
else:
|
||||
client.publish('error', payload='No Such Type', qos=0)
|
||||
|
||||
|
@ -38,5 +43,6 @@ class MQTT:
|
|||
# Publish a message
|
||||
self.client.loop_forever(retry_first_connection=True)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
mq = MQTT()
|
||||
|
|
10
api.py
10
api.py
|
@ -3,7 +3,7 @@ import subprocess
|
|||
|
||||
import uvicorn
|
||||
from db.models.base import BaseResponse
|
||||
from db.models.log_data_model import LOT_DATA
|
||||
from db.models.log_data_model import LOT_DATA, LOT_DATA_MODEL
|
||||
from db.repository import add_kb_to_db, get_kb_detail, get_kb_detail_by_time, delete_kb_detail_by_time
|
||||
|
||||
from fastapi import FastAPI
|
||||
|
@ -17,6 +17,14 @@ def add(data: LOT_DATA):
|
|||
return BaseResponse(code=500, msg=e)
|
||||
|
||||
|
||||
def delete(start_time, end_time):
|
||||
try:
|
||||
delete_kb_detail_by_time(start_time, end_time)
|
||||
return BaseResponse()
|
||||
except Exception as e:
|
||||
return BaseResponse(code=500, msg=e)
|
||||
|
||||
|
||||
def get_data():
|
||||
try:
|
||||
data = get_kb_detail()
|
||||
|
|
18
ceshi.py
18
ceshi.py
|
@ -202,13 +202,14 @@ def run_with_client(client):
|
|||
'soil_potassium_phosphate_potassium': jia_data,
|
||||
'rainfall': rainfall_data,
|
||||
'wind_speed': speedwind_data,
|
||||
'wind_direction': winddirection_data}
|
||||
|
||||
t = LOT_DATA(**data, create_time=int(time.time()))
|
||||
'wind_direction': winddirection_data,
|
||||
'create_time': int(time.time())
|
||||
}
|
||||
t = LOT_DATA(**data)
|
||||
# TODO 判断数据是否正常
|
||||
add(t)
|
||||
# 发送给服务器
|
||||
client.publish('lot_data', payload=data, qos=0)
|
||||
client.publish('lot_data', payload=json.dumps(data, ensure_ascii=False), qos=0)
|
||||
r = add(t)
|
||||
|
||||
|
||||
def run_no_client():
|
||||
|
@ -375,13 +376,12 @@ def run_no_client():
|
|||
'wind_direction': winddirection_data}
|
||||
data = LOT_DATA(**data, create_time=int(time.time()))
|
||||
# TODO 判断数据是否正常
|
||||
add(data)
|
||||
|
||||
r = add(data)
|
||||
|
||||
|
||||
def t1():
|
||||
import time
|
||||
for i in range(100):
|
||||
while (1):
|
||||
time.sleep(2)
|
||||
data = {
|
||||
"wind_speed": 1,
|
||||
|
@ -411,6 +411,8 @@ def t2():
|
|||
time = 3
|
||||
|
||||
from threading import Thread
|
||||
|
||||
|
||||
def on_connect(client, userdata, flags, rc):
|
||||
global time
|
||||
if rc == 0:
|
||||
|
|
Loading…
Reference in New Issue