azureazure-iot-edge

Azure IoT Edge. Module Twin Configuration. Create a target condition based of device twin tags?


The question is quite simple. I am trying to create a target condition for a module twin configuration, where I want to choose my specific modules by using the device tags as a criteria. Azure provides the following example:

enter image description here

Target Condition The target condition is continuously evaluated to include any new modules that meet the requirements or remove modules that no longer do through the lifetime of the configuration. Valid conditions specify either a moduleId (e.g. from devices.modules where moduleId='{id}'), one or more module twin tag criteria (e.g. from devices.modules where tags.environment = 'prod' AND tags.location = 'westus'), or reported property criteria (e.g. from devices.modules where properties.reported.lastStatus='200')

This is referring to module twin tags. However, I would like to filter based on the device twin tags instead. Is it possible?


Solution

  • No, you'll notice when you try it, there's a validation message: An error showing: Target condition must begin with 'FROM devices.modules'.

    Target condition must begin with 'FROM devices.modules'.

    And when you do start it with FROM devices.modules, it automatically scopes the next part of the query to the module twin only. So FROM devices.modules WHERE tags.foo = 'bar' will only return modules that have that tag. Not the device.

    I tested this with a device with a module. The device twin has the correct tag and value and is not returned when running this condition. I added a second device, again with a module but this time with the tag on the module twin. That module is returned when running the condition.