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

Add interface call listConfigurations() #732

Open reitsma opened 5 years ago

reitsma commented 5 years ago

Perhaps I am missing something, but I cannot find a call in iotagent-node-lib to list all configurations known by an agent. In the Atos LoRa agent I see a workaround to just use iotagent-node-lib/lib/services/groups/groupService, but that should be considered as an internal interface.

The call will be used to setup the proper MQTT subscriptions on startup of the agent for all configurations currently defined. If there is a different way then I really would like hear about it. New configurations can be handled through the addConfigurationProvisionMiddleware callback, so that is ok.

fgalan commented 5 years ago

GET /iot/services should providde al configurations. For instance if I create a new configurationo (aka "service"):

curl -X POST http://localhost:4061/iot/services -H "Fiware-Service: myhome" -H "Fiware-ServicePath: /environment" -H "Content-Type: application/json" -d @- <<EOF
{
    "services": [
        {
            "entity_type": "Device",
            "resource": "/iot/ul",
            "protocol": "HTTP_UL",
            "apikey": "11111111111111111"
        }
    ]
}
EOF

Then I create another:

curl -X POST http://localhost:4061/iot/services -H "Fiware-Service: myhome" -H "Fiware-ServicePath: /environment" -H "Content-Type: application/json" -d @- <<EOF
{
    "services": [
        {
            "entity_type": "Device",
            "resource": "/iot/ul",
            "protocol": "HTTP_UL",
            "apikey": "22222222222222222"
        }
    ]
}
EOF

I can get both using GET /iot/services (note specially the "count": 2 field):

$ curl -s -S http://localhost:4061/iot/services -H "Fiware-Service: myhome" -H "Fiware-ServicePath: /environment" | python -mjson.tool

{
    "count": 2,
    "services": [
        {
            "__v": 0,
            "_id": "5c45e424e3462299aee0fc48",
            "apikey": "11111111111111111",
            "attributes": [],
            "commands": [],
            "entity_type": "Device",
            "internal_attributes": [],
            "lazy": [],
            "resource": "/iot/ul",
            "service": "myhome",
            "static_attributes": [],
            "subservice": "/environment"
        },
        {
            "__v": 0,
            "_id": "5c45e42ee3462299aee0fc49",
            "apikey": "22222222222222222",
            "attributes": [],
            "commands": [],
            "entity_type": "Device",
            "internal_attributes": [],
            "lazy": [],
            "resource": "/iot/ul",
            "service": "myhome",
            "static_attributes": [],
            "subservice": "/environment"
        }
    ]
}

(Test done using IOTA-UL)

Maybe I'm fully understand the report or I'm missing something...