Connecting a Raspberry Pi to IBM Watson, Bluemix and Node-RED
IBM recently helped spark the Internet of Things enthusiasm into a bunch of developers by sending out Raspberry Pi 3 computers to developers who signed up for their Bluemix platform trial. I had been eager to give Bluemix and IBM Watson a try and figured this was as good a time as any to sign up! I was lucky enough to be one of the developers who received a Raspberry Pi 3 and so, I did what I always do with new emerging technology, I began tinkering and writing about my experience.
This is the first part of a series of articles around combining the Raspberry Pi with IBM Watson and Bluemix. This article focuses on the various ways you can connect up the Raspberry Pi to IBM’s cloud services, along with my tips along the way for when things didn’t quite go to plan for me. It was a lot of fun and I highly recommend people give IBM Bluemix and Watson a try, especially if you have a spare Raspberry Pi lying around!
Setting Up a Quick Test of Watson IoT on Our Raspberry Pi
To set up the IBM Watson IoT Platform on our Raspberry Pi, we run the following commands on the Pi itself:
First, we download the Watson IoT Platform installer from IBM’s GitHub:
curl -LO https://github.com/ibm-messaging/iot-raspberrypi/releases/download/188.8.131.52/iot_1.0-2_armhf.deb
Then, we run the following command to install it:
sudo dpkg -i iot_1.0-2_armhf.deb
Once this has installed, it will automatically run the IBM Watson IoT Platform service on our device. In fact, the service runs automatically each time our Pi is booted up. If you aren’t sure if it is running and want to be certain, run the following command:
service iot status
That should bring up a response that looks something like so:
● iot.service – LSB: IoT service
Loaded: loaded (/etc/init.d/iot)
Active: active (running) since Fri 2016-04-29 23:33:47 UTC; 15s ago
└─11960 /opt/iot/iot /dev/null
If you see the above message, you’re good to go! In fact, we can already see Raspberry Pi data being streamed to the IBM’s cloud. To do so, type in:
service iot getdeviceid
It will return an ID for our device and a URL we should visit:
The device ID is abcdefghijkl
For Real-time visualization of the data, visit http://quickstart.internetofthings.ibmcloud.com/?deviceId=abcdefghijkl
If we head to
http://quickstart.internetofthings.ibmcloud.com/?deviceId=abcdefghijkl (with our device’s ID rather than the placeholder), we should see a pretty neat visualization from IBM! In it, we can see our Raspberry Pi’s CPU temperature and other stats from the cloud.
Now, let’s approach it in a different way and set up IBM Bluemix to handle our data.
Getting Started in Bluemix
To log into Bluemix, head to the IBM Bluemix login page. You can sign up for an IBM ID and BlueMix from there too if you do not already have an account.
Once Bluemix loads, we select our region by clicking the top right-hand corner account icon:
Then, if Bluemix requests that we create a space in that region, we do so. I’ve named my space “dev”:
Then, we click on “Use Services or APIs” to find a good initial service for our app.
In this screen, we need to find the “Internet of Things Platform” service. You can do so by either clicking the “Internet of Things” checkbox on the left hand side to filter the selections down, or by typing into the search bar “Internet of Things Platform”. However we search for it, once we have it we select it for our app.
We then click “Create” on the next screen, you could change the “Service Name” if you wanted to adjust this. It doesn’t really affect much, so for my example I just left it as is. You could name it something like “Raspberry Pi Service” if you so desired:
We scroll down on the welcome screen that appears and choose “Launch Dashboard”:
Now we can add our Raspberry Pi to this new service by clicking “Add Device”:
Click to “Create device type”:
Another screen will appear asking whether we want to create a device type or gateway type. We want a device type:
Finally, we name our device type. The first field is for a device type name that will be used in our APIs and such, so keep it lowercase and separated by dashes. e.g. “my-pis” or “iot-sample-devices”. Underneath that, you can write a longer and more human readable description:
The next screen gives us options for our device template, providing fields we can use for each device to define its characteristics. This is very much up to you and what device data you’d like to record in this device type. As I am using this device type to just track Raspberry Pis, I’ve chosen only to define their “Model” (e.g. Raspberry Pi 2, Raspberry Pi 3… etc).
Then, we set our default model type. I set my main model type for this device template to be “Raspberry Pi 3 Model B”:
You can add your own custom metadata in JSON format if you would like, for our purposes in this simple tutorial, we can skip this step.
Now our device type is ready to be used! We should be back at the “Add Device” screen. This time, our new device type should be selected. Check that is the case and click “Next”.
Continue reading %Connecting a Raspberry Pi to IBM Watson, Bluemix and Node-RED%