Skip to content

Latest commit

 

History

History
102 lines (66 loc) · 3.57 KB

lab-2-2-create-your-iot-hub-and-register-device.md

File metadata and controls

102 lines (66 loc) · 3.57 KB

Lab 2.2: Create your IoT hub and register device

What you will do

  • Create a resource group.
  • Create your Azure IoT hub in the resource group.
  • Add Raspberry Pi 3 to the Azure IoT hub by using the Azure command-line interface (Azure CLI).

When you use Azure CLI to add Pi to your IoT hub, the service generates a key for Pi to authenticate with the service.

What you will learn

In this article, you will learn:

  • How to use Azure CLI to create an IoT hub
  • How to create a device identity for Pi in your IoT hub

What you need

  • An Azure account
  • A Mac or a Windows computer with the Azure CLI installed

Create your IoT hub

Azure IoT Hub helps you connect, monitor, and manage millions of IoT assets. To create your IoT hub, follow these steps:

  1. Install Azure CLI by running the following command:

    npm install -g azure-cli
  2. Sign in to your Azure account by running the following command:

    azure login

    All your available subscriptions are listed after a successful sign-in.

  3. Set the default subscription that you want to use by running the following command:

    azure account set {subscription id or name}

    subscription ID or name can be found in the output of the azure login or the azure account list command.

  4. Register the provider by running the following command. Resource providers are services that provide resources for your application. You must register the provider before you can deploy the Azure resource that the provider offers.

    azure provider register -n "Microsoft.Devices"
  5. Create a resource group named iot-sample in the North Europe region by running the following command:

    azure group create --name iot-sample --location northeurope

    northeurope is the location you create your resource group. If you want to use another location, you can run az account list-locations -o table to see all the locations Azure supports.

  6. Create an IoT hub in the iot-sample resource group by running the following command:

    azure iothub create --name {my hub name} --resource-group iot-sample --location northeurope --sku-name S1 --units 1

    By default, the tool creates an IoT Hub in the Free pricing tier. For more infomation, see Azure IoT Hub pricing.

NOTE: The name of your IoT hub must be globally unique. You can create only one F1 edition of Azure IoT Hub under your Azure subscription.

Register Pi in your IoT hub

Each device that sends messages to your IoT hub and receives messages from your IoT hub must be registered with a unique ID. You will use Azure CLI to register your Pi and create a self-signed X.509 certificate for device authentication.

Run the following command:

npm i -g iothub-explorer
iothub-explorer login **AddConnectionString**
iothub-explorer create **NameOfDevice*

Summary

You've created an IoT hub and registered Pi with a device identity in your IoT hub. You're ready to learn how to send messages from Pi to your IoT hub.

In the next lab you will start sending messages, from your device to IoT Hub.


Back to Lab 2 - IoT with Linux and Node.js

Back to IoT Labs homepage


9gag: Sorry for the long post, here's a potato:

9gag Potato