Connecting Things to Internet (Part 4) – Configuring and Connecting a Gateway Device to IoT Hub

This is the fourth installment of 5 part series Connecting Things to Internet – a step-by-step guide on how to get things connected to the Internet using low cost devices. In this fourth article, I will focus on getting Windows Azure IoT SDK installed on on your gateway device, The Rasbberry Pi 2, and configure the device in IoT hub that was create in the second article. As mentioned in the earlier article, I will be using Node implementation of Azure IoT SDK in this series.

Installing Azure IoT Node SDK

It is assumed that you already have Node(0.12.x or later) and serialport package installed in your RPi. If not done so, please refer to the previous article and have the gateway device ready before proceeding with the steps in this article. There are 2 ways of installing Azure IoT in your RPi.

Option 1: Installing IoT suite by compiling the source code.


  • Connect to your RPi using Bitvise SSH Client and clone the project to your working directory



  • Now you should have the project cloned in your working directory


  • Navigate to the node folder in your local copy of this repository (azure-iot-sdks). Run the build/ script to prepare your development environment. it will take a while to complete the build. so, please be patient.


  • Then run the build/ script to verify your installation. if the build is completed successfully you should not see any errors.



Option 2: Installing IoT suite by using npm

  • Go to your working directory and execute the following commands in the given order


Configuring Remote Device

After installing Windows IoT Azure SDK on your RPi, the next step of the process is to configure the device that you added in the  second article. Follow the steps to have the device configured in the IoT hub.

  • Copy the following javascript code in to your text editor and save the file, configure-device.js, in the working directory of your RPi. make sure that you replace IoT hub name, device id and the device key in the code with the values recorded from the device creation step. you may add dummy metadata from line 28 to 40. however, make sure to have a valid DeviceID at line 27.
  • Execute the following command
  • Log in to the IoT hub, select the newly added device and verify the device metadata defined in the above code.

This concludes the fourth article in the series. In the fifth and last article, I will explain how to send the sensor data captured from Arduino to the Iot Hub.

Connecting Things to Internet (Part 3) – Device Setup

This is the third article of 5 part series on how to get things connected to Internet. The first article sets the stage for the series by explaining the objectives and the background while the second article focuses on creating the heart of the IoT project, The IoT Hub. In this third article, I will go more hands-on with setting up the physical remote sensing device that will be collecting and pushing telemetry to the IoT hub. Devices generally fall into two categories;

  • Devices that are directly connected to the Internet which has more computing power to support secure IP connections like, Intel Galileo, Particle Core and Windows Phone.
  • The second type is the simple devices requiring a gateway to connect to the Internet. In this article, I will configure Raspberry Pi to act as the gateway for Arduino UNO micro-controller.

Arduino UNO + DHTXX Setup

Before I go into much details, I assume that you have some basic electronics knowledge, basic understanding of Arduino and how to download a sketch code to the controller. if not, please check out the article Getting Started with Arduino. As I mentioned in my first article, a low-cost DHT11 humidity and temperature sensor is used for the project. These sensors are very basic and slow, but are great for hobbyists who want to do some basic data collection and logging. There is also a very basic chip inside that sensor that converts analog temperature and humidity readings to digital and spits out a digital signal.

  • DHTXX has four pins;







  • Connect the sensor to Arduino board as per the below sketch


  • Connect the board to your computer via USB cable


  • Make sure Arduino IDE is configured correctly with your Arduino board by following two steps;
    • Confirm IDE is connected to the correct board. in my case it’s Arduino
    • Confirm the COM port connection. based on your USB connection you will have different COM port


  • Compile and burn the below Arduino code into the board. make sure that you include the DHT library in to your Arduino libraries folder before you start compiling the code. this link provides more information how to import external libraries in to your development environment.

NOTE: Certain bloggers convert raw data into a format that is compatible with the IoT hub application before it’s written to the serial port. In my opinion, micro-controllers are not optimized to carry out heavy string operations and has limited memory capacity. But, they are optimized for read/write operations. Therefore, I will write only the raw data to the serial port and pass the responsibility of string formatting to more powerful gateway device.

  • Open serial monitor(Tools–>Serial Monitor in Arduino IDE) and note the raw data being written to the serial port.


