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.Setupapp -> Authentication -> add Web platform and set withhttps://localhostas 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 Directoryand configure Active Directory Authentication. Create a new app with nameEdgeDevice.RequestCertificateand Save - Configure Function settings: connection string to blob and container name
- Add
EdgeDevice.RequestCertificateapp to Access Policy of KeyVault service with Key Permissions = Sign, Secret Permissions = None, Certificate Permissions = Get - Go to DPS service
- Add Certificate
RootCert.cerfrom your machine or from Vault, name itCA. Copy code from portal. - Go to
appsetting.jsonofEdgeDevice.RequestCertificateproject. SetClientIdto Id ofEdgeDevice.RequestCertificateapp from Azure. SetTenantIdof app andBaseUrlto URL of Azure function (https://certauthorityfunction.azurewebsites.net). Run
cd EdgeDevice.RequestCertificate
dotnet run- Set verification code as a device name.
- Upload generated
IssuedCertificate.certo portal and pressVerify - Create enrollment group and specify CA certificate
- Now you can create certificate for any devices. Specify
DeviceNameand run:
cd EdgeDevice.RequestCertificate
dotnet run- Go to appsettings.json of
EdgeDevice.Simulatorproject. SetDeviceName- from previous step. SetDpsIdScopefrom 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.