Building Connected Things with an ESP8266 and Microsoft Azure

Setting Up 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 (a software reference to your physical device) that you will use to send telemetry to Azure.

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.

  1. Login to the account you created in Getting Started.
  2. Click on the New menu option in the upper-left.
  3. Select Internet of Things.
  4. Select Azure IoT Hub.
  5. Give it a unique name (e.g. rickgrimes-iot-hub).
  6. Select or create a new Resource Group.
  7. Select a location. (Choose the one closest to your physical location.)

New IoT Hub

Once the IoT Hub is created, navigate into it and:

  1. Click on the key icon at the top of the blade.
  2. In the next blade, click on the iothubowner entry.
  3. 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: Install the IoT Hub Explorer Command Line Interface

Cross Platform

If you are on a non-Windows machine, or prefer to use a command line interface instead of the DeviceExplorer utility, you can install the iothub-explorer command line interface. The iothub-explorer tool enables you to provision, monitor, and delete devices in your IoT hub. It runs on any operating system where Node.js is available.

  1. Download and install Node.js from here.
  2. From a command line (Command Prompt on Windows, or Terminal on Mac OS X), execute the following:
npm install -g iothub-explorer

Create a New Azure IoT Device with the IoTHub-Explorer

If you are on a non-Windows machine, or prefer to use a command line interface instead of the DeviceExplorer utility, you can provision a new Azure IoT Hub device using the iothub-explorer command line interface.

In the same directory as before, using the Node.js command prompt or Terminal, execute the following command: (you may need to wrap the connections string in quotes, depending on the command line application you are using)

  iothub-explorer "[YOUR IOT HUB CONNECTION STRING]" create Thingy --connection-string

Once a device is created, the device information, including the device-specific connection string, will be displayed.

New Device using IoT Hub Explorer

The device-specific connection string identifies the device by name and includes a key that is only for that device. Make a note of the device connection string; you will need it in the next lab.

Option 2: Install Azure IoT Hub DeviceExplorer (Windows Only)

Windows Only

The simplest way to provision a new device is with the DeviceExplorer utility (Windows only). If you are using Windows, download and run Device Explorer. After running the installer, the DeviceExplorer.exe can be found at C:\Program Files (x86)\Microsoft\DeviceExplorer. When you run the utility you need to input the iothubowner connection strong (from the previous step) in the IoT Hub Connection String field found in the Configuration tab.

Device Explorer

Create a New Azure IoT Device with the DeviceExplorer

To create a new azure IoT device with DeviceExplorer, do the following:

  1. Open DeviceExplorer.
  2. Select the Management tab.
  3. Click the Create button.
  4. In the dialog that opens, enter the name of your device (e.g. Thingy).
  5. Click the Create button, and click Done on the confirmation dialog that opens.

Create a Device

You will see your device in the Devices list. Once a device is created, you can get the device-specific connection string by selecting it in the Devices list, right-clicking and selecting Copy connection string for selected device:

Device Connection String

For more information on how to use DeviceExplorer, the Project deviceexplorer is available on Github.

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’ll deploy an Azure Web Site that uses D3.js to visualize the output of your Weather Station.

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