az-iothub-ps: Device Provisioning Service scripts added
iot powershell iothub azure
The az-iothub-ps suite of PowerShell scripts for creating all of the elements of an Azure IoT Hub scenario as well as automatically querying for connection metadata for IoT device apps, now supports generating a DPS for a Resource Group, as well as connecting a hub in the group to it.
It’s the Swiss Army Knife for Azure IoT Hub!
About az_iothub_ps
az_iothub_ps consists of a suite of PowerShell scripts for listing, selecting, creating and deleting an Azure Resource Group, IoT Hub and Device. It is orchestrated by the main script get-iothub that actions these activities as a hierarchy of menus. The scripts can query Azure, using Azure Cli, for the hub connectivity meta-data which can then be presented as environment variables, as a script to regenerate them, and now as a launchsetting.json file (see below). These variables can then be injested into an IoT device or serviec app.
The suite also contains the Azure IOT Hub SDK .Net Core C# Quickstart device and server apps. These have been modified to get the hub connection meta-data from the environment varaiables. The enviroment variables scripts can be appropriately located for use by these apps when saved. Also, the functionality of the quickstarts have been extended to include interaction by device apps with real hardware.
Update of az_iothub_ps
Having selected a Resource Group you can now add a new Device Provisioning Service requiring only its name. You can then select and link an IoT Hub to it (and disconnect). The menu driven PowerShell script can also get the DPS connectivity SubscriptionID and ID Scope. As connectivity between IoT Devices and Hubs gravitates towards Hub connectivity via DPS as per Azure Sphere and Azure IoT Central, this is a useful extension. The script currently does not handle the device connectivity to DPS; 2Do.
NB: Once a device is configured to connect to an IoT Hub using DPS, when coding to use this you need 3 things:
- The ID Scope
- Get it now using az_iothub_ps
- The IoT Hub DPS name:
hubname
becomes
hubname.azure-devices.net
`
- The tenant
- With Azure Sphere you run
azsphere tenant list
from the Azure Sphere CLI command line
- With Azure Sphere you run
{
"SchemaVersion": 1,
"Name": "SphereBME280",
"ComponentId": "82a16cf9-d4e1-4235-a6e5-14ed23c4cc18",
"EntryPoint": "/bin/app",
"CmdArgs": [ "--- [1] YOUR IOT CENTRAL DPS SCOPE ID ---" ],
"Capabilities": {
"AllowedConnections": [ "global.azure-devices-provisioning.net", "--- [2] YOUR IOT CENTRAL IOTHUB DNS NAME ---" ],
"AllowedTcpServerPorts": [],
"AllowedUdpServerPorts": [],
"Gpio": [
...
],
...
"DeviceAuthentication": "--- [3] YOUR AZURE SPHERE TENANT ID--- "
}
}
app_manifest.json DPS connectivity in the app
So what do you currently get from this?
- Menu driven creation of an Az DPS
- Menu driven configuration of the connection of an Az IoT Hub to the DPS
- Note: Does not handle the configurration of certificate driven hub connectivity as required by Az Sphere
- A list of IOT Hubs hosted by a DPS
- Including hubs configured using a certificate.
- The ID Scope required for device connectivity via DPS to the hub
Nb: There was an option to run the main script get-iothub from a command line to generate the group,hub and device. This is being extended to add the DPS option.
Nb2: There is also a new feature Write Env Vars To launchSettings.Json in 6. Environment Variables. This can generate the launchSettings.Json file that then can placed in a .NET Core app so as to read the values at startup from there.
Links
The Main Menu
A Z U R E I o T H U B S E T U P using PowerShell AND Azure CLI
Subscription :"Visual Studio Ultimate with MSDN"
Group :"StreamMeUp"
Hub :"StreamsAway"
Device :"StreamedDevice"
DPS :"DPStreamMe"
1. Subscription
2. Groups
3. IoT Hubs
4. Devices
5. DPS <-- Current Selection
6. Environment Variables
7. Quickstart Apps
8. Manage App Data
9. All in one. Get a New: (Group ... Hub in Group ... Device for Hub)
0. Done
R. Reset script globals
X. Exit
Select action (number). (Default is highlighted) X To exit
The DPS Menu
A Z U R E I o T H U B D E V I C E P R O V I S I O N I N G S E R V I C E (DPS) using PowerShell AND Azure CLI
Subscription :"Visual Studio Ultimate with MSDN"
Current Group :"StreamMeUp"
Current Hub :"StreamsAway"
Current Device :"StreamedDevice"
Current DPS :"DPStreamMe"
Using Short Menu
Select a D P S or option
No. of entities: 1
1. DPStreamMe <-- Current Selection
N. New
R. Refresh
S. Show
U. Unselect
D. Delete
G. Generate Env Vars for Hub Connection
C. Connect Current Hub to DPS
Z. Disconnect Current Hub from DPS
B. Back
Please make a (single digit) selection .. Or just [Enter] if required selection is highlighted BELOW
Show selected.
Show
DPStreamMe (Wait):
Location Name Resourcegroup Subscriptionid
------------------ ---------- --------------- ------------------------------------
australiasoutheast DPStreamMe StreamMeUp 81514943-cccc-4444-9999-efaa554fbab5
Connected Hubs (Wait):
qqqqqq.azure-devices.net
Press any key to return..
Topic | Subtopic | |
Next: > | Azure Sphere Projects | BME280 Sensor |
< Prev: | Azure Sphere | Trying out some of the Samples |
This Category Links | ||
Category: | IoT Index: | IoT |
Next: > | Blazor-IoT | Azure IoT Hub Interaction using Blazor on a RPi - Intro |
< Prev: | .Net Core on IoT | Some Deployment key points |