Once you start getting raw data readings on serial port, you are ready for the next step, setting up the gateway device – the Raspberry Pi.

Raspberry Pi 2 B Setup

The next step of the device setup project is the configuration of the Internet gateway. This article assumes that you have fair bit of understanding of Raspberry Pi and it’s models, have a Raspberry Pi up and running which is connected to your wireless network (or wired), and able to connect to it using a remote client, such as Putty or Bitvise SSH Client. I am a fan of Bitvise and will be using it to remotely connect to RPi 2 B. If you don’t have the RPi setup yet, please download the OS and follow the installation guide.

For this article, I will use Node.js implementation of Azure IoT SDK. Please follow the provided steps below in the given order to get the RPi setup with Node SDK.

Installing Node on RPi

  • Update the existing OS by executing the following commands. it will take longer to update your OS if you have not done this for a while.

NOTE 1: If you wish to install the latest Node.js on your RPi, then make sure you have the latest OS, Raspbian Jessie, installed on your device. the latest Node installation will not work with older versions of the OS.

  • Download the latest Node package from Node-ARM site and install the package
  • NOTE 2: You also can install older version of Node.js if you have Raspbian Wheezy OS

  • Install older version of Node

    DISCLAIMER: My advice in this case is to install the older version of Node as Windows Azure IoT SDK does not require you to have latest Node and you always can upgrade to the latest if required. At the time of writing, serialport (Node package that is used to communicate with serial port) is compatible with Node 0.10.xx but, not 1.12.xx. If you are required to install latest Node for other projects, please make sure serialport package is compatibly with your Node version.
  • Verify the installation by typing the following command. it should give you the Node version on your RPi


  • Node Package Manager(npm) is used in the next step to install serialport package. therefore, verify npm instillation with the following command and install npm if not installed already.


Installing serialport package on RPi

  • In addition to setting up Node on your RPi, you also require to install serialport package that enables communication with the micro-controller serial port. please run the following command to have the serialport installed.
  • After installing serialport, run the following command to verify and validate the installation.If serialport is installed successfully, you will see the following output.


Configuring RPi with Arduino

Configuring RPi with Arduino to read serial data involves few steps that you have to follow in the order. First and foremost you have to detect the serial port which Arduino is connected via.

  • Connect Arduino to RPi over any available USB ports.



  • Save the following code into get-serial-ports.js and ftp the file to /home/pi/development/iot (or any working directory of your choice) in your RPi.

  • Execute get-serial-ports.js file



This code will scan the active serial ports in your RPi and return the list of port names to the terminal. Based on the configuration of the device, you will see different serial port names in the format /dev/ttyXXXX and you can choose the appropriate port that is connected to Arduino. In my configuration, /dev/ttyACM0 is connected to Arduino and /dev/ttyAMA0 is connected to wireless network card. Write down the serial port name that will be used in the next step.

  • Save below code into read-serial.js, upload the file to your working directory and run the node file.


If all the steps are followed in the given order you will have your very first IoT device setup that is capable of connecting to the Internet and you should now see RPi reading serial data sent from Arduino scrolling down the command window. As I mentioned earlier, I prefer not to process the data in Arduino, but send the raw data to the RPi that will take care of processing. Therefore, you will see comma separated temperature and humidity readings.

This concludes setting up Raspberry Pi and micro-controller which will be used for telemetry. In my next article, I will explain how to install, configure Windows Azure IoT SDK on your RPi and start sending data to Azure IoT hub that was created in my previous article.


Connecting Things to Internet (Part 2) – Setting up IoT Hub

This is the second part of the 5 part series on how to in get things connected to Internet. In the previous article, I set the stage for the series by explaining the background and the steps that are involved in the series to complete your first IoT project. In this article, I will explain how to setup and configure the heart of the project, Windows Azure IoT hub.

