Click here to Skip to main content
14,122,532 members
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

5.1K views
1 bookmarked
Posted 17 May 2016
Licenced CPOL

Connecting to IBM Bluemix Internet of Things using MQTT

, 17 May 2016
Rate this:
Please Sign up or sign in to vote.
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.

This article is for our sponsors at CodeProject. These articles are intended to provide you with information on products and services that we consider useful and of value to developers

Get access to the new Intel® IoT Developer Kit, a complete hardware and software solution that allows developers to create exciting new solutions with the Intel® Galileo and Intel® Edison boards. Visit the Intel® Developer Zone for IoT.

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"
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Intel Corporation
United States United States
You may know us for our processors. But we do so much more. Intel invents at the boundaries of technology to make amazing experiences possible for business and society, and for every person on Earth.

Harnessing the capability of the cloud, the ubiquity of the Internet of Things, the latest advances in memory and programmable solutions, and the promise of always-on 5G connectivity, Intel is disrupting industries and solving global challenges. Leading on policy, diversity, inclusion, education and sustainability, we create value for our stockholders, customers and society.
Group type: Organisation

43 members


You may also be interested in...

Pro

Comments and Discussions

 
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web02 | 2.8.190518.1 | Last Updated 17 May 2016
Article Copyright 2016 by Intel Corporation
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid