This commit is contained in:
xyj 2023-12-09 17:43:08 +08:00
parent ee953c9c73
commit 232a2955cc
2 changed files with 2 additions and 8 deletions

View File

@ -67,11 +67,6 @@ def on_message(client, userdata, msg):
times = 120 times = 120
def exec_shutdown():
pass
client = mqtt.Client(client_id=device_name) 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
@ -81,9 +76,8 @@ while True:
try: try:
# ceshi-mqtt.lihaink.cn # ceshi-mqtt.lihaink.cn
client.connect('192.168.1.27', 1883) client.connect('192.168.1.27', 1883)
client.loop_forever() client.loop_start()
except Exception as e: except Exception as e:
print("Connection failed:", e) print("Connection failed:", e)
time.sleep(10) time.sleep(10)
print("正在尝试重连") print("正在尝试重连")

View File

@ -32,7 +32,7 @@ while True:
try: try:
# ceshi-mqtt.lihaink.cn # ceshi-mqtt.lihaink.cn
client.connect('192.168.1.27', 1883) client.connect('192.168.1.27', 1883)
client.loop_forever() client.loop_start()
except Exception as e: except Exception as e:
print("Connection failed:", e) print("Connection failed:", e)
if times == 0: if times == 0: