This commit is contained in:
xyj 2023-12-11 14:56:51 +08:00
parent d8597294af
commit d19903e199
2 changed files with 8 additions and 7 deletions

View File

@ -9,6 +9,8 @@ import configparser
config = configparser.ConfigParser()
config.read('/home/pi/lot_manager/conf/main/config.conf')
# config.read('/home/lihai/pythonProjects/lot_manager/conf/main/config.conf')
@ -38,8 +40,8 @@ class MQTTClient:
self.client.on_message = self.on_message
def on_connect(self, client, userdata, flags, rc):
self.client.subscribe(self.topic)
self.client.publish('success', payload='成功订阅lot_mqtt,time=' + str(datetime.datetime.now()), qos=0)
client.subscribe(self.topic)
client.publish('success', payload='成功订阅lot_mqtt,time=' + str(datetime.datetime.now()), qos=0)
def on_message(self, client, userdata, msg):
if not valid(msg, client):
@ -77,7 +79,6 @@ class MQTTClient:
pass
def start(self):
self.client.connect(self.broker, self.port)

View File

@ -6,8 +6,8 @@ import paho.mqtt.client as mqtt
from device import device_name
from tool import *
config = configparser.ConfigParser()
config.read('/home/pi/lot_manager/conf/main/config.conf')
# config = configparser.ConfigParser()
# config.read('/home/pi/lot_manager/conf/main/config.conf')
times = 6
@ -26,7 +26,7 @@ class DataUploadClient:
def on_connect(self, client, userdata, flags, rc):
global times
times = 6
self.client.publish('success', payload='连接成功,执行数据推送和本地存储' + str(time.time()), qos=0)
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)
def on_disconnect(self, client, userdata, rc):
@ -44,7 +44,7 @@ if __name__ == '__main__':
# topic = config.get("topic", "name")
# username = config.get("security", "username")
# password = config.get("security", "password")
MQTT = DataUploadClient("192.168.1.27", 1883, "lot_mqt", "demo", "123456")
MQTT = DataUploadClient("192.168.1.27", 1883, "lot_mqtt", "demo", "123456")
while True:
try:
MQTT.start()