update
This commit is contained in:
parent
a6a9f61ff5
commit
f5fc061309
5
MQTT.py
5
MQTT.py
|
@ -33,13 +33,13 @@ class MQTTClient:
|
||||||
self.password = password
|
self.password = password
|
||||||
# 千万不要指定client_id 不然死翘翘
|
# 千万不要指定client_id 不然死翘翘
|
||||||
self.client = mqtt.Client()
|
self.client = mqtt.Client()
|
||||||
self.client.username_pw_set(self.username, self.password)
|
|
||||||
self.client.on_connect = self.on_connect
|
self.client.on_connect = self.on_connect
|
||||||
self.client.on_message = self.on_message
|
self.client.on_message = self.on_message
|
||||||
|
|
||||||
def on_connect(self, client, userdata, flags, rc):
|
def on_connect(self, client, userdata, flags, rc):
|
||||||
if rc == 0:
|
if rc == 0:
|
||||||
client.subscribe(self.topic)
|
self.client.subscribe(self.topic)
|
||||||
client.publish('success', payload='成功订阅lot_mqtt,time=' + str(datetime.datetime.now()), qos=0)
|
client.publish('success', payload='成功订阅lot_mqtt,time=' + str(datetime.datetime.now()), qos=0)
|
||||||
|
|
||||||
def on_message(self, client, userdata, msg):
|
def on_message(self, client, userdata, msg):
|
||||||
|
@ -78,6 +78,7 @@ class MQTTClient:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
|
self.client.username_pw_set(self.username, self.password)
|
||||||
self.client.connect(self.broker, self.port)
|
self.client.connect(self.broker, self.port)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ class DataUploadClient:
|
||||||
self.password = password
|
self.password = password
|
||||||
# 千万不要指定client_id 不然死翘翘
|
# 千万不要指定client_id 不然死翘翘
|
||||||
self.client = mqtt.Client()
|
self.client = mqtt.Client()
|
||||||
self.client.username_pw_set(self.username, self.password)
|
|
||||||
self.client.on_connect = self.on_connect
|
self.client.on_connect = self.on_connect
|
||||||
self.client.on_disconnect = self.on_disconnect
|
self.client.on_disconnect = self.on_disconnect
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@ class DataUploadClient:
|
||||||
subprocess.Popen(['/usr/bin/bash /home/pi/lot_manager/bash/stop_data_upload.sh'], shell=True)
|
subprocess.Popen(['/usr/bin/bash /home/pi/lot_manager/bash/stop_data_upload.sh'], shell=True)
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
|
self.client.username_pw_set(self.username, self.password)
|
||||||
self.client.connect(self.broker, self.port)
|
self.client.connect(self.broker, self.port)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue