We had the exact same problem last month. The issue is definitely the missing device twin tags combined with how gateway-mgmt queries devices. Here’s the complete solution:
1. DPS Provisioning Workflow - Fix Initial Twin State:
Update your enrollment group in DPS to include initial twin tags. In the Azure portal, go to your DPS instance → Manage enrollments → your enrollment group → Initial device twin state. Add this configuration:
{
"tags": {
"deviceType": "edgeGateway",
"managementGroup": "production",
"role": "gateway"
},
"properties": {
"desired": {
"gatewayManagementEnabled": true
}
}
}
2. IoT Hub Device Registry Sync - Manual Fix for Existing Devices:
For devices already provisioned without tags, update them manually using Azure CLI:
az iot hub device-twin update --device-id edge-gateway-03 \
--hub-name prod-iothub-west \
--tags '{"deviceType":"edgeGateway","role":"gateway"}'
3. Edge Runtime Health - Verify Module Communication:
SSH into your edge device and check that edgeAgent is reporting correctly:
sudo iotedge list
sudo iotedge logs edgeAgent --tail 50
Look for successful twin sync messages. The edgeAgent must be actively reporting module status for gateway-mgmt to recognize the device as healthy.
4. Gateway-mgmt Permissions - Verify Service Principal:
Confirm the gateway-mgmt service principal has these RBAC roles at the IoT Hub scope:
- IoT Hub Registry Contributor
- IoT Hub Twin Contributor
- IoT Hub Data Contributor (for telemetry access)
5. IoT Hub Event Routing - Critical for Real-time Updates:
Gateway-mgmt requires device lifecycle events. In your IoT Hub, configure a message route:
- Route name: DeviceLifecycleToGatewayMgmt
- Data source: Device Lifecycle Events
- Routing query: `opType = ‘createDeviceIdentity’ OR opType = ‘updateTwin’
- Endpoint: Your gateway-mgmt Event Hub or Service Bus endpoint
6. Force Refresh in Gateway Management:
After applying twin tags, the gateway-mgmt cache might need a refresh. Restart the gateway-mgmt pod/service or trigger a manual device discovery scan if your platform supports it.
The root cause is that gateway-mgmt filters devices using twin tag queries like SELECT * FROM devices WHERE tags.deviceType = 'edgeGateway'. Without these tags set during DPS provisioning, devices are invisible to the management layer even though they exist in IoT Hub. The initial twin state in your enrollment group ensures all future devices get the required tags automatically. For the 20-30 devices we had already provisioned, we wrote a script using the Azure SDK to bulk-update their twins with the missing tags, and they appeared in gateway-mgmt within 2-3 minutes.