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 86 forks source link

Static attributes from service not applied if device has static attributes #757

Closed manucarrace closed 4 years ago

manucarrace commented 5 years ago

If a Service (device group) is provisioned with static_attributes and then a device is provisioned also with static_attributes (different attributes), when a measure is sent to the apikey-device_id, only static_attributes from device are applied.

If device is provisioned without static_attibutes, static_attributes from service are applied.

fgalan commented 5 years ago

What should be expected behaviour? To provide the union set of both (config level and device level) static attributs (givin priority to the ones in device level if some attribute is in both sets)?

manucarrace commented 5 years ago

Right. This is the expected behaviour

Madhu-NEC commented 4 years ago

Hi @fgalan, @manucarrace As per my investigation, the entity created at Orion contains the static attributes defined at service level but the same does not stored at IOT database i.e. when we execute GET /iot/devices API, the same attribute is not displayed.

Service creation request: Created a service group using below as body of the request. Attribute bootstrapServer is provisioned as static attribute.

{
  "services": [
    {
      "resource": "/device",
      "apikey": "abcd",
      "entity_type": "StreetlightControlCabinet",
      "trust": "8970A9078A803H3BL98PINEQRW8342HBAMS",
      "cbHost": "http://<orion>:1026",
      "commands": [
        {
          "name": "wheel1",
          "type": "Wheel"
        }
      ],
      "lazy": [
        {
          "name": "luminescence",
          "type": "Lumens"
        }
      ],
      "attributes": [
        {
          "name": "status",
          "type": "Boolean"
        }
      ],
      "static_attributes": [
        {
          "name": "bootstrapServer",
          "type": "Address",
          "value": "127.0.0.1"
        }
      ]
    }
  ]
}

Device creation request: Created a device using below as body of the request. No static attributes are given at device level.

{
  "devices": [
    {
      "device_id": "Light1",
      "protocol": "GENERIC_PROTO",
      "entity_name": "TheFirstLight1",
      "entity_type": "StreetlightControlCabinet",
      "attributes": [{
        "name": "temp",
        "type": "Number"
      }]
    }
  ]
}

Output of Device GET request: No static attribute is displayed when we request GET /iot/devices.

{
    "count": 1,
    "devices": [
        {
            "device_id": "Light1",
            "service": "ultest",
            "service_path": "/",
            "entity_name": "TheFirstLight1",
            "entity_type": "StreetlightControlCabinet",
            "transport": "HTTP",
            "attributes": [
                {
                    "object_id": "temp",
                    "name": "temp",
                    "type": "Number"
                }
            ],
            "lazy": [],
            "commands": [],
            "static_attributes": [],
            "protocol": "GENERIC_PROTO",
            "explicitAttrs": false
        }
    ]
}

Entity created at Orion: As displayed in below screenshot, attribute bootstrapServer is created for the entity at Orion. orion_entity_v2

So, as per my understanding, the only need is to implement the code which will store the attribute bootstrapServer at IOT database so that same will be displayed for GET /iot/devices API. Please confirm my understanding.

fgalan commented 4 years ago

Fixed by PR https://github.com/telefonicaid/iotagent-node-lib/pull/908

fgalan commented 4 years ago

Not sure if PR #908 fully solves this or is anything else pending... to be reviewed.

Madhu-NEC commented 4 years ago

Hi @fgalan,

As per my understanding, PR #908 addresses this bug. I request you to please let me know if anything is still pending?

Thanks!

Madhu-NEC commented 4 years ago

Hi @fgalan ,

Is there any update on this issue?

Thanks!

fgalan commented 4 years ago

Original issue says:

If a Service (device group) is provisioned with static_attributes and then a device is provisioned also with static_attributes (different attributes), when a measure is sent to the apikey-device_id, only static_attributes from device are applied.

If device is provisioned without static_attibutes, static_attributes from service are applied.

Looking to the test added in #908 (just the descritpion, assuming the tests are correctly implemented) we have the following cases:

  1. When a device provisioning request without static attributes arrives to the IoTA and static attribute is configured at group level
    • should store the device with static attributes provided in configuration
  2. When a device provisioning request with static attributes arrives to the IoTA and static attribute is not configured at group level
    • should store the device with static attributes provided in device
  3. When a device provisioning request with static attributes arrives to the IoTA and static attribute is also configured at group level
    • should store the device with static attributes provided in configuration as well as device
  4. When a device provisioning request with static attributes arrives to the IoTA and same static attribute is also configured at group level
    • should store the device with static attributes provided in device

So, I understand they cover correctly the way of working so, after this analysis I think the issue is covered so I'll close it.

Of course, if somebody has a different opinion and think something is pending, tell so and I can re-open the issue.