Connect to IBM Bluemix* IoT Using MQTT

By Peter Newman,

Published:04/29/2016   Last Updated:04/29/2016

This article provides a step-by-step guide to show you how to set up a connection to IBM Bluemix* using MQTT, as well as command and code samples for additional setup and ease of use.

IBM Bluemix* IoT initial setup

  1. Create an account, if you do not yet have one.

  2. Log into your account.

  3. Select New Dashboard if that option is presented.

Add an Internet of Things Platform

  1. Go to your dashboard and click Use Services or APIs to add a new service.

  2. Click Internet of Things Platform.

  3. In the Service Name field, type a name of your choosing.

  4. From the Selected Plan drop-down list, choose a pricing plan.

  5. Click the Create button.

Add a device type

  1. Under Connect your devices, click the Launch dashboard button.

  2. This opens a new IBM Watson IoT* Platform window.

  3. On the Device Types tile, click the Add Device button.

  4. Click the Create device type button.

  5. This opens the Create Device Type page.

  6. Click the Create device type button.

  7. Fill the Name and Description fields and click Next.

  8. Specify the attributes for your template and click Next.

  9. In the Submit Information step, click Next.

  10. If necessary, add metadata and click Create.

Add a device

  1. From the Choose Device Type drop-down list, select the new device type you created in the previous section, and click Next.

  2. In the Device ID field, type the ID of your device and click Next.

  3. If necessary, add metadata and click Next.

  4. In the Security step, auto-generate an authentication token by clicking Next.

  5. Click Add.

  6. Make a note of the Authentication Token displayed under Your Device Credentials.

Summary

If you have followed all the steps above, you should have all the information that your program needs to connect to the MQTT server:

MQTT_SERVER - use \<Your organization ID\>.messaging.internetofthings.ibmcloud.com, along with the ssl:// (for C++) or mqtts:// (for JavaScript*) protocol

MQTT_CLIENTID - use d:\<Your organization ID\>:\<Your device type\>:\<Your device ID\>

MQTT_TOPIC - use iot-2/evt/status/fmt/json

MQTT_USERNAME - use use-token-auth

MQTT_PASSWORD - use the string with the authorization token of your device

Additional setup for C++

When running your C++ code on the Intel® Edison board, you need to set the MQTT client parameters in Eclipse*. To do that:

  1. Go to Run configurations and, in the Commands to execute before application field, type the following:

    chmod 755 /tmp/<Your app name>; export MQTT_SERVER="ssl://<Your organization ID>.messaging.internetofthings.ibmcloud.com:8883"; export MQTT_CLIENTID="d:<Your organization ID>:<Your device type>:<Your device ID>"; export MQTT_USERNAME="use-token-auth"; export MQTT_PASSWORD="<Your authorization token>"; export MQTT_TOPIC="iot-2/evt/status/fmt/json"
    
  2. Click the Apply button to save these settings.

  3. Click the Run button to run the code on your board.

Additional setup for JavaScript*

When running your JavaScript* code on the Intel® Edison board, you need to set the MQTT client parameters in the Intel® XDK IDE. Add the following entries to the config.json file:

    {
    "MQTT_SERVER": "mqtts://<Your organization ID>.messaging.internetofthings.ibmcloud.com:8883",
    "MQTT_CLIENTID": "d:<Your organization ID>:<Your device type>:<Your device ID>",
    "MQTT_USERNAME": "use-token-auth",
    "MQTT_PASSWORD": "<Your authorization token>",
    "MQTT_TOPIC": "iot-2/evt/status/fmt/json"
    }

IBM Bluemix*

Product and Performance Information

1

Intel's compilers may or may not optimize to the same degree for non-Intel microprocessors for optimizations that are not unique to Intel microprocessors. These optimizations include SSE2, SSE3, and SSSE3 instruction sets and other optimizations. Intel does not guarantee the availability, functionality, or effectiveness of any optimization on microprocessors not manufactured by Intel. Microprocessor-dependent optimizations in this product are intended for use with Intel microprocessors. Certain optimizations not specific to Intel microarchitecture are reserved for Intel microprocessors. Please refer to the applicable product User and Reference Guides for more information regarding the specific instruction sets covered by this notice.

Notice revision #20110804