- 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.
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
- An Azure account
- A Mac or a Windows computer with the Azure CLI installed
Azure IoT Hub helps you connect, monitor, and manage millions of IoT assets. To create your IoT hub, follow these steps:
-
Install Azure CLI by running the following command:
npm install -g azure-cli
-
Sign in to your Azure account by running the following command:
azure login
All your available subscriptions are listed after a successful sign-in.
-
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 theazure login
or theazure account list
command. -
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"
-
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 runaz account list-locations -o table
to see all the locations Azure supports. -
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.
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*
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