Building Connected Things with Windows 10 IoT and Microsoft Azure

Lab 04: Setting Up an Azure IoT

In this lab, you will provision an Azure IoT Hub and an IoT Hub device.

Table of Contents

In this lab you will provision a new Azure IoT Hub. Once you have the IoT Hub created, you will be able to create a new Azure IoT device that you will use to send telemetry to Azure. Azure IoT devices are software references to physical devices.

Bill of Materials

What you will need:

  1. An Azure Account.

Setup an Azure IoT Hub

In a browser, navigate to the Azure Portal at https://portal.azure.com. Login to the account you created in the ‘Getting Started’ lab. Once logged in:

  1. Click on the New menu option in the upper-left.
  2. Select Internet of Things.
  3. Select Azure IoT Hub.
  4. Give it a name. (e.g. your name followed by iot-labs)
  5. Select or create a new Resource Group.
  6. Select a location. Choose the one closest to your physical location.

New IoT Hub

Once the IoT Hub is created,

  1. Navigate into the IoT Hub.
  2. Click on the key icon at the top of the blade.
  3. In the next blade, click on the iothubowner entry.
  4. Copy the Connection string-primary key to your clipboard.

Azure IoT Hub Connection String

Azure IoT Hub only allows connections from known devices that present proper credentials. In this lab you will use either the DeviceExplorer utility or the iothub-explorer command line interface to provision a device for use in Azure IoT Hub. Although Azure IoT Hub supports multiple authentication schemes, you will use pre-shared keys in this lab.

Option 1: Use Azure IoT Hub DeviceExplorer (Windows Only)

The simplest way to provision a new device is with the DeviceExplorer utility. DeviceExplorer is only available in Windows.

  1. Download and run Device Explorer.
  2. After running the installer, the DeviceExplorer.exe can be found at C:\Program Files (x86)\Microsoft\DeviceExplorer.
  3. Run DevicExplorer.exe.
  4. Open the Configuration tab.
  5. Paste the iothubowner connection string from the previous section of this lab in the IoT Hub Connection String field.
  6. Click Update.

DeviceExplorer

You’ll now create a new Azure IoT Device.

  1. Switch to the Management tab.
  2. Click the Create button.
  3. In the dialog that opens, enter a name for your IoT device. This can be the same name as your Raspberry Pi 2, or it can be different.
  4. Click the Create button, and click Done on the confirmation dialog that opens.

Create a new virtual device

You will see your device in the Devices list. Once a device is created, you can get the device-specific connection string.

  1. Select your device in the Devices list
  2. Right-click and select Copy connection string for selected device:

Get the device-specific connection string

Option 2: Use the IoT Hub Explorer Command Line Interface (Cross Platform)

If you’re not using Windows, or if you prefer to use a command line interface, you can install the iothub-explorer command line interface. The iothub-explorer tool enables you to provision devices in your IoT hub. It runs on any computer where Node.js is available. You can install Node.js from NodeJS.org.

  1. Open a command prompt and type the following:
  npm install -g iothub-explorer
  1. After iothub-explorer is installed, execute the following, replacing [connection-string] with your iothubowner connection string (from the previous lab) and [device-id] with the Azure IoT Hub id for this device.
  iothub-explorer [YOUR IOT HUB CONNECTION STRING] create [YOUR DEVICE NAME] --connection-string
  1. Copy the device-specific connection string.

Conclusion & Next Steps

Congratulations! You have created an Azure IoT Hub that you will connect devices to. You also created a representation of a physical device in your IoT Hub. In the next lab you will build a Universal Windows Application application that will collect data from the Raspberry Pi 2 and send it to Azure IoT Hub.

Go to ‘Lab 05: Sending Device-to-Cloud (D2C) Messages’ ›