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ru8MA0GCSqGSIb3DQEBCwUAA4IBAQBLQNvAUKr+yAzv95ZU\r\n"
|
|
|
|
"RUm7lgAJQayzE4aGKAczymvmdLm6AC2upArT9fHxD4q/c2dKg8dEe3jgr25sbwMp\r\n"
|
|
|
|
"jjM5RcOO5LlXbKr8EpbsU8Yt5CRsuZRj+9xTaGdWPoO4zzUhw8lo/s7awlOqzJCK\r\n"
|
|
|
|
"6fBdRoyV3XpYKBovHd7NADdBj+1EbddTKJd+82cEHhXXipa0095MJ6RMG3NzdvQX\r\n"
|
|
|
|
"mcIfeg7jLQitChws/zyrVQ4PkX4268NXSb7hLi18YIvDQVETI53O9zJrlAGomecs\r\n"
|
|
|
|
"Mx86OyXShkDOOyyGeMlhLxS67ttVb9+E7gUJTb0o2HLO02JQZR7rkpeDMdmztcpH\r\n"
|
|
|
|
"WD9f\r\n"
|
|
|
|
"-----END CERTIFICATE-----"]
|
|
|
|
|
|
|
|
client = mqtt.MQTT('192.168.1.255')
|
|
|
|
|
|
|
|
#test TLS
|
|
|
|
# client.setHost('j6npr4w.mqtt.iot.gz.baidubce.com')
|
|
|
|
# client.setPort(1884)
|
|
|
|
# client.setCa(test_baidu_ca_crt)
|
|
|
|
|
|
|
|
client.setHost('broker.emqx.io')
|
|
|
|
client.setPort(1883)
|
|
|
|
|
|
|
|
client.setClientID('123456dddecetdc')
|
|
|
|
client.setUsername('j6npr4w/mqtt-client-dev')
|
|
|
|
client.setPassword('lcUhUs5VYLMSbrnB')
|
2022-12-18 00:41:57 +08:00
|
|
|
client.setVersion('3.1.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
|
|
|
|
|
|
|
ret = client.disconnect()
|
2022-12-18 00:41:57 +08:00
|
|
|
print("disconnect ret:%d" % ret)
|