gpt4 book ai didi

python - MQTT 客户端不断与 Bluemix IOT Foundation 断开连接

转载 作者:太空宇宙 更新时间:2023-11-03 17:21:53 24 4
gpt4 key购买 nike

我只是尝试使用 mosquitto mqtt 客户端连接到我的 Bluemix IOT Foundation 实例。我按照 https://docs.internetofthings.ibmcloud.com/messaging/devices.html 中所述配置了所有内容。我的 python 客户端已连接,但一秒钟后断开连接。

import paho.mqtt.client as mqtt

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

def on_disconnect(client, userdata, rc):
print("Disconnect with result code "+str(rc))

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

client = mqtt.Client(client_id="d:gixu3a:RaspberryPi:abcdefgh")

client.on_connect = on_connect
client.on_message = on_message
client.on_disconnect = on_disconnect

client.username_pw_set("use-token-auth", password="XXXXXXX")

client.connect("gixu3a.messaging.internetofthings.ibmcloud.com", 1883, 60)

client.loop_forever()

断开连接时返回代码为 1,我还可以在 IOT Foundation 仪表板内看到连接:

Connection State
Disconnected on Saturday, October 10, 2015 at 9:10:22 PM from 89.140.177.130
with an insecure connection Refresh

我可以从 Bluemix 端获取任何日志文件吗?

最佳答案

这是因为它不接受主题有效 - 设备只能订阅命令 - 尝试订阅类似“iot-2/cmd/acommand/fmt/json”的内容

关于python - MQTT 客户端不断与 Bluemix IOT Foundation 断开连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33058114/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com