Table of Contents
- Table of Contents
- Bill of Materials
- Setup an Azure IoT Hub
- Install Azure IoT Hub DeviceExplorer
- Create a New Azure IoT Device
- Conclusion & Next Steps
If you haven’t already done so, please follow the instructions in ‘Getting Started’.
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:
- A Microsoft Azure Account (refer to ‘Getting Started’)
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 such as your name followed by ‘iot-labs’ (i.e. rickgrimes-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 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
Install 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.
Install the IoT Hub Explorer Command Line Interface
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 devices in your IoT hub. It runs on any computer where Node.js is available.
On Windows, open the Node.js command prompt and type the following:
cd C:\Development\IoTLabs npm install -g iothub-explorer npm update -g iothub-explorer
On Mac OS X open Terminal and type the following:
cd ~/Development/IoTLabs npm install -g iothub-explorer npm update -g iothub-explorer
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:
Create a New Azure IoT Device from the Command Line
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 commands (you may need to wrap the connections string in quotes, depending on the terminal application you are using). You may replace MyIoTGateway with any name you’d like:
iothub-explorer [YOUR IOT HUB CONNECTION STRING] create MyIoTGateway --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. Copy the device connection string somewhere that you will be able to access it shortly.
Conclusion & Next Steps
Congratulations! You have created an Azure IoT Hub and a representation of a physical device. Next you will prepare the development board you will be working with throughout these labs.
Continue to the next labs based on the device you are working with.