Geographically Provisioning IoT Devices on Azure
The goal of this repository is to explain how you can implement IoT device geo-provisioning with Azure IoT Hub, Device Provisioning Service (DPS), Functions and Maps. Using these Azure services, you will learn how to control an IoT device’s provisioning based on their location.
The corresponding Tech Community blog that fully explains this architecture can be found here.
Getting Started
Prerequisites
- Create an Azure IoT Hub
- Create an Azure IoT Hub Device Provisioning Service (DPS)
- Ensure the IoT Hub from step 1 has been linked to this DPS
- Create an Azure Function App
- Ensure the Runtime Stack and Version settings have been set to .NET and 6
- Create an Azure Maps account
- Install the .NET 6.0 SDK on your local machine
Demo
To run the demo, follow these steps:
- Obtain your Azure Maps account's Primary Key
- You can find the value of this key in the Azure Portal under the Authentication blade of your Azure Maps account or by using the Azure CLI script below:
az maps account keys list -n "mapsAccountName" -g "resourceGroupName" -o tsv --query primaryKey
- You can find the value of this key in the Azure Portal under the Authentication blade of your Azure Maps account or by using the Azure CLI script below:
- Update the subscriptionKey variable's value in the run.csx file, under the Azure Function Code folder, with the Primary Key value from step 1.
- From the Azure portal, create an HTTP Trigger function in your Azure Function App.
- Replace the HTTP Trigger function's default code with the code in the run.csx file.
- Create an Individual Enrollment with a Custom Allocation Policy that uses your Azure Function App and the HTTP Trigger function from step 4.
- Run the below commands locally, from within the root folder of this project:
cd GeoProvisioningSample dotnet build dotnet run -- --DpsIdScope "replaceMeWithDPSScopeID" --DeviceId "replaceMeWithEnrollmentRegistrationId" --DeviceSymmetricKey "replaceMeWithEnrollmentPrimaryKey" --IPAddress "replaceMeWithEitherAPublicIPv4ORIPv6Address"
- For now, this demo is configured to only allow provisioning devices with a public IPv4 or IPv6 address from the United States (US).