Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / IoT

Connecting the Intel® IoT Gateway to Microsoft Azure

5.00/5 (1 vote)
9 Sep 2016CPOL5 min read 5K  
This guide will walk you through adding the IoT Cloud repository to your Intel® IoT Gateway and adding support for Microsoft Azure so you can begin developing applications for this platform in your programming language of choice.

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 guide will walk you through adding the IoT Cloud repository to your Intel® IoT Gateway and adding support for Microsoft* Azure* so you can begin developing applications for this platform in your programming language of choice.

Prerequisites

  • Intel® IoT Gateway Technology running IDP 3.1 or above with internet access
  • A development device (e.g. laptop) on the same network as the Intel® IoT Gateway
  • Terminal access to the Intel® IoT Gateway from your development device
  • Microsoft Azure account: https://portal.azure.com/

Please see the following documentation for setting up your Intel® IoT Gateway: https://software.intel.com/en-us/node/633284

Adding the IoT Cloud repository to your Intel® IoT Gateway

  1. Access the console on your gateway either using a monitor and keyboard connected directly or SSH (recommended).
  2. Add the GPG key for the cloud repository using the following command:
    rpm --import <a href="http://iotdk.intel.com/misc/iot_pub.key">http://iotdk.intel.com/misc/iot_pub.key</a>
  3. On your development device (e.g. laptop), open a web browser and load the IoT Gateway Developer Hub interface by entering the IP address of your gateway in the address bar.

    Tip: You can find your gateway’s IP address using the ‘ifconfig’ command.

  4. Log in to the IoT Gateway Developer Hub interface using the credentials root:root.

    Image 1

  5. Add the IoT Cloud repository.
    1. Go to the Packages section and click the Add Repo + button.

      Image 2

      Populate the fields with the following information and click Add Repository:

      Name: IoT_Cloud

      URL: http://iotdk.intel.com/repos/iot-cloud/wrlinux7/rcpl13

      Image 3

      Finally, click the Update Repositories button to update the package list.

Adding Microsoft* Azure* support to your Intel® IoT Gateway

  1. Click the Add Packages + button to bring up the list of packages you can install.

    Image 4

  2. Search for cloud-azure using the search box at the top of the package window. Click the Install button next to the packagegroup-cloud-azure entry.

    Image 5

Setup an Azure* IoT Hub

  1. In a browser, navigate to the Azure* Portal at https://portal.azure.com and log in to your Azure account.
  2. Create a new IoT Hub.
    1. Select New in the top left of the Azure Portal. Select Internet Of Things from the list, and select ‘IoT Hub.

      Image 6

    2. Give your new IoT Hub a unique Name and select which Pricing and scale tier you require.
    3. In the Resource Group section select Create New and give it a unique name in the box provided.
    4. Select the ‘Location’ nearest to you and click Create.

      Image 7

      It will take some time to deploy your new Resource Group and IoT Hub, but eventually you should get a Deployments succeeded notification.

      Image 8

    5. Once your new Resource Group has been created, navigate into it by selecting the Resource groups option in the left-hand panel and selecting the Resource Group you just created from the list.

      Image 9

    6. Select the IoT Hub you just created from the list, then click the Keys icon. Select iothubowner from the policy list, then click the Copy button next to the Connection string-primary key to copy your IoT Hub connection string to the clipboard.

      Image 10

Create a new Azure* IoT Device

Tip: To make copying connection strings easier, it is recommended that you use SSH to connect to your gateway or access the command line through the Intel Developer Hub interface. If you are accessing the command line of your gateway directly using a keyboard and mouse, you will need to manually enter the connection string in the next section.

  1. Enter the following in your gateway’s console to add it to your IoT Hub:
    iothub-explorer "[YOUR CONNECTION STRING]" create IntelIoTGateway --connection-string

    If the device is successfully added, you will get output similar to this:

    Image 11

  2. Load the Node-RED interface. Go to the Administration section of the IoT Gateway Developer Hub and click Launch under the Node-RED icon.

    Image 12

  3. Configure a Node-RED flow.
    1. Drag an ‘inject’, ‘function’ and ‘azureiothub’ node from the nodes panel on the left into the current flow (you may need to scroll down in the nodes panel).Drag an ‘inject’, ‘function’ and ‘azureiothub’ node from the nodes panel on the left into the current flow (you may need to scroll down in the nodes panel).

      Image 13Image 14Image 15

    2. Arrange and connect the nodes as in the screenshot above. Here we have an inject node which will send a trigger at a specified interval to a function which will randomly generate a number to send to your Azure IoT Hub. First we need to configure the nodes.

      Image 16

    3. Double-click on the timestamp node to bring up the configuration dialogue. Change the settings so they match the screenshot below, and click Ok when done. This will set the node to send a trigger every 5 seconds.

      Image 17

    4. Double-click on the ‘function’ node to bring up the configuration dialog box. Here we are going to add some simple code to generate a random number which we can send to our Azure IoT Hub. In reality this could be a sensor reading, for example.
    5. In the ‘Function’ box enter the following code as in the screenshot below:
      msg.payload = Math.round(Math.random() * 100);

      Image 18

      Click the Ok button when done, to close the configuration dialog box.

    6. Double-click the Azure IoT Hub node to bring up the configuration dialog box again. Add the device connection string you copied/saved earlier into the Connection String box and click Ok. (Make sure you enter the device connection string and not the one for your IoT Hub!)

      Image 19

  4. Now your flow is configured you can deploy your flow. Click the Deploy button in the top right of the screen.

    Image 20

    If everything is working correctly, the status of the Azure IoT Hub node should change to Connected and eventually Sent message, as in the screenshot below. A message will be sent to your Azure IoT Hub every five seconds while the flow is running.

    Image 21

    If you navigate back to the Azure* Portal and load your IoT Hub instance, you will see the message count in the Usage tile increasing.

    Image 22

  5. Monitor device events (Optional).

    You can monitor devices in your IoT Hub using the iothub-explorer utility from the command line.

    There is also a Windows utility called Device Explorer if you prefer a visual application: https://github.com/Azure/azure-iot-sdks/blob/master/tools/DeviceExplorer/doc/how_to_use_device_explorer.md

    To monitor device events in the command line on your gateway, run the following command:

    iothub-explorer "[YOUR IOT HUB CONNECTION STRING]" monitor-events [YOUR DEVICE NAME]

    If the Node-RED flow is deployed and running you should see the random numbers being sent to Azure* in the console output similar to the screenshot below.

    Image 23

License

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