2022-11-20 19:01:05 +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')
|
|
|
|
client.setVersion('4')
|
|
|
|
client.setKeepAlive('10')
|
|
|
|
|
|
|
|
ret = client.connect()
|
|
|
|
print("ret:%d" % ret)
|
|
|
|
|
2022-11-23 21:16:20 +08:00
|
|
|
client.publish('topic1234', 'hello pikascript')
|
2022-11-23 10:14:48 +08:00
|
|
|
|
2022-11-23 21:16:20 +08:00
|
|
|
|
|
|
|
def callback1(signal):
|
|
|
|
print("py cb: %s:%s" % (client.recv_topic, client.recv_msg))
|
|
|
|
|
|
|
|
|
|
|
|
ret = client.subscribe('topic', 1, callback1)
|
2022-11-20 19:01:05 +08:00
|
|
|
|
2022-11-23 10:14:48 +08:00
|
|
|
client.listSubscribrTopic()
|
|
|
|
|
2022-11-23 09:28:31 +08:00
|
|
|
#ret = client.disconnect()
|
2022-11-20 19:01:05 +08:00
|
|
|
#print("ret:%d" % ret)
|