In this task, we'll create the <name>iot Microsoft Azure* IoT Hub and since it's our first Azure resource, we'll create the <name>group resource group to put it in. Make sure that you understand the information in the Planning your Azure Resources section before continuing.
2. Click the + New button, then select Internet of Things, and select Iot Hub.
3. Complete the properties for the new IoT Hub as shown below, the click the Create button to provision the new IoT Hub in the new Resource Group:
- Name: <name>iot - Use the naming prefix you selected in the Planning your Azure Resources section.
- Pricing and scale tier: S1 - Standard (There is a free tier, but we will be removing these resources at the end of the lab, and the S1 pricing teir should not impact your subscription significantly)
- IoT Hub units: 1
- Device-to-cloud partitions: 4
- Subscription: choose the subscription you wish to use if you have multiple available
- Resource Group: Create new resource group using the <name>group naming convention
- Location: Choose the location listed above that is closest to you, and then make sure to use that location for all other resources in the lab.
- Pin to dashboard: Checked (this will place a tile for the IoT Hub on your portal dashboard.)
Note: The Enable Device Management-PREVIEW option will likely not be there. This screen shot was taken when that feature was still in preview.
4. The IoT Hub could take five minutes or longer to deploy. While it is deploying, a tile will be shown on your portal dashboard that looks like this:
5. Once the deployment is complete, the blade for your IoT Hub should open in the portal.
6. In order to connect to your IoT Hub from client applications, you need to know the name and key for a Shared Access Policy (SAS Policy) that provides your client application the necessary privileges. Your IoT Hub comes pre-provisioned with a number of SAS policies that you can use, or you can create additional policies as needed. In this lab we will use two of the default SAS policies.
- iothubowner - This policy allows applications that connect with it full access to the IoT Hub. They can manage devices registered with the hub, as well as send and receive messages. We will use this SAS policy when we want to manage our IoT Hub.
- service - This policy is intended for back-end services or client applications that need to interact with devices via the IoT Hub. These applications need to be able to receive messages coming into the hub from devices in the field (Device-to-Cloud messages), as well as send messages back to those devices (Cloud-to-Device messages). This policy is granted the service connect permission which allows it to do just that.
7. In the portal, with your IoT Hub blade open, click on the Shared access policies along the left edge to see the hub's SAS policies:
8. Click on the iothubowner policy name to see its details, then click on the Copy Icon to the right of the Connect string - primary key to copy the connection string to your clipboard.
9. Update the the myresources.txt file with the ***<name>iot*** iot hub name, and iothubowner connection string so you can retrieve them easily later.
10. Repeat the last two steps to copy and document the service SAS policy primary connection string:
Note: Make sure to save the changes to the myresources.txt file each time.
11. The last thing we need to do to configure our IoT Hub is to add a Consumer Group for the <name>job Stream Analytics Job to use as it reads messages from the IoT Hub.
Note: Consumer groups enable multiple consuming applications to each have a separate view of the event stream, and to read the stream independently at their own pace and with their own offsets. In a stream processing architecture, each downstream application equates to a consumer group. By creating a consumer group specifically for the Stream Analytics Job, it allows us to use other tools (like iothub-explorer) to monitor messages using the $Default consumer group, and not conflict with the Stream Analytics job. Basically each consumer group allows you to run a different application (or pool of consumers) on the hub and allow each application to receive their own copy of the messages.
- Click on the Endpoints link along the left, then click on the Events endpoint
- In the Properties blade for the Events endpoint, at the bottom, enter the following name into the empty box below the $Default consumer group:
- Click the Save button at the top of the Properties blade to save the new consumer group, the close the Properties blade.