Table of Contents
- Table of Contents
- Setup an Azure IoT Hub
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.
Setup an Azure IoT Hub
- Click on the New menu option in the upper-left.
- Select Internet of Things.
- Select Azure IoT Hub.
- Give it a name. (e.g. your name followed by iot-labs).
- Select or create a new Resource Group.
- Select a location. Choose the one closest to your physical location.
Once the IoT Hub is created,
- Navigate into the IoT Hub.
- Click on the key icon at the top of the blade.
- In the next blade, click on the iothubowner entry.
- Copy the Connection string-primary key to your clipboard.
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.
- Download and run Device Explorer.
- After running the installer, the DeviceExplorer.exe can be found at C:\Program Files (x86)\Microsoft\DeviceExplorer.
- Run DevicExplorer.exe.
- Open the Configuration tab.
- Paste the iothubowner connection string from the previous section of this lab in the IoT Hub Connection String field.
- Click Update.
You’ll now create a new Azure IoT Device.
- Switch to the Management tab.
- Click the Create button.
- 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.
- Click the Create button, and click Done on the confirmation dialog that opens.
You will see your device in the Devices list. Once a device is created, you can get the device-specific connection string.
- Select your device in the Devices list
- Right-click and select Copy connection string for selected device:
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.
- Open a command prompt and type the following:
npm install -g iothub-explorer
- 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
- 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 that will collect data from the RPi2 and send it to Azure IoT Hub.