1
votes

I am having trouble in MQTT communication. I am new to MQTT and IOT. I am using IBM Bluemix as a cloud service. I can publish the data using node-red MQTT node on the device type. But I am not able to subscribe to that device and topic. Whenever I try to subscribe, it gets disconnected. Thanks

In this picture, I am publishing the status event to the device enter image description here

In this picture, I am getting the published data in the cloud enter image description here

However, as shown below, when i try to subscribe, it gets disconnected enter image description here

PS: I am using the same client ID. I don't know how to use a different client ID for the same device type.

2
If you share your code (or nodered flow) we could help more. Show also the error/warning you get at the disconnect. Make sure your subscribe is not using the same clientid as the publish. Unless they are both the same piece of code, in which case make sure you don't do two connects.amadain
thanks for your reply. how can i use some other clientid rather then the device client id. I am confused at that point.Hsn
according to bluemix documentation clienid should be: d:orgId:deviceType:deviceId and the error i am getting is Code: 8, Message: AMQJS0008I Socket closed.Hsn
It can be the same clientID if it is the same Connection. You cannot, at the same time, use the same clientID for two different connections.amadain
It's just a guess. Which is all can be done with the Q as is. You should include your code or node red flow and the messages you get when you subscribe.amadain

2 Answers

2
votes

When you publish, you are publishing as a device and connecting with the device client ID. A device can not subscribe to a status event, so you should be subscribing as an application. It will connect with an ID such as A:orgId:appId https://console.ng.bluemix.net/docs/services/IoT/applications/mqtt.html#mqtt

0
votes

I am adding this info as answer because it was too long to put as comment. You generate the API key from your Watson IOT Platform service dashboard.

When connecting an Application you need 3 properties:

Organization ($org)

API Key ($key)

API Token ($token)

Applications require an API Key to connect into an Organization. When an API Key is registered a token will be generated that must be used with that API key.

To generate your API Key and token, launch your Watson IoT service dashboard. Select “Apps” from the left sidebar, then “API Keys” in the top menu, and choose “Generate API Key” Button on top right. The platform will provide you with a pair of “API Key” and “Authentication Token”, that you need to note down.
See screenshot. enter image description here

The API key will look something like this: a:$org:a84ps90Ajs

The token will look something like this: MP$08VKz!8rXwnR-Q*

When making an MQTT connection using an API key the following applies:

MQTT client ID: a:$org:$appId MQTT username must be the API key: a:$org:a84ps90Ajs MQTT password must be the authentication token: MP$08VKz!8rXwnR-Q*