将 Bluemix 地理空间服务连接到 Watson IoT Platform 时出现未授权错误

Not authorized error connecting Bluemix geospatial service to Watson IoT Platform

我已经在 Bluemix 中部署了 Bluemix GeoSpatial 入门应用程序。

它工作正常,直到我想连接到 Watson IoT Platform 而不是演示 MQTT 服务器。

我将 mqtt1.m2m4connectedlife.com 更改为 dzqml6.messaging.internetofthings.ibmcloud.com 并将 mqtt_uidmqtt_pw 添加到启动参数 jsonObject。

我在 Watson IoT Platform 仪表板中创建了一个 API 键,并将这些值用于 mqtt_uidmqtt_pw

然后我在启动应用程序时在日志中得到一个"Error: Connection refused: Not authorized"。

然后我还尝试了 mqtt_uidmqtt_pw 的 Watson IoT Platform 环境变量中的 apiKey 和 apiToken,但仍然出现相同的错误。

我也为 clientid 和 notify/input 主题尝试了不同的值,但没有成功。

我阅读了一些其他 post 的类似错误,由于在创建组织和分发到所有服务器之间存在延迟,这些错误在一段时间后得到解决。

https://developer.ibm.com/answers/questions/163862/iot-cloud-error-not-authorized.html

等了一天还是一样的错误

我还按照 post 中的建议将自己添加为该组织的永久成员:

如有任何帮助,我将不胜感激!

当您使用 API 密钥建立 MQTT 连接时,请确保以下几点适用:

The MQTT client ID is in the format: a:orgId:appId
The MQTT user name is the API key: such as a-orgId-a84ps90Ajs
The MQTT password is the authentication token: such as MPVKz!8rXwnR-Q*

有关详细信息,请参阅 documentation。如果您仍然遇到错误,请告诉我们您的 IoT 服务的 6 个字符组织 ID,我们可以检查日志以解决您出现授权错误的原因。

起始应用程序中有一部分 Node.js 代码直接订阅通知主题。身份验证错误是否来自该订阅尝试?如果是这样,您是否修改了那部分代码以传递凭据?

这是我所指的 app.js 中的代码行。

var clientId = 'geo-quickstart:' + port;
//create the MQTT client and subscribe
client = mqtt.createClient(1883,"mqtt1.m2m4connectedlife.com", { "clientId": clientId } );
console.log("Subscribing to topic: " + notify_topic_string + "\n");
client.subscribe(notify_topic_string);

如果您没有在 createClient 调用中传递凭据,请尝试将参数 {username: "user", password: "pass"} 添加到参数列表中。