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

MQTT client keeps disconnecting from Bluemix IOT Foundation

我只是尝试使用 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()

Return 断开连接时的代码是 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"

的内容