This commit is contained in:
xyj 2023-12-05 17:04:37 +08:00
parent 42a53c63fa
commit a5e3ec951c
3 changed files with 6 additions and 4 deletions

View File

@ -46,7 +46,8 @@ class MQTT:
self.client.on_connect = self.on_connect
self.client.on_message = self.on_message
# Establish a connection
self.client.connect('ceshi-mqtt.lihaink.cn', 1883)
# ceshi-mqtt.lihaink.cn
self.client.connect('127.0.0.1', 1883)
# Publish a message
self.client.loop_forever(retry_first_connection=True)

View File

@ -35,7 +35,7 @@ if __name__ == '__main__':
client.on_connect = on_connect
client.on_connect_fail = on_connect_fail
# Establish a connection
client.connect('ceshi-mqtt.lihaink.cn', 1883)
client.connect('127.0.0.1', 1883)
# Publish a message
client.loop_forever()
except Exception as e:

View File

@ -40,11 +40,12 @@ def on_connect(client, userdata, flags, rc):
if __name__ == '__main__':
client = mqtt.Client(transport="websockets")
client = mqtt.Client()
client.username_pw_set("demo", "123456")
# Specify callback function
client.on_connect = on_connect
# Establish a connection
client.connect('ceshi-mqtt.lihaink.cn', 8083)
# ceshi-mqtt.lihaink.cn
client.connect('192.168.1.27', 1883)
# Publish a message
client.loop_forever()