I have 100+ edge devices with multiple modules, managed by an automatic deployment. Each device has it's own characteristics, like max allowed values. We also have an external module which requires account credentials (id/password/certificate/key) unique for each device.
I tried:
How can I get this this done? Does IoT Edge have a recommended approach / support / workaround for this? Or should we build something our self?
Example of the layered deployment to enable the external module and set the property defaults:
"content": {
"modulesContent": {
"$edgeAgent": {
"properties.desired.modules.externalModule1": {
"settings": {
"image": "123.azurecr.io/externalModule1:0.1.12",
"createOptions": "{\"NetworkingConfig\":{\"EndpointsConfig\":{\"host\":{}}},\"HostConfig\":{\"NetworkMode\":\"host\",\"LogConfig\":{\"Type\":\"json-file\",\"Config\":{\"max-size\":\"10m\",\"max-file\":\"3\"}}}}"
},
"type": "docker",
"status": "running",
"restartPolicy": "always",
"version": "1.0"
}
},
"externalModule1": {
"properties.desired": {
"MaxChargePower": 5000,
"MaxDischargePower": 10000
}
}
}
}
}
Example of the layered deployment to set the device specific values:
{
"content": {
"modulesContent": {
"$edgeAgent": {},
"externalModule1": {
"properties.desired.MaxChargePower": 6000,
"properties.desired.MaxDischargePower": 15000,
"properties.desired.iotpool_account": {
"iotpool_id" : "<insert iotpool id>",
"iotpool_password" : "<insert iotpool password>",
"cert" : "<insert cert>",
"key" : "<insert key>"
}
}
}
}
}
You can modify the module twin directly per-device without having an automatic deployment targeting the device overriding it.
The key is to reference a specific section of the desired properties in the automatic deployment (base or layered). In your example -
"content": {
"modulesContent": {
"$edgeAgent": {
"properties.desired.modules.externalModule1": {
"settings": {
"image": "123.azurecr.io/externalModule1:0.1.12",
"createOptions": "{\"NetworkingConfig\":{\"EndpointsConfig\":{\"host\":{}}},\"HostConfig\":{\"NetworkMode\":\"host\",\"LogConfig\":{\"Type\":\"json-file\",\"Config\":{\"max-size\":\"10m\",\"max-file\":\"3\"}}}}"
},
"type": "docker",
"status": "running",
"restartPolicy": "always",
"version": "1.0"
}
},
"externalModule1": {
"properties.desired": {
"MaxChargePower": 5000,
"MaxDischargePower": 10000
}
}
}
}
}
changes to..
"content": {
"modulesContent": {
"$edgeAgent": {
"properties.desired.modules.externalModule1": {
"settings": {
"image": "123.azurecr.io/externalModule1:0.1.12",
"createOptions": "{\"NetworkingConfig\":{\"EndpointsConfig\":{\"host\":{}}},\"HostConfig\":{\"NetworkMode\":\"host\",\"LogConfig\":{\"Type\":\"json-file\",\"Config\":{\"max-size\":\"10m\",\"max-file\":\"3\"}}}}"
},
"type": "docker",
"status": "running",
"restartPolicy": "always",
"version": "1.0"
}
},
"externalModule1" {
"properties.desired.powerSettings": {
"MaxChargePower": 5000,
"MaxDischargePower": 10000
}
}
}
}
Now you can specialize per-device using the module twin without having it overwritten. You don't need to use nested deployments so you won't run into the number of deployments limit:
"properties.desired.iotpool_account": {
"iotpool_id" : "<insert iotpool id>",
"iotpool_password" : "<insert iotpool password>",
"cert" : "<insert cert>",
"key" : "<insert key>"
}