MQTT客户端始终与Bluemix IOT Foundation

时间:2015-10-10 19:30:13

标签: python ibm-cloud mqtt iot

我只是尝试使用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端获取任何日志文件吗?

1 个答案:

答案 0 :(得分:1)

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