iotagent-node-lib icon indicating copy to clipboard operation
iotagent-node-lib copied to clipboard

Multientity plugin entity_name based on registered device id

Open versatildefuy opened this issue 3 years ago • 8 comments

Hello guys,

I was making use of the multi-entity plugin for the first time with the lwm2m iotagent. My goal was to create a DeviceConfig entity with lazy attributes and another Device entity with active attributes. The problem I found is that the name of the entity in the multi-entity plugin must always be explicitly added to the resource. E.g.

{
    "name": "Longitude",
    "type": "Number",
    "entity_name": "idas-03-service:Other",
    "entity_type": "Other"
}

In this case, you can see how for a resource a specific type and entity name is added. What I would like to know is if there is a way to change the entity name dynamically depending on the id of the registered device. Something like that:

{
    "name": "Longitude",
    "type": "Number",
    "entity_name": "${@id}:Other",
    "entity_type": "Other"
}

This way you could make use of the multi-entity plugin by using static provisioning (config.js file) or service provisioning.

Perhaps it is possible to solve this problem in another way. Any advice? Thank you very much for your time and efforts, Greetings,

versatildefuy avatar Sep 18 '20 10:09 versatildefuy

It seems that multi entity plugin is not loaded by lwm2m iotagent (https://github.com/telefonicaid/lightweightm2m-iotagent/blob/master/lib/iotAgentLwm2m.js#L48), like other iotagent does (i.e. iotagent-ul https://github.com/telefonicaid/iotagent-ul/blob/8f5e3000694ada39067777881d726b4b9789061a/lib/iotagent-ul.js#L175). Maybe this issue should be moved into lwm2m agent.

AlvaroVega avatar Sep 21 '20 15:09 AlvaroVega

Thank you for your response @AlvaroVega.

You are right, the plugin is not loaded by default and cannot be loaded by configuration. I will open the issue you suggested.

In my case, I'm loading the plugin manually, adding it to the iotAgentLwm2m.js file, and it works.

The problem is how to provide a per-service configuration (Service API) where when a device, for which you don't know its identifier before connecting, connects to the iotagent, the iotagent can provide multi-entity based on that identifier.

For example, for this configuration:

{
    "services": [
        {
            "resource": "/device",
            "apikey": "",
            "type": "Device",
            "commands": [],
            "lazy": [],
            "attributes": [
                {
                    "name": "Longitude",
                    "type": "Number"
                },
                {
                    "name": "Latitude",
                    "type": "Number",
                    "entity_name": "${@id}:Other",
                    "entity_type": "Other"
                }
            ]
        }
    ]
}

When a device with "Device-test" identifier is connected, two entities should be created in Orion:

  • Device-test:Device with Device type and a single Longitude attribute
{
  "id": "Device-test:Device"
  "type": "Device"
  "Longitude": -1
}
  • Device-test:Other with type Other and a single Latitude attribute
{
  "id": "Device-test:Other"
  "type": "Other"
  "Latitude": 1
}

I could not find examples to achieve this multi-entity based on the device identifier. Is this possible at present?

Thank you very much in advance

versatildefuy avatar Sep 22 '20 06:09 versatildefuy

It seems that an specific issue was created in IOTA-LW2M repository (https://github.com/telefonicaid/lightweightm2m-iotagent/issues/231). Thus, maybe this one can be closed? Or is there anything pending with regards to iotagent-node-lib?

fgalan avatar Sep 24 '20 11:09 fgalan

No, this issue is a question about the functionality of the multitentity plugin regardless of the iota used, and the other issue is related to the iota lwm2m and the possibility of adding the plugins in the code by default.

versatildefuy avatar Sep 28 '20 10:09 versatildefuy

@fgalan @AlvaroVega I think the question by @versatildefuy is about the possibility to use "expressions" in the in the generation of entity_name

chicco785 avatar Nov 19 '20 15:11 chicco785

No, this issue [issue A] is a question about the functionality of the multitentity plugin regardless of the iota used, and the other issue [issube B] is related to the iota lwm2m and the possibility of adding the plugins in the code by default.

I'm a bit lost :) Which issue corresponds to "issue A" and which one corresponds to "issue B"?

fgalan avatar Jan 25 '21 12:01 fgalan

in my understanding

issue a. is about having "expressions" in the in the generation of entity_name which hopefully is solved by the PR that was completed.

issue b. lwm2m, by default, is not loading the needed plugin.

chicco785 avatar Jan 25 '21 12:01 chicco785

With regards to issue A there had been HUGE advances in JEXL expression support in recent versions. I'd recommend to have a look to the newest version (2.24.0 by the time being). Under my understanding in this version JEXL expressions can be used in entity_name.

With regards to issue B, maybe it should be moved to lwm2m repository.

fgalan avatar Sep 14 '22 12:09 fgalan