1

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.

irf_zack
  • 33
  • 5
  • The https REST API is on 443... I don't see how it could be for sockets also. – amadain Dec 07 '16 at 11:14
  • 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 Dec 07 '16 at 11:27

2 Answers2

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

idan
  • 554
  • 6
  • 19
  • Have you established connection over websocket or tcp ?? I think you are answering for normal tcp connection. The opening of connection must start with the protocol ws(s)://HOST for websocket client. Also, endpoint is required which I do not find ... like for eg., ** wss://HOST:443/PATH/TO/PATH **. – irf_zack Dec 07 '16 at 06:53
  • wss works as well. see below comment from @amadain. Ref to topics, devices publish to the event topics in the format: iot-2/evt/event_id/fmt/format_string **event_id**:ID of the event, for example status. The event ID can be any string that is valid in MQTT. If wildcards are not used, subscriber applications must use this string in their subscription topic to receive the events that are published on their topic. **format_string**: string that defines the content type of the message payload so that the receiver of the message can determine how to parse the content. – idan Dec 08 '16 at 07:27
0

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.

amadain
  • 2,724
  • 4
  • 37
  • 58
  • Thanks amadain for the reply. As you said we don't need to specify a further endpoint. How should we send 'client_id', 'username', 'password'? Does we have to give all these details inside the HEADERS ? – irf_zack Dec 08 '16 at 07:19
  • I don't know anything about erlang. For nodejs it is the same as connecting via mqtt, just protocol changes to wss. You can look at the nodejs sample code. – amadain Dec 09 '16 at 10:09