telefonicaid / iotagent-json

IoT Agent for a JSON based protocol (with HTTP, MQTT and AMQP transports)
https://fiware-iotagent-json.rtfd.io/
GNU Affero General Public License v3.0
51 stars 88 forks source link

Error With Context Broker LD #523

Closed massimolauri closed 3 years ago

massimolauri commented 3 years ago

Debug log:

Iot Agent Json:

Request to Iot Agent Json `time=2021-01-07T10:52:32.046Z | lvl=DEBUG | corr=dff99780-3298-4772-93a6-58e7e3335f35 | trans=dff99780-3298-4772-93a6-58e7e3335f35 | op=IoTAgentNGSI.DeviceService | from=n/a | srv=manhole | subsrv=/tombini | msg=Registering device into NGSI Service:

{

"id": "968574",

"type": "Device",

"name": "urn:ngsi-ld:Device:968574",

"service": "manhole",

"subservice": "/tombini",

"active": [

{

"object_id": "t",

"name": "temperature",

"type": "Property",

"metadata": {

"unitCode": {

"type": "Text",

"value": "CEL"

}

}

}

],

"staticAttributes": [],

"lazy": [],

"commands": [],

"timezone": "Europe/Rome",

"transport": "HTTP",

"internalId": null,

"explicitAttrs": false,

"subscriptions": [],

"polling": true

} | comp=IoTAgent`

Call generated to Context Broker from Iot Agent Json

time=2021-01-07T10:52:32.048Z | lvl=DEBUG | corr=dff99780-3298-4772-93a6-58e7e3335f35 | trans=dff99780-3298-4772-93a6-58e7e3335f35 | op=IoTAgentNGSI.Devices-LD | from=n/a | srv=manhole | subsrv=/tombini | msg=Creating initial entity in the Context Broker:

{

"url": "http://orion-context-broker-ld:1026/ngsi-ld/v1/entityOperations/upsert/",

"method": "POST",

"json": [

{

"@context": [

"https://schema.lab.fiware.org/ld/context.jsonld"

],

"id": "urn:ngsi-ld:Device:968574",

"type": "Device",

"temperature": {

"type": "Property",

"value": null, <----- ERROR

"unitCode": "CEL"

}

}

],

"headers": {

"fiware-service": "manhole",

"fiware-servicepath": "/tombini",

"NGSILD-Tenant": "manhole",

"NGSILD-Path": "/tombini",

"Content-Type": "application/ld+json"

}

}

Context Broker: time=Thursday 07 Jan 10:52:32 2021.099Z | lvl=ERROR | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=kjTreeToContextAttribute.cpp[818]:kjTreeToContextAttribute | msg=NULL value for Property 'https://smart-data-models.github.io/data-models/terms.jsonld#/definitions/temperature'

time=Thursday 07 Jan 10:52:32 2021.099Z | lvl=ERROR | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=kjTreeToUpdateContextRequest.cpp[135]:kjTreeToContextElementAttributes | msg=kjTreeToContextAttribute failed for attribute 'https://smart-data-models.github.io/data-models/terms.jsonld#/definitions/temperature': NULL value for Property

fgalan commented 3 years ago

Which IOTA JSON version are you using, please?

massimolauri commented 3 years ago

Latest 1.16, working perfectly on IOTA UL.

fgalan commented 3 years ago

Latest 1.16, working perfectly on IOTA UL.

That's weird... as IOTA JSON depends on iotagent-node-lib 2.14.0 which doesn't include any NGSI-LD functionality yet.

Maybe @jason-fox (main contributor to the NGSI-LD functionality to IOTAs) can help to clarify this.

jason-fox commented 3 years ago

Run

curl -X GET \
  'http://localhost:4041/iot/about'

For the 1.16 release you should get:

{
    "libVersion": "2.14.0",
    "port": "4041",
    "baseRoot": "/",
    "version": "1.16.0"
}

There should be no NGSI-LD support.

If you are using 1.16.0-next, the best idea is to refresh your node_modules

npm run clean
npm install
jason-fox commented 3 years ago

I am not seeing this behaviour when running fiware/iotagent-json:latest - running docker inspect:

 "Labels": {
                "maintainer": "FIWARE IoTAgent Team. Telefónica I+D",
                "org.nodejs.version": "10.23.0",
                "org.opencontainers.image.authors": "iot_support@tid.es",
                "org.opencontainers.image.created": "2020-12-17",
                "org.opencontainers.image.description": "An Internet of Things Agent for the JSON protocol (with AMQP, HTTP and MQTT transports). This IoT Agent is designed to be a bridge between Ultralight and the NGSI interface of a context broker.",
                "org.opencontainers.image.documentation": "https://fiware-iotagent-json.rtfd.io/",
                "org.opencontainers.image.licenses": "AGPL-3.0-only",
                "org.opencontainers.image.revision": "0e94f2e95969e3cf9bc426703d35da82612b02e2",
                "org.opencontainers.image.source": "https://github.com/telefonicaid/iotagent-json",
                "org.opencontainers.image.title": "IoT Agent for the JSON protocol",
                "org.opencontainers.image.vendor": "Telefónica Investigación y Desarrollo, S.A.U",
                "org.opencontainers.image.version": "latest"
            }

0e94f2e95969e3cf9bc426703d35da82612b02e2 corresponds to the latest GitHash.

jason-fox commented 3 years ago

I think I have discovered the issue:

"active": [
   {
      "object_id": "t",
      "name": "temperature",
      "type": "Property",
      "metadata": {
          "unitCode": {
                 "type": "Text",
                "value": "CEL"
          }
       }
    }
]

"type": "Property", a fallback for string (which used to be blank) and is not checking currently checking for null. It is a simple fix in the IoT Agent lib, but in the meantime provision your attribute using Float or Integer rather than Property.

fgalan commented 3 years ago

Fixed in PR https://github.com/telefonicaid/iotagent-node-lib/pull/980

fgalan commented 3 years ago

Fixed in PR telefonicaid/iotagent-node-lib#980

PR has been merged. I understand this issue can be closed. Do you agree @jason-fox @massimolauri ?

jason-fox commented 3 years ago

Yes, the fix is in the IoT Agent Node lib mainline, but since there haven't been any changes within the JSON IoT Agent's code base an up-to-date Docker Image with the changes in the dependent library isn't available on Docker Hub unless someone pushes a build manually.

Currently the only build likely to have NGSI-LD is latest and that is never stable. For safety checkout the JSON and code base cd to the docker folder and build your own bleeding edge Docker Image:

docker build  -t fiware/iotagent-json . --no-cache

The fix should automatically pass down to the JSON IoT Agent latest docker image the next time the code base gets updated (or a full release is made pinning to an official IoT Agent Node lib version). There is not yet a versioned release with NGSI-LD support available and current latest lacks the latest library bug fixes.

jason-fox commented 3 years ago

I have manually triggered a rebuild of the fiware/iotagent-json DockerHub Image - it should now be sufficient to run

docker pull  -t fiware/iotagent-json

to get latest - it is still unstable, but should have the NGSI-LD bug fix.

fgalan commented 3 years ago

Based on the previous feedback, I'm closing the issue. It can be reopened if @massimolauri finds something is not ok after the tests.