IoT Hub provides foundational services that are specifically designed for secure and reliable bi-directional device connectivity for millions of IoT devices, and enables device management for IoT solutions, at scale, for a diverse set of devices and device topologies. One of the main use of Azure IoT Hub is to gather telemetry from devices. More information on IoT Hub is freely available on the public domain. You may get more additional information on IoT hub in this article. In addition to Azure IoT hub, Microsoft has released Azure IoT Suite in public preview that abstracts existing IoT services like IoT Hub, Stream Analytics, DocuemntDB, Event Hubs, Azure Websites and other services allowing you to focus on the IoT question at hand rather than the implementation. At the time of writing, there are 2 base implementations provided. For this series, I will use the remote monitoring base implementation project.

Provisioning Remote monitoring IoT solution

This section will give you the step-by-step guidance on how to create a IoT remote monitoring site.

  • Log in to (Azure free trial subscription is sufficient for this)
  • Click Select button on  Remote monitoring tile(see image above)


  • Provide solution name, region and the type of the subscription. You may have to enter a different solution name if the solution name is already taken. You will also be able to see the services that will be created as part of the solution that will help to determine the cost that will incur to host the solution on Azure platform.

Solution details

  • Provisioning the IoT remote monitoring application will take several minutes to be completed based on the time of the day and the region you have selected. you will be able to monitor the provisioning status on the provisioning page.



  • Once the solution provisioning is completed you can directly go to the solution home by clicking Solution dashboard. however, I would like to draw your attention to the services that have been provisioned as a part of the solution. clicking on Azure management portal will take you to your management portal.


  • Once you are in the management portal you will see all the required foundational services that are provisioned as a part of the IoT remote monitoring solution. This may give you a very good understanding of what services is required for a IoT solution as well as you may be easily determine the cost of hosting the solution on Azure platform.

All resources


Exploring remote monitoring solution

This section, I will show you the major components of the solution and how the site enables device management capabilities in secure manner. The hub menu identifies 4 admin menu items and 1 command menu item.


Solution dashboard is loaded by default when you navigate to the solution site. there are 3 main areas in the dashboard;



  1. Bing map : maps the location of each device that is defined in the device management list
  2. Telemetry History : Displays temperature and humidity data collected by the selected device.
  3. Alarm History : History of the predefined alarm triggers


The default solution will provision 4 simulated devices that generates random temperature and humidity data. as you can see in the image below, you can edit device metadata in the properties tab of each device. in addition to editing the metadata, you can disable the device, add rule to the device and send a command to the device from the IoT hub.




Third menu item is Rules where you can define various rules for each device.




Last menu item of the Hub Menu is the actions menu that will enable you to assign pre-defined actions on the device.




Add a device will enable you to add a device of your choice. this will be discussed in detail in the next section.


Provisioning remote monitoring devices

In the previous section, I have explained each menu item that is available in your IoT remote monitoring solution. in this chapter we will look at how a new device can be provisioned. the base solution allows us to create a simulated device that generates random device data. however, I am not interested in provisioning a simulated device as our objective is to connect a physical device to the internet and upload telemetry to the Windows Azure website. there are 3 steps involved in adding a physical device to the device management list. we will start by clicking ‘ADD A DEVICE’ menu item at the bottom left of the dashboard.

  • Step 1: Choosing a device type. in this case, we will choose Custom Device and click Add New button.


  • Step 2: Enter a Device ID and check if the id exists already. you may choose to have the system generate an id for you. however, manually entering an id would us enable a human readable id which make us easy to identify the device in the future rather than having a guid assigned to it by the system. after confirming that the id is unique to this solution, click create to provision the device.



  • Step 3: Once the device is provisioned in the device management list, you will be able to retrieve information that will be used to configure your physical device to securely connect to the IoT hub. as you can see, there is a link to an article that explains how to configure a physical device. but, the article assumes that you are programming the device in C++ and lacks the information on how to configure the device to send data to the solution that we are working with.



After verifying and recording the device information,  click Done to go back to the dashboard page. as you can see in the below image, the newly provisioned device is added to the device list. however, it is disabled until actual data is sent to the hub via the physical device.


