.NET Core on IoT: Using the az-iothub-ps script
February 28, 2020 17:13
David Jones MVP
iot
powershell
dotnetcore
iothub
azure
iot-core
raspbian
28 Feb 2020 17:13:20
David Jones MVP
iot powershell dotnetcore iothub azure iot-core raspbian
iot powershell dotnetcore iothub azure iot-core raspbian
Just the steps to use the script. No background info._
What you need
- An Azure account
- Az CLI installed
- VS Code installed (optional)
- PowerShell enabled (Typically is in Windows)
- See Turn Windows features on or off in the Programs and Features (Control Panel)
- Nb There is also PowerShell Core that runs on more than Windows now.
PowerShell Core Windows installation
See the side menu there for other platforms.
Getting started
- Get the az-iothub-ps repository
- https://github.com/djaus2/az-iothub-ps
- Here’s what you need to clone it:
https://github.com/djaus2/az-iothub-ps.git
- Or just get the zip file here
- Download or clone it into a folder on your desktop
- Set path to the script and run the script
-In the PS folder run
.\set-path
- run
get-iothub
- run
You get a Splash Screen, press any key to go the main menu.
Setting up an Azure IoT and getting the connection strings
- Subscription
- Select the subcription to use. Usually only one.
- Group
- Create a new Resource Group or select an existing one from the subscription.
- Give a unique group name
- Set the location by enter the number of the location
- Hub
- Give it a unique hub name
- Create a new IOT Hub or select an existing one from the Group.
- If no other hubs in the group, for a new one, select SKU F1 (Free)
- Otherwise select S1 (Standard 1)
- Device
- Give it a unique Device name
- Create a new Device for the hub, or select an existing one
- Environment Variables
- Select option 2. Generate Enviroment Variables
- Save to file (PowerShell and/or Bash)
- Put a copy in the script root, Quickstarts and elsewhere as required.
- You can now reload them when you need
- Run Quickstart Apps
- If running on the desktop, assuming .NET Core is ready to go .._
- To run both the device and server on the desktop simultaneoously select option1
And choose the Quickstart pair of apps you want to run- When you exit the script, just run .\run-apps in PowerShell
- Two consoles will fire up, one for each app.
- When you exit the script, just run .\run-apps in PowerShell
- To run just one of the apps, choose option 2
Then select the Quickstart and then the specific app.- In that folder run
dotnet run
- In that folder run
Note that the hub connection info is extracted from the environment variables.
- If deploying to run on a device that doesn’t have .NET Core installed
- Download the specific IoT Hub SDK (os-cpu). And extract
- Eg win-arm or linux-arm for the RPi
- The .NET Core will be in ps\qs-apps\dotnet whereas Quickstarts are in ps\qs-apps\quickstarts
- In 5. Environment Variables, make sure you have saved them to Quickstarts folder
- Copy the qs-apps folder to the target
- In quickstarts folder on the device run set-env:
- .\setenv for PowerShell
- Need to run
source ./set-env.sh
in Bash but on the RPi …- There is a fix required for this wrt DOS line endings:
- Run
tr -d '\r' < set-env.sh > set-env2.sh
- Run
source ./set-envl.sh
instead.
- Navigate to a device app folder and run the app. Enter:
dotnet run
- Download the specific IoT Hub SDK (os-cpu). And extract
Topic | Subtopic | |
This Category Links | ||
Category: | IoT Index: | IoT |
Next: > | .NET Core on IoT | You can now fully automate Group-Hub-Device creation |
< Prev: | .NET Core on IoT | Remote Publishing to the RPI |