This commit is contained in:
xyj 2023-12-07 09:20:44 +08:00
parent 9ac576d57b
commit 28cdd733bc
3 changed files with 5 additions and 5 deletions

View File

@ -48,7 +48,6 @@ def exec_shutdown():
if __name__ == '__main__': if __name__ == '__main__':
while True: while True:
try: try:
client = mqtt.Client(client_id='device1') client = mqtt.Client(client_id='device1')
@ -58,10 +57,11 @@ if __name__ == '__main__':
client.on_message = on_message client.on_message = on_message
# Establish a connection # Establish a connection
# ceshi-mqtt.lihaink.cn # ceshi-mqtt.lihaink.cn
client.connect('ceshi-mqtt.lihaink.cn', 1883) client.connect('192.168.1.27', 1883)
# Publish a message # Publish a message
client.loop_forever() client.loop_forever()
except: except:
print("等待30秒连接")
time.sleep(30) time.sleep(30)
if times == 0: if times == 0:
# 重启机器 # 重启机器

View File

@ -35,11 +35,11 @@ if __name__ == '__main__':
client.on_connect = on_connect client.on_connect = on_connect
client.on_connect_fail = on_connect_fail client.on_connect_fail = on_connect_fail
# Establish a connection # Establish a connection
client.connect('ceshi-mqtt.lihaink.cn', 1883) client.connect('192.168.1.27', 1883)
# Publish a message # Publish a message
client.loop_forever() client.loop_forever()
except Exception as e: except Exception as e:
# print("等待5秒重新连接客户端") print("等待5秒重新连接客户端")
time.sleep(5) time.sleep(5)
if times != 0: if times != 0:
times -= 1 times -= 1

View File

@ -200,6 +200,6 @@ if __name__ == '__main__':
client.on_connect = on_connect client.on_connect = on_connect
# Establish a connection # Establish a connection
# ceshi-mqtt.lihaink.cn # ceshi-mqtt.lihaink.cn
client.connect('ceshi-mqtt.lihaink.cn', 1883) client.connect('192.168.1.27', 1883)
# Publish a message # Publish a message
client.loop_forever() client.loop_forever()