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
58 stars 84 forks source link

[NGSILD] fix ENTITY_GENERIC_ERROR when context broker respond with status code… (201 code) #1617

Closed aquarta closed 1 month ago

aquarta commented 1 month ago

… in update operation

with orion ld 1.5.1 during the transmission of the first measure operation the context broker respond with 201 status code. The log reports

time=2024-05-30T16:55:53.988Z | lvl=DEBUG | corr=01307aed-e06c-4a1f-84b5-2719df05fde3 | trans=01307aed-e06c-4a1f-84b5-2719df05fde3 | op=IoTAgentNGSI.Request | from=n/a | srv=openiot | subsrv=/ | msg=Options: {
    "url": "http://orion:1026/ngsi-ld/v1/entityOperations/upsert/?options=update",
    "method": "POST",
    "headers": {
        "fiware-service": "openiot",
        "fiware-servicepath": "/",
        "Content-Type": "application/ld+json",
        "NGSILD-Tenant": "openiot",
        "NGSILD-Path": "/"
    },
    "json": [
        {
            "@context": "http://context/datamodels.context.jsonld",
            "id": "urn:ngsi-ld:HeightSensor:hsensor31061690_a",
            "type": "HeightSensor",
            "height": {
                "type": "Property",
                "value": 7,
                "observedAt": "2024-05-30T16:55:53.984Z"
            }
        }
    ]
} | comp=IoTAgent
time=2024-05-30T16:55:54.000Z | lvl=DEBUG | corr=01307aed-e06c-4a1f-84b5-2719df05fde3 | trans=01307aed-e06c-4a1f-84b5-2719df05fde3 | op=IoTAgentNGSI.Request | from=n/a | srv=openiot | subsrv=/ | msg=Response [
    "urn:ngsi-ld:HeightSensor:hsensor31061690_a"
] | comp=IoTAgent
time=2024-05-30T16:55:54.000Z | lvl=DEBUG | corr=01307aed-e06c-4a1f-84b5-2719df05fde3 | trans=01307aed-e06c-4a1f-84b5-2719df05fde3 | op=IoTAgentNGSI-LD | from=n/a | srv=openiot | subsrv=/ | msg=Unknown error executing update operation | comp=IoTAgent
time=2024-05-30T16:55:54.001Z | lvl=ERROR | corr=01307aed-e06c-4a1f-84b5-2719df05fde3 | trans=01307aed-e06c-4a1f-84b5-2719df05fde3 | op=IOTAUL.HTTP.Binding | from=n/a | srv=openiot | subsrv=/ | msg=MEASURES-002: Couldn't send the updated values to the Context Broker due to an error: {"name":"ENTITY_GENERIC_ERROR","message":"Error accesing entity data for device: urn:ngsi-ld:HeightSensor:hsensor31061690_a of type: HeightSensor and {\"timestamp\":true,\"defaultResource\":\"/iot/d\",\"explicitAttrs\":true,\"multiCore\":false,\"relaxTemplateValidation\":false,\"defaultEntityNameConjunction\":\":\",\"defaultType\":\"Thing\",\"lazy\":[],\"commands\":[],\"staticAttributes\":[{\"name\":\"category\",\"type\":\"Property\",\"value\":\"sensor\"},{\"name\":\"supportedProtocol\",\"type\":\"Property\",\"value\":\"ul20\"}],\"_id\":\"6658af9976ff3b1fc9d81d1d\",\"creationDate\":\"2024-05-30T16:55:53.973Z\",\"id\":\"hsensor31061690_a\",\"type\":\"HeightSensor\",\"name\":\"urn:ngsi-ld:HeightSensor:hsensor31061690_a\",\"service\":\"openiot\",\"subservice\":\"/\",\"apikey\":\"dummykeyasdasd\",\"__v\":0,\"active\":[{\"object_id\":\"h\",\"name\":\"height\",\"type\":\"Property\"},{\"object_id\":\"b\",\"name\":\"batteryLevel\",\"type\":\"Property\"},{\"object_id\":\"gps\",\"name\":\"location\",\"type\":\"geo:point\"}],\"subscriptions\":[]}","details":["urn:ngsi-ld:HeightSensor:hsensor31061690_a"],"code":201} | comp=IoTAgent

I think this would fix https://github.com/FIWARE/tutorials.IoT-Agent/issues/23

AlvaroVega commented 1 month ago

An update operation in CB could response with a 201 ? is this just for ngsi-ld ?

fgalan commented 1 month ago

Maybe the author of the NGSI-LD contributio (@jason-fox ) could have a look and provide feedback on this.

aquarta commented 1 month ago

And update operation in CB could response with a 201 ?

I think yes, if is the first measure, since in this case the entity is created in context broker

is this just for ngsi-ld ?

I don't know, I've experimented that only for ngsi-ld with orion-ld, I didn't tried other context brokers for that.

jason-fox commented 1 month ago

Yes any 2xx Status codes are legitimate here in NGSI-LD. LGTM 👍

fgalan commented 1 month ago

Yes any 2xx Status codes are legitimate here in NGSI-LD. LGTM 👍

Great!

@aquarta please add a line in the CHANGES_NEXT_RELEASE file briefly describing the fix and this PR will me merged.

aquarta commented 1 month ago

Done