Now that we have provisioned an IoT hub that is capable of receiving remote sensing data and provisioned a custom device in the device management list, our next step is to configure a physical device that is capable of collecting remote sensing data and upload them to the hub. in my next article, I will go through step-by-step on how to configure Arduino UNO micro-controller with Raspberry Pi.

Connecting Things to Internet (Part 1) – Background and The Project Setup

The “Internet of Things” is expanding exponentially and everybody is talking about it. Samsung’s recent show case of  internet connected refrigerator, Family Hub Refrigerator, is a perfect example of how the world is evolving as a connected world. So, what is IoT anyway?

Simply put, this is the concept of basically connecting any device, with an on and off switch, to the Internet (and/or to each other). This includes everything from mini-scale chips, cell phones, coffee makers, washing machines, headphones, cars, wearable devices and almost anything else you can think of. According to IDC there were about 2 billion things connected to the internet by 2006 and the number passed  15 billion by the end of 2015. It is projected that  200 billion devices and thing will be connected to the internet by year 2020. that is on average 26 smart devices per every person on earth!

Past, present and future of IoT

Not so long ago, it was extremely hard to get something connected to the internet. this subject was mostly limited to major manufacturing and healthcare industry. with the commoditization of mini-scale computers like Raspberry Pi and low cost internet software services, like Windows Azure IoT Suite, opened up a whole new era for makers, hobbyists and  electronics enthusiasts by providing low cost ways to easily get things connected to internet. Recently Microsoft has announced Azure IoT Suite in public preview. This suite is an abstraction layer on top of existing services such as IoT Hub, Stream Analytics, DocumentDb, Event Hubs and other services allowing you to focus on your business scenario rather than the implementation. There are so many blog posts and articles on IoT and it’s uses, and on Windows Azure IoT and telemetry. At the time of writing it was hard to find one location that explains how to get started on IoT suite end-to-end. This was the reason for me to write a series of articles that consolidates all the information scattered every where on the public domain. The series comprises of 5 parts and acts as a one stop shop for how to get started with Azure IoT hub and configuring, and connecting devices. I would suggest that you would follow the steps in the given order to have the project successfully completed.

  1. Connecting Things to Internet (Part 1) – Background and The Project Setup (this article)
  2. Connecting Things to Internet (Part 2) – Setting up IoT Hub
  3. Connecting Things to Internet (Part 3) – Device Setup
  4. Connecting Things to Internet (Part 4) – Configuring  and Connecting the Device to IoT Hub
  5. Connecting Things to Internet (Part 5) – Device Management and Monitoring

This is the first part of multi-part series of articles on how to get started with Internet of Things. The article focuses on building a simple temperature and humidity sensing network using Azure IoT hub. this project is extremely simple and may not suite your current business requirements. however, it serves as the starting point and gives a good understanding of what to expect in a IoT project. It can be built quickly and easily with minimal knowledge of programming or Microsoft Azure, using commodity devices – for example an Arduino UNO board with a simple temperature and humidity sensor like DHT22, connected to a Raspberry Pi sending data to an Azure website.

Project Setup



Hardware prerequisites

For this project I am using Arduino UNO as the micro-controller that acts as the remote device that collects sensory data of DHT22 humidity and temperature collector. This device lacks computing power to directly connect to the internet and send data over secured connection. However, there are micro-controllers that are capable of directly connecting to the internet, like Intel Edison that bypasses a gateway device that is capable of connecting to the internet.

I am using Raspberry Pi 2 as the gateway device that connects to the internet. Pi communicates with Arduino, reads sensory data via serial port, formats the data to a pre-agreed format  and sends the stream to IoT hub.

Software prerequisites

For the purpose of the article, I will be using Node.js on Pi that runs on Debian Linux to read data from Arduino and connect to Azure hub. the choice was mainly determined due to 2 reasons.

  1. Lack of mono support for Azure C# IoT SDK on Pi.
  2. Node.js IoT SDK can be used on previous less powerful models of RPi.

Next Step

In my next article, I will focus on how to set up the IoT hub that provides the skeleton of remote monitoring solution that will be used in the rest of the series. I would recommend that you start by going to Azure portal and sign-up for free trial subscription if you don’t have one already.