Click here to Skip to main content
13,894,726 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


1 bookmarked
Posted 18 Oct 2016
Licenced CPOL

Connecting to Microsoft Azure with Node-RED

, 18 Oct 2016
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.

Editorial Note

This article is in the Product Showcase section 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.


  • 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:

Please see the following documentation for setting up your Intel® IoT Gateway:

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

  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. Login to the IoT Gateway Developer Hub interface using your credentials. The default login and password are both root.
  5. Add the IoT Cloud repository

  6. Go to the Packages section and click the Add Repo + button.

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

    Name: IoT_Cloud


    Finally, click Update Repositories to update the package list.

Adding Microsoft Azure support to your Intel® IoT Gateway

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

    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.

Setting up an Azure IoT Hub

  1. In a browser, navigate to the Azure Portal at and login to your Azure account.
  2. To create a new IoT Hub, click New in the top left of the Azure Portal. Choose Internet of Things > IoT Hub.

  3. Give your new IoT Hub a unique Name and select your Pricing and scale tier.
  4. In the Resource Group section, select Create New and type a unique name in the text field provided.

  5. From the Location drop-down list, select the location nearest to you. Click Create. It will take some time to deploy your new Resource Group and IoT Hub. Once the process is complete, a “Deployments succeeded” message displays.

  6. 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 Resource Groups list.

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

Create a new Azure IoT Device

Tip: We recommended you use SSH to connect to your gateway or access the command line through the Intel Developer Hub interface to make copying connection strings easier. If you are accessing the command line of your gateway directly using a keyboard and mouse, you’ll 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 adding the device is successful, you will get output similar to the above image.

    The device connection string identifies the device by name and includes a key that is only for that device. Copy the device connection string so you can use it in the next section.

Connecting to Microsoft Azure with Node-RED

  1. After installing the Azure cloud package, you need to restart the Node-RED service so it can pick up the newly installed nodes. Run the following command from the gateway’s console:
    systemctl restart node-red-experience
  2. Load the Node-RED interface.

  3. Go to the Administration section of the IoT Gateway Developer Hub and click Launch under the Node-RED icon.
  4. Configure a Node-RED flow.

  5. 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 to find these nodes).

  6. 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.

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

  8. Double-click on the function node to bring up the configuration dialog. Here we are going to add some simple code to generate a random number, which we can then send to our Azure IoT Hub.

    Note: Although this example uses a random number, you could just as easily modify the code to use a sensor reading instead.

  9. In the Function pane, enter the following code as in the screenshot above:
    msg.payload = Math.round(Math.random() * 100);
  10. Click Ok when done to close the configuration dialog.

  11. Double-click the Azure IoT Hub node to bring up the configuration dialogue. Paste the device connection string you copied earlier into the Connection String field and click Ok. Make sure you enter the device connection string and not the one for your IoT Hub!

Now your flow is configured, hit the Deploy button in the top right of the screen to deploy the flow.

If everything is working correctly, the status of the Azure IoT Hub node should change to “Connected”, then “Sent message”, as in the screenshot above. A message will be sent to your Azure IoT Hub every 5 seconds while the flow is running.

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 over time.

Monitoring device events (Optional)

You can monitor devices in your IoT Hub using the b utility from the command line.

There is also a Windows utility called Device Explorer if you prefer a visual application:

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

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.


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


About the Author

Intel Corporation
United States United States
You may know us for our processors. But we do so much more. Intel invents at the boundaries of technology to make amazing experiences possible for business and society, and for every person on Earth.

Harnessing the capability of the cloud, the ubiquity of the Internet of Things, the latest advances in memory and programmable solutions, and the promise of always-on 5G connectivity, Intel is disrupting industries and solving global challenges. Leading on policy, diversity, inclusion, education and sustainability, we create value for our stockholders, customers and society.
Group type: Organisation

43 members

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web05 | 2.8.190306.1 | Last Updated 18 Oct 2016
Article Copyright 2016 by Intel Corporation
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid