update
This commit is contained in:
parent
7e738c71f9
commit
c789292032
|
@ -1,24 +1,10 @@
|
|||
import json
|
||||
import time
|
||||
|
||||
import paho.mqtt.client as mqtt
|
||||
|
||||
from device import device_name
|
||||
from tool import *
|
||||
|
||||
|
||||
def valid(msg, client):
|
||||
origin_data = json.loads(msg.payload.decode('utf-8'))
|
||||
if 'msg' not in origin_data:
|
||||
client.publish('error', payload='msg must be supplied', qos=0)
|
||||
return False
|
||||
if 'device_name' not in origin_data:
|
||||
client.publish('error', payload='device_name must be supplied', qos=0)
|
||||
return False
|
||||
client.publish('error', payload=device_name, qos=0)
|
||||
if device_name != origin_data['device_name']:
|
||||
return False
|
||||
return True
|
||||
times = 6
|
||||
|
||||
|
||||
class DataUploadClient:
|
||||
|
@ -31,6 +17,8 @@ class DataUploadClient:
|
|||
self.client.on_disconnect = self.on_disconnect
|
||||
|
||||
def on_connect(self, client, userdata, flags, rc):
|
||||
global times
|
||||
times = 6
|
||||
self.client.publish('success', payload='连接成功,执行数据推送和本地存储' + str(time.time()), qos=0)
|
||||
subprocess.Popen(['/usr/bin/bash /home/pi/lot_manager/bash/start_data_upload.sh'], shell=True)
|
||||
|
||||
|
@ -51,3 +39,6 @@ if __name__ == '__main__':
|
|||
except:
|
||||
# print("重新连接")
|
||||
time.sleep(10)
|
||||
if times == 0:
|
||||
MQTT.on_disconnect(None, None, None)
|
||||
times -= 1
|
|
@ -189,7 +189,7 @@ def local():
|
|||
add(t)
|
||||
time.sleep(1)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
# print(e)
|
||||
pass
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue