RPI-Pico-Arduino-AzSDK: Create an IoT Hub and Device
For the Azure IoT SDK C Arduino, an IOT Hub and an “attached” Device are required. There are a number of ways to create them ….
For the Azure IoT SDK C Arduino, you need IoT Hub and a Device connected to it. You will need an Azure Subscription, whether Free or Paid. It is suggested that you create the Hub and Device in a new Group so deletion only requires deletion of the Group. The Hub needs to be a Free (F1) or Standard (S1) or else Methods etc won’t work. During the creation you are prompted for a Region. I just choose the closest one to me; which is in my country (Australia SE).
There are various ways to create an Azure IOT Hub:
- In the Azure Portal
- In the VS Code using the Azure IoT Visual Studio Code extension.
- Command line API scripts
- djaus2/az-iothub-ps PowerShell scripts.
Acccording to the VSCode Extension:
The Azure IoT Visual Studio Code extension is in a maintenance mode. Please see this announcement for more details. We recommend using the command line steps to develop edge modules over VSCode extensions.
There is some pushback on this, particularly given that the Microsoft Learn, newbe focused, documents still use the extension in VS Code.
Note that apart from the Azure Portal approach (where you are already logged in), you need to do an az login before you can start any azure creations.
Create an IoT Hub and Device
Start: Get an Azure Subscription if you don’t already have one.
Create and IoT Hub and Device on Azure using one of the following methods:
1. Azure Portal
- Log on to the Azure Portal
- Follow the steps here
2. Azure Cli
- Start by installing the Az Cli as per here
- In a Terminal (eg in VS Code) copy the commands in order as per here
3. Azure PowerShell
This can be done in a browser using an Azure Cloud Shell:.
- Follw the direction here
4. VS Code Azure IoT Hub extension.
- Follow the steps to create an IoT Hub and device here down to (but not including) “Send simulated telemetry and listen for direct method calls”.
5. az-iothub-ps PowerShell Script/s
I have another repository that when cloned and opened in VS Code provides a menu driven context for creating and managing an Azure IoT Hub and releated entities. The scripts can be used separately or as a menu driven UI:
- Get an Azure Subscription (You can get a free one for a month or so).
- Clone the above repository and open the PS folder in VS Code and from a terminal run:
- Select the subscription and login
- Create a new Group
- Create a new IoT Hub
- Create a new Device
- Get the Connectivity details (6. Environment Variables)
These connection strings are used in dicuussions later in this blog series.
In get-iothub, assuming you have have done the az login and you have a selected Subscription, select option 9…
1. Subscription <-- Current Selection 2. Groups 3. IoT Hubs 4. Devices 5. DPS 6. Environment Variables 7. Quickstart Apps 8. Manage App Data 9. All in one. Get a New: (Group ... Hub in Group ... Device for Hub)
which brings up:
A Z U R E I o T H U B D O A L L using PowerShell AND Azure CLI Enter GroupName HubName DeviceName as CSV string:
- You enter a new GroupName,a new HubName,a new DeviceName
- It will prompt for the location for the Group.
- It will prompt for the Hub SKU
All will be done auto-magically!!!
And what? … There is more?? …
Ps: You can also include a DPS in the csv string if you want one and yet get all of the following if you wish:
 Create New Group <GroupName> in Subscription: <SubscriptionName> then ...  Create New Hub <HubName> with SKU S1 in that Group then ...  Create New Device <DeviceName> for that Hub then ...  Get connection strings and Save to shell scripts etc (ps1,sh,json) then ...  Create a New Device Provisioning Service <DPSName> then ...  Connect the IoT Hub to the DPS. then...  Setup Azsphere, and Verify Tenant with Certificates.
|This Category Links|
|Category:||Pico W AzSDK Index:||Pico W AzSDK|
|Next: >||RPI-Pico-Arduino-AzSDK||IoT Hub Connection Strings|