2022-12-11 14:54:56 +08:00
|
|
|
import mqtt
|
2022-12-11 19:08:16 +08:00
|
|
|
import PikaStdDevice
|
2022-12-11 14:54:56 +08:00
|
|
|
|
2022-12-11 19:08:16 +08:00
|
|
|
client = mqtt.MQTT('broker.emqx.io',port=1883,clinetID='clientid',username='name_',password='passwd_')
|
2022-12-11 14:54:56 +08:00
|
|
|
|
|
|
|
ret = client.connect()
|
|
|
|
print("ret:%d" % ret)
|
|
|
|
|
2022-12-11 19:08:16 +08:00
|
|
|
def callback0(signal):
|
|
|
|
print("py cb: %s:%s" % (client.recv_topic, client.recv_msg))
|
2022-12-11 14:54:56 +08:00
|
|
|
|
|
|
|
|
2022-12-11 19:08:16 +08:00
|
|
|
ret = client.subscribe('topic_pikapy_qos0', 0, callback0)
|
|
|
|
print("ret:%d" % ret)
|
2022-12-11 20:09:29 +08:00
|
|
|
ret = client.subscribe('topic_pikapy_qos1', 1,0)
|
|
|
|
print("ret:%d" % ret)
|
|
|
|
ret = client.subscribe('topic_pikapy_qos2', 2,0)
|
|
|
|
print("ret:%d" % ret)
|
2022-12-11 14:54:56 +08:00
|
|
|
|
|
|
|
|
2022-12-11 19:08:16 +08:00
|
|
|
#sleep wait for recv data
|
|
|
|
T = PikaStdDevice.Time()
|
|
|
|
T.sleep_s(5)
|
|
|
|
|
2022-12-11 20:09:29 +08:00
|
|
|
out = client.listSubscribrTopic()
|
|
|
|
print('out',out)
|
2022-12-11 19:08:16 +08:00
|
|
|
|
2022-12-11 20:09:29 +08:00
|
|
|
client.unsubscribe('topic_pikapy_qos0');
|
|
|
|
client.unsubscribe('topic_pikapy_qos1');
|
|
|
|
client.unsubscribe('topic_pikapy_qos2');
|
2022-12-11 14:54:56 +08:00
|
|
|
|
2022-12-11 19:08:16 +08:00
|
|
|
T.sleep_s(5)
|
2022-12-11 14:54:56 +08:00
|
|
|
client.listSubscribrTopic()
|
|
|
|
|
2022-12-11 19:08:16 +08:00
|
|
|
T.sleep_s(10)
|
|
|
|
|
|
|
|
ret = client.disconnect()
|
|
|
|
print("ret:%d" % ret)
|