telefonicaid / iotagent-node-lib

Module to enable IoT Agent developers to build custom agents for their devices that can easily connect to NGSI Context Brokers
https://iotagent-node-lib.rtfd.io/
GNU Affero General Public License v3.0
60 stars 85 forks source link

Multientity plugin with more than two entities does not work #877

Closed manucarrace closed 4 years ago

manucarrace commented 4 years ago

A device with the following data:

{
  "devices": [
    {
      "protocol": "IoTA-UL",
      "entity_name": "contador12",
      "entity_type": "multientity",
      "attributes": [
        {
          "expression": "${@cont1}",
          "name": "vol",
          "type": "string",
          "entity_name": "WaterMeter01",
          "entity_type": "WaterMeter"
        },
        {
          "expression": "${@cont1}",
          "name": "vol",
          "type": "string",
          "entity_name": "WaterMeter02",
          "entity_type": "WaterMeter"
        },
        {
          "expression": "${@cont1}",
          "name": "vol",
          "type": "string",
          "entity_name": "WaterMeter03",
          "entity_type": "WaterMeter"
        },
        {
          "expression": "${@cont1}",
          "name": "vol",
          "type": "string",
          "entity_name": "WaterMeter04",
          "entity_type": "WaterMeter"
        }        
      ],
      "device_id": "test99"
    }
  ]
}

When a measure is sent to the iotagent, only the first two entities are properly updated. The rest of entities are not updated with the value of the attribute.

Device was provisioned with:

curl -i --location --request POST 'http://localhost:18082/iot/devices' \
--header 'Content-Type: application/json' \
--header 'fiware-service: smartcity' \
--header 'fiware-servicepath: /' \
-d '{
"devices": [
{
"protocol": "IoTA-UL",
"entity_name": "contador14",
"entity_type": "multientity",
"attributes": [
{
"expression": "${@cont1}",
"name": "vol",
"type": "string",
"entity_name": "WaterMeter01",
"entity_type": "WaterMeter"
},
{
"expression": "${@cont1}",
"name": "vol",
"type": "string",
"entity_name": "WaterMeter02",
"entity_type": "WaterMeter"
},
{
"expression": "${@cont1}",
"name": "vol",
"type": "string",
"entity_name": "WaterMeter03",
"entity_type": "WaterMeter"
},
{
"expression": "${@cont1}",
"name": "vol",
"type": "string",
"entity_name": "WaterMeter04",
"entity_type": "WaterMeter"
}
],
"device_id": "contador14"
}
]
}'

If we change the name of the attribute "vol" by a specific name for each entity (lets say vol1, vol2, vol3 and vol4) it works.

AlvaroVega commented 4 years ago

It worked to me with a device provisioned like: Screenshot from 2020-07-02 12-57-17 just with different object_id per attribute an then sending measure:

mosquitto_pub -h localhost -t /json/mhbgcrkex4j4rif2rlq3uo5ut/contador12/attrs -m '{"cont1": 34}' -u iota -P 'XXXX'

Screenshot from 2020-07-02 12-55-51

AlvaroVega commented 4 years ago

It seems that multientity plugins is not working well when attributes object_id is the same, since that plugin relies sometimes in that value https://github.com/telefonicaid/iotagent-node-lib/blob/master/lib/plugins/multiEntity.js#L176

fgalan commented 4 years ago

Once PR https://github.com/telefonicaid/iotagent-node-lib/pull/878 has been merged, can this issue be closed?