2022-12-11 14:54:56 +08:00
|
|
|
import mqtt
|
|
|
|
|
|
|
|
client = mqtt.MQTT('192.168.1.255')
|
|
|
|
|
|
|
|
client.setHost('broker.emqx.io')
|
|
|
|
client.setPort(1883)
|
|
|
|
client.setClientID('123456dddecetdc')
|
|
|
|
client.setUsername('test1')
|
|
|
|
client.setPassword('aabbccdd')
|
2022-12-18 00:41:57 +08:00
|
|
|
client.setVersion('3.1')
|
|
|
|
client.setKeepAlive(10)
|
2022-12-11 14:54:56 +08:00
|
|
|
|
|
|
|
ret = client.connect()
|
2022-12-18 00:41:57 +08:00
|
|
|
print("connect ret:%d" % ret)
|
2022-12-11 14:54:56 +08:00
|
|
|
|
2022-12-18 22:25:27 +08:00
|
|
|
client.publish('topic_pikapy', 'hello pikascript qos=0', 0)
|
|
|
|
client.publish('topic_pikapy', 'hello pikascript qos=1', 1)
|
|
|
|
client.publish('topic_pikapy', 'hello pikascript qos=2', 2)
|
2022-12-11 14:54:56 +08:00
|
|
|
|
|
|
|
ret = client.disconnect()
|
2022-12-18 22:25:27 +08:00
|
|
|
print("disconnect ret:%d" % ret)
|