简体   繁体   English

订阅MQTT使用node-red在bluemix中不起作用

[英]Subscribe MQTT not working in bluemix using node-red

I am having trouble in MQTT communication. 我在MQTT通信中遇到麻烦。 I am new to MQTT and IOT. 我是MQTT和IOT的新手。 I am using IBM Bluemix as a cloud service. 我正在将IBM Bluemix用作云服务。 I can publish the data using node-red MQTT node on the device type. 我可以使用设备类型上的节点红色MQTT节点发布数据。 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 在这张照片中,我正在将状态事件发布到设备 在此处输入图片说明

In this picture, I am getting the published data in the cloud 在这张照片中,我正在云中获取已发布的数据 在此处输入图片说明

However, as shown below, when i try to subscribe, it gets disconnected 但是,如下所示,当我尝试订阅时,它会断开连接 在此处输入图片说明

PS: I am using the same client ID. PS:我使用的是相同的客户端ID。 I don't know how to use a different client ID for the same device type. 我不知道如何为同一设备类型使用其他客户端ID。

When you publish, you are publishing as a device and connecting with the device client ID. 发布时,您将作为设备发布并与设备客户端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 它将与一个ID连接,例如A:orgId:appId https://console.ng.bluemix.net/docs/services/IoT/applications/mqtt.html#mqtt

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. 您可以从Watson IOT Platform服务仪表板生成API密钥。

When connecting an Application you need 3 properties: 连接应用程序时,您需要3个属性:

Organization ($org) 组织($ org)

API Key ($key) API密钥($ key)

API Token ($token) API令牌($令牌)

Applications require an API Key to connect into an Organization. 应用程序需要API密钥才能连接到组织。 When an API Key is registered a token will be generated that must be used with that API key. 注册API密钥后,将生成必须与该API密钥一起使用的令牌。

To generate your API Key and token, launch your Watson IoT service dashboard. 要生成API密钥和令牌,请启动Watson IoT服务仪表板。 Select “Apps” from the left sidebar, then “API Keys” in the top menu, and choose “Generate API Key” Button on top right. 从左侧栏中选择“应用程序”,然后在顶部菜单中选择“ API密钥”,然后在右上方选择“生成API密钥”按钮。 The platform will provide you with a pair of “API Key” and “Authentication Token”, that you need to note down. 该平台将为您提供一对“ API密钥”和“身份验证令牌”,您需要记下它们。
See screenshot. 查看截图。 在此处输入图片说明

The API key will look something like this: a:$org:a84ps90Ajs API密钥如下所示:a:$ org:a84ps90Ajs

The token will look something like this: MP$08VKz!8rXwnR-Q* 令牌看起来像这样:MP $ 08VKz!8rXwnR-Q *

When making an MQTT connection using an API key the following applies: 使用API​​密钥建立MQTT连接时,适用以下条件:

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* MQTT客户端ID:a:$ org:$ appId MQTT用户名必须是API密钥:a:$ org:a84ps90Ajs MQTT密码必须是身份验证令牌:MP $ 08VKz!8rXwnR-Q *

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM