import paho.mqtt.client as mqtt
product_key = ""
device_name = ""
device_secret = ""
region_id = "cn-shanghai"
topic = "/sys/k13k3tVfCRE/YBXC1/thing/event/property/post"#.format(product_key, device_name)#可能改
client_id = "python_mqtt_client" # MQTT客户端的唯一ID
def on_connect(client, userdata, flags, rc):
print("Connected with result code " + str(rc))
client.subscribe(topic)
def on_message(client, userdata, msg):
print("Topic: " + msg.topic + " Message: " + str(msg.payload))
client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION1, client_id)
client.on_connect = on_connect
client.on_message = on_message
client.username_pw_set(device_name + "&" + device_secret)
client.connect(product_key + ".iot-as-mqtt." + region_id + ".aliyuncs.com", 1883, 60)
client.loop_forever()
总是报这个错:Connected with result code 4
product_key = ""
device_name = ""
device_secret = ""
这三个省略了
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。