Table of Contents
- Table of Contents
- Bill of Materials
- Setup an Azure IoT Hub
- Option 1: Install the IoT Hub Explorer Command Line Interface
- Create a New Azure IoT Device with the IoTHub-Explorer
- Option 2: Install Azure IoT Hub DeviceExplorer (Windows Only)
- Create a New Azure IoT Device with the DeviceExplorer
- 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.
Bill of Materials
What you will need:
- 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 Getting Started.
- Click on the New menu option in the upper-left.
- Select Internet of Things.
- Select Azure IoT Hub.
- Give it a unique name (e.g. rickgrimes-iot-hub).
- 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.
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
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 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.
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)
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.
Create a New Azure IoT Device with the DeviceExplorer
To create a new azure IoT device with DeviceExplorer, do the following:
- Open DeviceExplorer.
- Select the Management tab.
- Click the Create button.
- In the dialog that opens, enter the name of your device (e.g. Thingy).
- 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:
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.