update
This commit is contained in:
parent
db380dc660
commit
b03872d169
5
MQTT.py
5
MQTT.py
|
@ -3,6 +3,7 @@ import os
|
||||||
import time
|
import time
|
||||||
import paho.mqtt.client as mqtt
|
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
|
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:
|
if 'device_name' not in origin_data:
|
||||||
client.publish('error', payload='device_name must be supplied', qos=0)
|
client.publish('error', payload='device_name must be supplied', qos=0)
|
||||||
return False
|
return False
|
||||||
if os.getenv('device_name').strip() != origin_data['device_name']:
|
if device_name != origin_data['device_name']:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -71,7 +72,7 @@ def exec_shutdown():
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
client = mqtt.Client(client_id=os.getenv('device_name').strip())
|
client = mqtt.Client(client_id=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
|
||||||
|
|
|
@ -3,6 +3,8 @@ import subprocess
|
||||||
import time
|
import time
|
||||||
import paho.mqtt.client as mqtt
|
import paho.mqtt.client as mqtt
|
||||||
|
|
||||||
|
from device import device_name
|
||||||
|
|
||||||
|
|
||||||
def on_connect(client, userdata, flags, rc):
|
def on_connect(client, userdata, flags, rc):
|
||||||
global times
|
global times
|
||||||
|
@ -21,7 +23,7 @@ times = 3
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
client = mqtt.Client(client_id=os.getenv('device_name').strip())
|
client = mqtt.Client(client_id=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
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
p = subprocess.Popen(['cat /home/pi/device_name'], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
# p = subprocess.Popen(['cat /home/pi/device_name'], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
out, err = p.communicate()
|
# out, err = p.communicate()
|
||||||
device_name = out.decode('utf-8').strip()
|
# device_name = out.decode('utf-8').strip()
|
||||||
|
device_name = os.getenv('device_name').strip()
|
||||||
|
|
|
@ -5,6 +5,7 @@ import serial
|
||||||
|
|
||||||
from db.models.lot_data_model import LOT_DATA
|
from db.models.lot_data_model import LOT_DATA
|
||||||
from api import add
|
from api import add
|
||||||
|
from device import device_name
|
||||||
|
|
||||||
|
|
||||||
def local():
|
def local():
|
||||||
|
@ -210,7 +211,7 @@ def test():
|
||||||
'wind_speed': 1,
|
'wind_speed': 1,
|
||||||
'wind_direction': 1,
|
'wind_direction': 1,
|
||||||
'create_time': int(time.time()),
|
'create_time': int(time.time()),
|
||||||
'device_name': os.getenv('device_name')
|
'device_name': device_name
|
||||||
}
|
}
|
||||||
t2 = LOT_DATA(**data)
|
t2 = LOT_DATA(**data)
|
||||||
add(t2)
|
add(t2)
|
||||||
|
|
|
@ -8,6 +8,7 @@ import paho.mqtt.client as mqtt
|
||||||
|
|
||||||
from api import add
|
from api import add
|
||||||
from db.models.lot_data_model import LOT_DATA
|
from db.models.lot_data_model import LOT_DATA
|
||||||
|
from device import device_name
|
||||||
|
|
||||||
|
|
||||||
def t():
|
def t():
|
||||||
|
@ -226,7 +227,7 @@ def on_connect(client, userdata, flags, rc):
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
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")
|
client.username_pw_set("demo", "123456")
|
||||||
# Specify callback function
|
# Specify callback function
|
||||||
client.on_connect = on_connect
|
client.on_connect = on_connect
|
||||||
|
|
Loading…
Reference in New Issue