1

基于 Websocket 协议的 MQTT

我正在尝试使用端口 443(ssl/tls)上的 erlang mqtt websockets 连接 IBM Watson IoT 服务。但是,我收到错误。

IBM dos ( https://console.ng.bluemix.net/docs/services/IoT/iotplatform_task.html#devices ) 说它支持 websocket 连接。除了正常的 tcp 连接(我成功连接)之外,没有提到 websocket 的使用(教程/指南)。

我想要一个简单的分步文档,例如 Amazon IoT ( http://docs.aws.amazon.com/iot/latest/developerguide/protocols.html ),用于将 websocket 连接作为客户端应用程序。

我正在计算我认为可能不正确的 URL/URI,即 ws(s)://host:port/path。目前,我将其命名为wss://fybr123mqtt.mybluemix.net (其中fybr123mqtt是我的应用程序名称)。通过 mqtt 连接到 IBM Watson IoT 的主机、端口和路径是什么?以及如何与主机一起发送其他参数,如“client_id”、“用户名”、“密码”、“身份验证令牌”?另外,建议一些用于 mqtt 的 erlang websocket 客户端,并提及访问 websocket 服务器的简单步骤。Erlang mqtt 客户端(emqttc)不支持 websocket。

4

2 回答 2

1

The connection process is clearly described here:
console.ng.bluemix.net/docs/services/IoT/devices/mqtt.html

The URL that you mentioned is not correct: wss://fybr123mqtt.mybluemix.net

On Step 2: Connecting your devices to Watson IoT Platform from console.ng.bluemix.net/docs/services/IoT/iotplatform_task.html#devices it says the following:

The following information is required when connecting your device:

URL: org_id.messaging.internetofthings.ibmcloud.com
Where org_id is the ID of your Watson IoT Platform organization.
Port:
    1883
    8883 (encrypted)
    443 (websockets)
Device identifier: d:org_id:device_type:device_id
This combination of parameters uniquely identifies your device.
Username: use-token-auth
This value indicates that you are using token authorization.
Password: Authentication token
This value is the unique token that you defined or that was assigned to your device when you registered it.

The org_id, device_type, device_id and password are provided after you complete Step 1: Registering your device with Watson IoT Platform

Note: The clienID is Device identifier: d:org_id:device_type:device_id

I successfully used mqttfx, eclipse paho, mosquitto and there are a lot of other free mqtt clients that you can use.

Also, there are good tutorials (recipes) that can help you get starter with IBM's client libraries in Java, Pyhton, etc. As examples you can have a look on: "ibm.com/developerworks/cloud/library/cl-mqtt-bluemix-iot-node-red-app/"

Here is an example for gateway device type with mosquitto "developer.ibm.com/recipes/tutorials/using-mosquitto-as-a-gateway-for-watson-iot/"

Lets not forget the client nodes from NodeRed, that are very easy to use.

Let me know if you still need help on this.

Thanks, Daniel

于 2016-12-07T06:39:23.377 回答
0

网址:wss://6DigitOrgID.messaging.internetofthings.ibmcloud.com:8883

使用 NodeJS 可以正常工作。我没有指定进一步的端点。

[BaseClient:connect] Connecting to IoTF with host : wss://6DigitOrgID.messaging.internetofthings.ibmcloud.com:8883
[DeviceClient:connect] DeviceClient Connected
connected
[DeviceClient:publish] Publishing to topic iot-2/evt/myevt/fmt/json with payload {"radiation":1} with QoS 2

这是基于示例客户 端代码"enforce-ws" : true

我修改了该客户端并使用 443 进行了测试:

[BaseClient:connect] Connecting to IoTF with host : wss://6DigitOrgID.messaging.internetofthings.ibmcloud.com:443
[DeviceClient:connect] DeviceClient Connected
connected
[DeviceClient:publish] Publishing to topic iot-2/evt/myevt/fmt/json with payload {"radiation":1} with QoS 2

我不知道 erlang 的任何示例。

于 2016-12-07T12:45:33.267 回答