D.I.Y- IBM Bluemix with Python and IoT service

1
1695

IBM Bluemix is a great place to begin with if you are planning to implement internet of things. You can make your application on this platform and bind it to some services. It’s easy to implement internet of things using NODE-RED application. The services can not only be used by the run-time applications on Bluemix but also can be accessed by programs running on remote machines. This is what I have explained in this article. I will be using Python program to publish the data to the IoT service.

At the end of the article, I have attached the required python code for publishing the CPU utilisation of my computer to the IoT cloud provided by IBM Bluemix.

Pre-requisites:

1.You need to register on IBM Bluemix.

2.You should have Linux machine with Paho-MQTT package installed for python.

3.Basics of MQTT.

4.Knowledge of Python programming.

So let’s get started!

Assuming that you have registered and are logged into IBM Bluemix, you will see a page something like this:

Selection_018

Few names that are important here: ORGANISATION, REGION, SPACE.

ORGANISATION – It is like your unique Identity on Bluemix.

REGION – There are two regions(US and UK).By default, my region was US.

SPACE – It is like a directory where your work is saved.All the apps and services are added to your space.I have named my space as “dev”.You can give any name.

Selection_019

After creating the space you can add apps or services to your account.I will add a service called Internet of Things which can be found in the CATALOG tab.This service gives you cloud platform to publish or subscribe the data.The data is published or subscribed using MQTT protocol.I will not elaborate on MQTT.As for now, you should know that it is a machine-to-machine light weight protocol for implementing Internet of Things.

Selection_021

Name your IoT service and Leave it unbound. Then hit create.

Selection_022

You will be asked to add a device.Now device is a “thing” which you want to get connected to the cloud. This “thing” will be called as device hereafter. Any device which intends to publish or subscribe the data needs to be registered first. We do it by adding this device.

Selection_023

Name your device. Device name will be referred to as device type. You can add a description of your device. This is not necessary though. Hit next and you will be asked to add device ID. Now this can be any unique ID. Usually we give MAC address of the device. Any unique sequence of characters will do. Remember that “:” i.e, colons are not valid so you need to remove these from your MAC address.

Selection_024

Selection_025 Selection_026 Selection_027 Selection_028

Leave the authentication token blank as it will be automatically generated. Hit next and you will see a page containing all the important credentials required to authenticate your device. You need to put this information in your code that runs on your machine

Selection_029

That’s it. Now add this newly created device.

You will see your device added in the list. The status of the device initially will be something like this.

Selection_033

Now, I will run the python code on my machine and let’s see what happens

Selection_032
Selection_030

You can see the data on the Bluemix as well. Click on the device name and refresh the prompted page.You will see the data being published by the machine/device.

Selection_031

IBM Bluemix provides various other interesting services and supports many run-time languages to build applications. Do explore them and keep learning!

Python code : ibm-iot-pub.py

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here