1
votes

MQTT over Websocket protocol

I'm trying to connect IBM Watson IoT service using erlang mqtt websockets on port 443(ssl/tls). But, I was receiving error.

The IBM dos(https://console.ng.bluemix.net/docs/services/IoT/iotplatform_task.html#devices) says that it support websocket connection. There is no mention of the websocket usage(tutorials/guide) except normal tcp connection(which i was successfull at getting conected).

I want a simple step by step doc like the Amazon IoT (http://docs.aws.amazon.com/iot/latest/developerguide/protocols.html) for websocket connectivity as a client application.

I'm figuring about the URL/URI which I think might be improper i.e ws(s)://host:port/path. Currently, i'm giving it as wss://fybr123mqtt.mybluemix.net (where fybr123mqtt is my application name). What is the host, port & path for connecting to IBM Watson IoT through mqtt ? And how to send other parameters like 'client_id', 'username', 'password', 'authentication token' along with the HOST ? Also, suggest some erlang websocket client for mqtt and also mention simple steps to access the websocket server. Erlang mqtt client (emqttc) does not support websocket.

2
The https REST API is on 443... I don't see how it could be for sockets also.amadain
It is 443 and protocol is wss. wss://OrgID.messaging.internetofthings.ibmcloud.com:443. For the java client there is a 'Websockets = true' setting but I have trouble getting it working. I'll try to look again later.amadain

2 Answers

1
votes

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

0
votes

Url: wss://6DigitOrgID.messaging.internetofthings.ibmcloud.com:8883

It works fine using NodeJS. I don't specify a further endpoint.

[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

This is based off the sample client code with "enforce-ws" : true

I modified that client and tested with 443 also:

[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

I don't know of any samples for erlang.