This is a sample showing an Azure IoT Edge deployment for Windows IoT Core with a .NET Core C# console app to demonstrate PWM control of a DC motor. Additionally, it can do this in a way that can coordinate with the Fruit WinML sample.
The pwm sample expects to be run on a board that is connected to a pwm motor circuit. When it receives a D2C Fruit Message or DirectMethod call it maps the fruit to a motor speed and runs the motor at that speed. the mapping is Grapes - 100%, apple, pear - 50%, pen - 0%.
- The deployment.json file demonstrates container creation options for exposing PWM controllers into the container.
- Azure subscription with the following resources:
- IoT Hub
- Storage
- Container Registry
- Function App with the [EventHubHandler Example] (....\EventHubHandler\Readme.md) installed if you wish to exercise the device state mirroring.
- Hardware:
- An x64 Board with Windows 10 IoT Core version 1809 (Build 17763) installed and PWM driver support.
- A PWM peripheral and support circuit. What was used for developing this sample is a simple DC motor with fan from an Arduino starter kit. There are many tutorial examples using an L293D motor controller chip that can be found on the internet. And, there are several other alternatives using different motor control circuits.
- Required packages to install
- Windows 10 SDK, version 1809
- .NET Core 2.2
- Azure IoT Hub Device SDK
- Either Visual Studio, VSCode, or the .NET Core dotnet.exe build environment
- cd to the directory container the .csproj
- dotnet publish
- Load the solution
- Right click on the cs project and select publish.
Unfortunately, this can't be done from a developer desktop since the IoT Core container cannot run on desktop. Instead it must be done on real hardware. After you have published your app do the following steps:
- Obtain an x64 machine with IoT Core installed.
- ssh into a command prompt on the machine.
- Install Docker on the IoT Core machine
- Download x64 docker.exe
- And x64 dockerd.exe
- Copy them to the IoT Core machine and put docker.exe in the path.
- from a command prompt run 'dockerd.exe --register-service'
- sc.exe start docker
- Copy your app to the machine
- Choose properties\dockerfile.dotnet or dockerfile.standalone depending on which kind of project you've built and copy that docker file to the machine
- Do 'docker login' with creds to your container registry.
- Do 'docker build -f < path to dockerfile> -t <registry/repo:tag> .' to build the image.
- docker push <registry/repo:tag>
The "preview" creds in the deployment.json are public read-only creds to the standard edge runtime modules. But, for the sample you must update the creds in the deployment.json file to provide access to your module container repository where you've stored the module you just built. And, you must update the image url in the module section with the correct url for your module image.
There are multiple ways to deploy the module:
The recommended way to get started is VSCode with the Azure IoT Edge extension. But, for larger scale production deployments scripting with CLI is likely preferable.