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

Autoprovison only works with the defined defaultResource #1524

Open fbuedding opened 10 months ago

fbuedding commented 10 months ago

IoT Agent Node Lib version the issue has been seen with

3.3.0

Bound or port used (API interaction)

Other

NGSI version

NGSIv2

Are you running a container?

Yes, I am using a contaner (Docker, Kubernetes...)

Image type

normal

Expected behaviour you didn't see

When a Service Group is provisioned with an api-key, resource other than the defaultResource and autoprovision is set to true documented here, then no device will be autoprovsioned upon receiving measurements. In my understanding the documentation let it sound like it should autoprovision a Device with the corresponding resource.

Bonus: when posting via http it also uses the default entity_type and not the one defined in the service group

Unexpected behaviour you saw

It did not autoprovision a device, it said it could not find one

Steps to reproduce the problem

# Create Service Group
curl --location 'http://localhost:4061/iot/services' \
--header 'fiware-service: openiot' \
--header 'fiware-servicepath: /' \
--header 'Content-Type: application/json' \
--data '{
 "services": [
   {
     "apikey":      "8b661f3b-6335-40d4-86ee-4d9119fe26e5",
     "cbroker":     "http://orion:1026",
     "entity_type": "House",
     "resource":    "/iot/house",
     "autoprovision":"true"
   }
 ]
}'

# Send mqtt to /ul/8b661f3b-6335-40d4-86ee-4d9119fe26e5/1/attrs
ad|123

Configs

environment:
        - "IOTA_CB_HOST=orion"
        - "IOTA_CB_PORT=1026"
        - "IOTA_NORTH_PORT=4061"
        - "IOTA_REGISTRY_TYPE=mongodb"
        - "IOTA_MONGO_HOST=mongodb"
        - "IOTA_MONGO_PORT=27017"
        - "IOTA_MONGO_DB=iotagent-ul"
        - "IOTA_PROVIDER_URL=http://iot-agent:4061"
        - "IOTA_AUTOCAST=true"
        - "IOTA_MQTT_HOST=mosquitto"
        - "IOTA_MQTT_PORT=1883"

Log output

{"name":"DEVICE_GROUP_NOT_FOUND","message":"Couldn\t find device group for fields: [\"resource\",\"apikey\"] and values: {\"resource\":\"/iot/house\",\"apikey\":\"8b661f3b-6335-40d4-86ee-4d9119fe26e5\"}
vivekNEC commented 5 months ago

Hi @fbuedding, @fgalan I would like to contribute on this issue.

mapedraza commented 5 months ago

Great to hear this @vivekNEC. I can assign you this issue. @fbuedding documented pretty well this issue, but, if you have any further question, feel free to post here.

Consider to check:

fgalan commented 2 months ago

When this issue gets addressed, have a look to doc/api.md file, look for FIXME mark and remove the 2 ones regarding #1524 (introduced in PR https://github.com/telefonicaid/iotagent-node-lib/pull/1551)