Table of Contents
- Table of Contents
- Setup an Azure IoT Hub
- (On Windows) Use the Azure IoT Hub DeviceExplorer
- (On Any Platform) Use the iothub-explorer CLI
- Conclusion & Next Steps
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.
Setup an Azure IoT Hub
In a browser, navigate to the Azure Portal at http://portal.azure.com and login. Once logged in:
- Click on the New menu option in the upper-left
- Select Internet of Things
- Select Azure IoT Hub
- Give it a name such as your name followed by ‘IotLabs’ (i.e. rickGrimesIotLabs)
- Select the pricing tier (the free F1 tier works as well for this lab)
- 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 it and:
- 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
(On Windows) Use the Azure IoT Hub DeviceExplorer
Azure IoT Hub only allows connections from known devices that present proper credentials. In this lab series you will use either the DeviceExplorer utility or the iothub-explorer command line interface to provision a device for use in Azure IoT Hub. While Azure IoT Hub supports multiple authentication schemes, you will use pre-shared keys in this lab series.
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 installed, 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.
Create a New Azure IoT Device
If you are using the DeviceExplorer simply open the Management tab and click the Create button. In the dialog that opens, enter the name of your device - something like MyIoTGateway works well. Then 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 by selecting it in the Devices list, right-clicking and selecting Copy connection string for selected device:
(On Any Platform) Use the iothub-explorer CLI
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.
- Download and install Node.js from here.
- 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
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.
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.
Conclusion & Next Steps
Congratulations! You have created an Azure IoT Hub and a representation of a physical device. Next you will write the app that will collect data and send it to the Azure IoT Hubs.