This repository contains all required scripts and source code to deploy iot hub sample infrastructure
Before moving to infrustructure deployment and run of sample application please make sure that following conditions were met:
- Installed Azure CLI: https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest
- Installed all necessary extensions for Azure CLI. To do this just run script below:
az extension add --name azure-cli-iot-extps1
npm install -g azure-functions-core-tools
- Login into Azure Account:
az login
- Create resources
.\deploy_resources.ps1
- Create a new Application in Azure Active Directory with name
RootCertificate.Setup
- Open
RootCertificate.Setup
app -> Authentication -> add Web platform and set withhttps://localhost
as a Redirect URI. Default client type set toYes
- Add thie app to Access Policy of KeyVault service
- Generate Root certificate on your machine and store it to KeyVault
cd RootCertificate.Setup
dotnet run
- Deoloy Azure Function.
- Got to Platform features of function -> Identity -> set Status to
On
- Open Authentication / Authorization of function and set App Service Authentication to
On
. ChooseLog in with Azure Active Directory
and configure Active Directory Authentication. Create a new app with nameEdgeDevice.RequestCertificate
and Save - Configure Function settings: connection string to blob and container name
- Add
EdgeDevice.RequestCertificate
app to Access Policy of KeyVault service with Key Permissions = Sign, Secret Permissions = None, Certificate Permissions = Get - Go to DPS service
- Add Certificate
RootCert.cer
from your machine or from Vault, name itCA
. Copy code from portal. - Go to
appsetting.json
ofEdgeDevice.RequestCertificate
project. SetClientId
to Id ofEdgeDevice.RequestCertificate
app from Azure. SetTenantId
of app andBaseUrl
to URL of Azure function (https://certauthorityfunction.azurewebsites.net). Run
cd EdgeDevice.RequestCertificate
dotnet run
- Set verification code as a device name.
- Upload generated
IssuedCertificate.cer
to portal and pressVerify
- Create enrollment group and specify CA certificate
- Now you can create certificate for any devices. Specify
DeviceName
and run:
cd EdgeDevice.RequestCertificate
dotnet run
- Go to appsettings.json of
EdgeDevice.Simulator
project. SetDeviceName
- from previous step. SetDpsIdScope
from DPS service. Run simulator:
cd EdgeDevice.Simulator
dotnet run
- Run WebApi service to send command to device
cd Evelator.Api
dotnet run
- Send request
curl -X POST -k https://localhost:5001/Elevator -H "Content-Type: application/json" -d "{ \"deviceName\": \"elevator1\", \"floor\": 17 }"
Create custom consumers to store events from IoT hub to database
- Create custom routes https://docs.microsoft.com/en-us/azure/iot-hub/tutorial-routing
- Subscribe for IoT Events in portal.