.NET Core on IoT: Using the PS Script to run Quickstarts on RPi (IoT-Core)
iot powershell dotnetcore iothub azure iot-core devicestreaming telemetry
The previous few posts introduced the one stop shop, the az-iothub-ps PowerShell script for setting up an Azure IoT Hub and for orchestrating the running of the Azure IOT Hub SDK Quickstart ,NET Core apps on a desktop. The prior posts in this series covered setting up .NET Core to run on a RPi. This post covers using the script in a PowerShell terminal running on a RPi running Windows 10 IoT-Core. A later post will cover the same scenario but when running Raspbian on the RPi.
The script in creating an Azure IoT Hub and querying it for relevant connection strings depends upon the installation of Azure CLI being available in the PowerShell shell. The Windows installation is a .msiex installation which isn’t available on Windows 10 IoT-Core. Whilst it was possible to install.NET Core as a “copy and paste” installation (see previous post .. coming) this isn’t poosible on IoT-Core. …More on this later,
The second gotcha is that whilst it is easy to remotely connect to an IoT-Core device using a PowerShell window, I use the IoT Core Dashboard, the script makes much use of
[System.Console]::ReadKey. This causes errors when run in a remote shell. The script was adjusted so that as an option to use
read-host` which means that for single key menu responses the choice is not activated upon the keypress but requires [Enter] to be pressed afterwards. …More on this later.
Nb Don’t use the script in PowerShell ISE as read-host doesn’t work there.
Using the script in the remote PowerShell shell
Whilst it can’t be used in this contect to create a hub and query for connection strings it can be used to:
- Run set-env.ps1 to set predetermined connection string as environemnet variables
- Configure .NET Core
- Navigate to a Quickstart folder ready to run the apps there.
In what follows the RPi is running an updated version of Windows 10 IoT-Core. It is assumed that .NET Core is NOT installed there.
- Setup the script, as previous, on the desktop
- Use it there to create a Hub and Device and create the script, set-env.ps1, for them
- Get and save the enviroment varaiables. Save the app settings as well.
- Get the required version of .NET Core in place for the RPi
- Create a share on the RPi and copy the script folder to there
- Make the folder on the desktop a share and connect to it from the RPi
- Use an FTP app, such FileZilla to copy (and if needed later to update) the script folder to the RPi
- Create text file IsRemote.txt is the root of the drive that has the folder (i.e. c:\IsEmbedded.txt)
- When the script runs, it checks for this and runs in the remote mode as per the second gotcha.
- Change directory to the PS folder and run
- Run the script
- The app settings and environment vaiable will be automatically loaded.
- .NET Core will be enable by set-path
You are now good to run the Quickstarts as on the desktop.
Nb: If you want to edit the sourec of an app. do it on the desktop. No synching required unless you are using ftp.
|This Category Links|
|Next: >||.NET Core on IoT||Using the PS Script to run Quickstarts on RPi (IoT-Core) - Simpler|
|< Prev:||.NET Core on IoT||Az-IoTHub-PS ... The IoT Hub Quickstart Apps|