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

Multientity plugin entity_name based on registered device id #913

Open versatildefuy opened 4 years ago

versatildefuy commented 4 years ago

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,

AlvaroVega commented 4 years ago

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.

versatildefuy commented 4 years ago

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:

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

fgalan commented 4 years ago

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?

versatildefuy commented 4 years ago

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.

chicco785 commented 3 years ago

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

fgalan commented 3 years ago

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"?

chicco785 commented 3 years ago

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.

fgalan commented 2 years ago

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.