This commit is contained in:
xyj 2023-12-09 15:23:18 +08:00
parent db380dc660
commit b03872d169
5 changed files with 15 additions and 8 deletions

View File

@ -3,6 +3,7 @@ import os
import time
import paho.mqtt.client as mqtt
from device import device_name
from tool import push_stream, close_stream, update, exec_sh, get_record, get_list_record, get_status
@ -19,7 +20,7 @@ def valid(msg, client):
if 'device_name' not in origin_data:
client.publish('error', payload='device_name must be supplied', qos=0)
return False
if os.getenv('device_name').strip() != origin_data['device_name']:
if device_name != origin_data['device_name']:
return False
return True
@ -71,7 +72,7 @@ def exec_shutdown():
if __name__ == '__main__':
while True:
try:
client = mqtt.Client(client_id=os.getenv('device_name').strip())
client = mqtt.Client(client_id=device_name)
client.username_pw_set("demo", "123456")
# Specify callback function
client.on_connect = on_connect

View File

@ -3,6 +3,8 @@ import subprocess
import time
import paho.mqtt.client as mqtt
from device import device_name
def on_connect(client, userdata, flags, rc):
global times
@ -21,7 +23,7 @@ times = 3
if __name__ == '__main__':
while True:
try:
client = mqtt.Client(client_id=os.getenv('device_name').strip())
client = mqtt.Client(client_id=device_name)
client.username_pw_set("demo", "123456")
# Specify callback function
client.on_connect = on_connect

View File

@ -1,5 +1,7 @@
import os
import subprocess
p = subprocess.Popen(['cat /home/pi/device_name'], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
device_name = out.decode('utf-8').strip()
# p = subprocess.Popen(['cat /home/pi/device_name'], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# out, err = p.communicate()
# device_name = out.decode('utf-8').strip()
device_name = os.getenv('device_name').strip()

View File

@ -5,6 +5,7 @@ import serial
from db.models.lot_data_model import LOT_DATA
from api import add
from device import device_name
def local():
@ -210,7 +211,7 @@ def test():
'wind_speed': 1,
'wind_direction': 1,
'create_time': int(time.time()),
'device_name': os.getenv('device_name')
'device_name': device_name
}
t2 = LOT_DATA(**data)
add(t2)

View File

@ -8,6 +8,7 @@ import paho.mqtt.client as mqtt
from api import add
from db.models.lot_data_model import LOT_DATA
from device import device_name
def t():
@ -226,7 +227,7 @@ def on_connect(client, userdata, flags, rc):
if __name__ == '__main__':
client = mqtt.Client(client_id=os.getenv('device_name').strip())
client = mqtt.Client(client_id=device_name)
client.username_pw_set("demo", "123456")
# Specify callback function
client.on_connect = on_connect