Internet of Things – Publish To BlueMix

Today I will talk about how you can publish your sensor data to BlueMix in the IBM cloud. I will publish information about the temperature and level of light in my room, and then I will show how that information can be viewed in real-time.

This video build on my previous video called “Internet of Things – Publish Sensor Data”, so please check that out for details. Just as in that video, I’m will be using temperature and light sensors, and publish their data to an MQTT broker. The difference is that this time I’m publishing to BlueMix, which is in the the IBM cloud (for more details on how to publish sensor data to BlueMix, see All the hardware that you need to perform this lab is the same as in the previous video, so please check that out for the details. The Arduino code (sketch) looks like this…

…and after the initial includes, constants for the two analogue input pins are defined (on lines 4-5). The MQTT client object is defined and created (on lines 6-7), followed by the declaration of a number of variables (on line 8-12). In the setup, we initialize the bridge (on line 16), which allows communication between the microcontroller and the microprocessor, and then I connect the MQTT client to the server (on line 17, and here you should replace the twelve zeros with the MAC address in lowercase of the Arduino network card). The eternal loop starts by checking if a five second interval has passed, and if so, reads the value from the temperature sensor (on line 25). Since that value is a raw value (in the range 0-1023), it needs to be converted (on lines 26-28) to a temperature using a formula (for more info, see, and then the temperature is added to the payload (on line 29). The light sensor value is read (on line 30) and added to the published data (on line 31), and the data is published to the MQTT broker (on lines 32-33).

When you have complied and uploaded the code to the Arduino, it starts publishing data to BlueMix, and to see that data in real-time, you can browse to (replace 000000000000 with the MAC address of the network card). As you can see at the bottom, you can choose to see either of the two published sensor data. The service that provides this functionality, the Internet of Things Foundation, can also store historic data, and can make it available through a secure API.

That is how you can publish your sensor data to BlueMix, and see it in real time.