美文网首页
python mqtt使用

python mqtt使用

作者: 李桥 | 来源:发表于2018-02-28 09:59 被阅读902次

broker 要求证书验证的简单例子
import paho.mqtt.client as mqtt
cafile = "/etc/mosquitto/ca/ca.crt"
certfile = "/home/ubuntu/CA/client.crt"
keyfile = "/home/ubuntu/CA/client.key"
user = "guest"
passwd = "12345678"
server = "localhost"
port = 8883

def on_connect(client, userdata, flags, rc):
print("Connected with result code "+str(rc))
client.subscribe("$SYS/broker/version")

def on_message(client, userdata, msg):
print(msg.topic+" "+str(msg.payload))

client = mqtt.Client()
client.tls_set(cafile,certfile,keyfile)
client.username_pw_set(user,passwd)
client.on_connect = on_connect
client.on_message = on_message

client.connect(server, port, 60)

client.loop_forever()

相关文章

网友评论

      本文标题:python mqtt使用

      本文链接:https://www.haomeiwen.com/subject/zhqbxftx.html