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
49 stars 89 forks source link

using NGSI V2, and a service, the device is not created, entity not created, and error returned #330

Closed agaldemas closed 1 year ago

agaldemas commented 5 years ago

using the latest image in dockerhub (Orion, IOTAgent-json), MongoDB 3.4 I have created a service such as:

{
    "count": 1,
    "services": [
        {
            "_id": "5baa2f7ac84bc6b523c46264",
            "subservice": "/testalain",
            "service": "testv2",
            "apikey": "apikey1",
            "resource": "/iot/json",
            "__v": 0,
            "attributes": [
                {
                    "name": "status",
                    "type": "string",
                    "object_id": "s"
                },
                {
                    "name": "temperature",
                    "type": "float",
                    "object_id": "t"
                },
                {
                    "name": "humidity",
                    "type": "float",
                    "object_id": "h"
                },
                {
                    "name": "location",
                    "type": "geo:json",
                    "object_id": "l"
                }
            ],
            "lazy": [],
            "commands": [],
            "entity_type": "chose",
            "internal_attributes": [],
            "static_attributes": [
                {
                    "name": "mygroupstatic1",
                    "type": "string",
                    "value": "test service apikey1"
                }
            ]
        }
    ]
}

using http transport, an update request is sent (using postman): [http://localhost:7896/iot/json?k=apikey1&i=device_002] with header:

Content-Type:application/json
Accept:application/json

when using NGSI V1, the behavior is OK, the device is created, as well the entity in Orion with the values. But when using NGSI V2, the device is not created, nor the entity and the following error is returned:

{
    "name": "ENTITY_GENERIC_ERROR",
    "message": "Error accesing entity data for device: device_002 of type: chose"
}

when the device and the entity exist (created with NGSI V1), the update request is successful... here is the configuration file:

var config = {};

config.mqtt = {
    host: 'mosquitto',
    port: 1883,
};

config.http = {
    port: 7896
};

config.iota = {
    logLevel: 'DEBUG',
    timestamp: true,
    contextBroker: {
        host: 'orion',
        port: '1026',
        ngsiVersion: 'v2'
    },
    server: {
        port: 4041
    },
    deviceRegistry: {
        type: 'mongodb'
    },
    mongodb: {
        host: 'mongo',
        port: '27017',
        db: 'iotagent-v2'
    },
    types: {},
    service: 'howtoService',
    subservice: '/howto',
    providerUrl: 'http://localhost:4041',
    deviceRegistrationDuration: 'P1M',
    defaultType: 'chose',
    defaultResource: '/iot/json'
};

//config.configRetrieval = false;
config.defaultKey = '1234';
config.defaultTransport = 'MQTT';

module.exports = config;

any idea about this problem ?

agaldemas commented 5 years ago

here is the logger DEBUG output corresponding the error:

idasJSON_1    | time=2018-09-25T15:17:13.167Z | lvl=DEBUG | corr=d549eac2-ffb1-4d2a-91f9-2068c92225e2 | trans=d549eac2-ffb1-4d2a-91f9-2068c92225e2 | op=IOTASON.HTTP.Binding | srv=testv2 | subsrv=/testalain | msg=Parsed data: [{"t":"14.22","h":"11.69","s":"hola ?"}] | comp=IoTAgent
idasJSON_1    | time=2018-09-25T15:17:13.174Z | lvl=DEBUG | corr=d549eac2-ffb1-4d2a-91f9-2068c92225e2 | trans=d549eac2-ffb1-4d2a-91f9-2068c92225e2 | op=IOTASON.HTTP.Binding | srv=testv2 | subsrv=/testalain | msg=Processing multiple HTTP measures for device [device_002] with apiKey [apikey1] | comp=IoTAgent
idasJSON_1    | time=2018-09-25T15:17:13.175Z | lvl=DEBUG | corr=d549eac2-ffb1-4d2a-91f9-2068c92225e2 | trans=d549eac2-ffb1-4d2a-91f9-2068c92225e2 | op=IoTAgentNGSI.MongoDBGroupRegister | srv=testv2 | subsrv=/testalain | msg=Looking for group params ["resource","apikey"] with queryObj {"resource":"/iot/json","apikey":"apikey1"} | comp=IoTAgent
idasJSON_1    | time=2018-09-25T15:17:13.188Z | lvl=DEBUG | corr=d549eac2-ffb1-4d2a-91f9-2068c92225e2 | trans=d549eac2-ffb1-4d2a-91f9-2068c92225e2 | op=IoTAgentNGSI.MongoDBGroupRegister | srv=testv2 | subsrv=/testalain | msg=Device group data found: {"_id":"5baa2f7ac84bc6b523c46264","subservice":"/testalain","service":"testv2","type":"chose","apikey":"apikey1","resource":"/iot/json","internalAttributes":[],"attributes":[{"name":"status","type":"string","object_id":"s"},{"name":"temperature","type":"float","object_id":"t"},{"name":"humidity","type":"float","object_id":"h"},{"name":"location","type":"geo:json","object_id":"l"}],"lazy":[],"staticAttributes":[{"name":"mygroupstatic1","type":"string","value":"test service apikey1"}],"commands":[]} | comp=IoTAgent
idasJSON_1    | time=2018-09-25T15:17:13.189Z | lvl=DEBUG | corr=d549eac2-ffb1-4d2a-91f9-2068c92225e2 | trans=d549eac2-ffb1-4d2a-91f9-2068c92225e2 | op=IoTAgentNGSI.MongoDBDeviceRegister | srv=testv2 | subsrv=/testalain | msg=Looking for device with id [device_002]. | comp=IoTAgent
idasJSON_1    | time=2018-09-25T15:17:13.199Z | lvl=DEBUG | corr=d549eac2-ffb1-4d2a-91f9-2068c92225e2 | trans=d549eac2-ffb1-4d2a-91f9-2068c92225e2 | op=IoTAgentNGSI.MongoDBDeviceRegister | srv=testv2 | subsrv=/testalain | msg=Device [device_002] not found. | comp=IoTAgent
idasJSON_1    | time=2018-09-25T15:17:13.200Z | lvl=ERROR | corr=d549eac2-ffb1-4d2a-91f9-2068c92225e2 | trans=d549eac2-ffb1-4d2a-91f9-2068c92225e2 | op=IoTAgentNGSI.Alarms | srv=testv2 | subsrv=/testalain | msg=Raising [MONGO-ALARM]: {"name":"DEVICE_NOT_FOUND","message":"No device was found with id:device_002","code":404} | comp=IoTAgent
idasJSON_1    | time=2018-09-25T15:17:13.201Z | lvl=DEBUG | corr=d549eac2-ffb1-4d2a-91f9-2068c92225e2 | trans=d549eac2-ffb1-4d2a-91f9-2068c92225e2 | op=IoTAgentNGSI.MongoDBDeviceRegister | srv=testv2 | subsrv=/testalain | msg=Looking for device with id [device_002]. | comp=IoTAgent
idasJSON_1    | time=2018-09-25T15:17:13.205Z | lvl=DEBUG | corr=d549eac2-ffb1-4d2a-91f9-2068c92225e2 | trans=d549eac2-ffb1-4d2a-91f9-2068c92225e2 | op=IoTAgentNGSI.MongoDBDeviceRegister | srv=testv2 | subsrv=/testalain | msg=Device [device_002] not found. | comp=IoTAgent
idasJSON_1    | time=2018-09-25T15:17:13.205Z | lvl=DEBUG | corr=d549eac2-ffb1-4d2a-91f9-2068c92225e2 | trans=d549eac2-ffb1-4d2a-91f9-2068c92225e2 | op=IoTAgentNGSI.MongoDBGroupRegister | srv=testv2 | subsrv=/testalain | msg=Looking for group params ["service","subservice","type"] with queryObj {"service":"testv2","subservice":"/testalain","type":"chose"} | comp=IoTAgent
idasJSON_1    | time=2018-09-25T15:17:13.232Z | lvl=DEBUG | corr=d549eac2-ffb1-4d2a-91f9-2068c92225e2 | trans=d549eac2-ffb1-4d2a-91f9-2068c92225e2 | op=IoTAgentNGSI.MongoDBGroupRegister | srv=testv2 | subsrv=/testalain | msg=Device group data found: {"_id":"5baa2f7ac84bc6b523c46264","subservice":"/testalain","service":"testv2","type":"chose","apikey":"apikey1","resource":"/iot/json","internalAttributes":[],"attributes":[{"name":"status","type":"string","object_id":"s"},{"name":"temperature","type":"float","object_id":"t"},{"name":"humidity","type":"float","object_id":"h"},{"name":"location","type":"geo:json","object_id":"l"}],"lazy":[],"staticAttributes":[{"name":"mygroupstatic1","type":"string","value":"test service apikey1"}],"commands":[]} | comp=IoTAgent
idasJSON_1    | time=2018-09-25T15:17:13.233Z | lvl=ERROR | corr=d549eac2-ffb1-4d2a-91f9-2068c92225e2 | trans=d549eac2-ffb1-4d2a-91f9-2068c92225e2 | op=IoTAgentNGSI.Alarms | srv=testv2 | subsrv=/testalain | msg=Releasing [MONGO-ALARM] | comp=IoTAgent
idasJSON_1    | time=2018-09-25T15:17:13.233Z | lvl=DEBUG | corr=d549eac2-ffb1-4d2a-91f9-2068c92225e2 | trans=d549eac2-ffb1-4d2a-91f9-2068c92225e2 | op=IoTAgentNGSI.DeviceService | srv=testv2 | subsrv=/testalain | msg=Device name not found, falling back to deviceType:deviceId [chose:device_002] | comp=IoTAgent
idasJSON_1    | time=2018-09-25T15:17:13.234Z | lvl=DEBUG | corr=d549eac2-ffb1-4d2a-91f9-2068c92225e2 | trans=d549eac2-ffb1-4d2a-91f9-2068c92225e2 | op=IoTAgentNGSI.DeviceService | srv=testv2 | subsrv=/testalain | msg=Registering device into NGSI Service:
idasJSON_1    | {
idasJSON_1    |     "id": "device_002",
idasJSON_1    |     "service": "testv2",
idasJSON_1    |     "subservice": "/testalain",
idasJSON_1    |     "type": "chose",
idasJSON_1    |     "transport": "HTTP",
idasJSON_1    |     "name": "chose:device_002",
idasJSON_1    |     "lazy": [],
idasJSON_1    |     "active": [
idasJSON_1    |         {
idasJSON_1    |             "name": "status",
idasJSON_1    |             "type": "string",
idasJSON_1    |             "object_id": "s"
idasJSON_1    |         },
idasJSON_1    |         {
idasJSON_1    |             "name": "temperature",
idasJSON_1    |             "type": "float",
idasJSON_1    |             "object_id": "t"
idasJSON_1    |         },
idasJSON_1    |         {
idasJSON_1    |             "name": "humidity",
idasJSON_1    |             "type": "float",
idasJSON_1    |             "object_id": "h"
idasJSON_1    |         },
idasJSON_1    |         {
idasJSON_1    |             "name": "location",
idasJSON_1    |             "type": "geo:json",
idasJSON_1    |             "object_id": "l"
idasJSON_1    |         }
idasJSON_1    |     ],
idasJSON_1    |     "staticAttributes": [
idasJSON_1    |         {
idasJSON_1    |             "name": "mygroupstatic1",
idasJSON_1    |             "type": "string",
idasJSON_1    |             "value": "test service apikey1"
idasJSON_1    |         }
idasJSON_1    |     ],
idasJSON_1    |     "commands": [],
idasJSON_1    |     "subscriptions": []
idasJSON_1    | } | comp=IoTAgent
idasJSON_1    | time=2018-09-25T15:17:13.235Z | lvl=DEBUG | corr=d549eac2-ffb1-4d2a-91f9-2068c92225e2 | trans=d549eac2-ffb1-4d2a-91f9-2068c92225e2 | op=IoTAgentNGSI.DeviceService | srv=testv2 | subsrv=/testalain | msg=Registration with Context Provider is not needed. Device without lazy atts or commands | comp=IoTAgent
idasJSON_1    | time=2018-09-25T15:17:13.236Z | lvl=DEBUG | corr=d549eac2-ffb1-4d2a-91f9-2068c92225e2 | trans=d549eac2-ffb1-4d2a-91f9-2068c92225e2 | op=IoTAgentNGSI.DeviceService | srv=testv2 | subsrv=/testalain | msg=Creating initial entity in the Context Broker:
idasJSON_1    |  {
idasJSON_1    |     "url": "http://orion:1026/v2/entities?options=upsert",
idasJSON_1    |     "method": "POST",
idasJSON_1    |     "json": {
idasJSON_1    |         "id": "chose:device_002",
idasJSON_1    |         "type": "chose",
idasJSON_1    |         "status": {
idasJSON_1    |             "type": "string",
idasJSON_1    |             "value": " "
idasJSON_1    |         },
idasJSON_1    |         "temperature": {
idasJSON_1    |             "type": "float",
idasJSON_1    |             "value": " "
idasJSON_1    |         },
idasJSON_1    |         "humidity": {
idasJSON_1    |             "type": "float",
idasJSON_1    |             "value": " "
idasJSON_1    |         },
idasJSON_1    |         "location": {
idasJSON_1    |             "type": "geo:json",
idasJSON_1    |             "value": " "
idasJSON_1    |         },
idasJSON_1    |         "mygroupstatic1": {
idasJSON_1    |             "type": "string",
idasJSON_1    |             "value": "test service apikey1"
idasJSON_1    |         },
idasJSON_1    |         "TimeInstant": {
idasJSON_1    |             "type": "DateTime",
idasJSON_1    |             "value": "2018-09-25T15:17:13.236Z"
idasJSON_1    |         }
idasJSON_1    |     },
idasJSON_1    |     "headers": {
idasJSON_1    |         "fiware-service": "testv2",
idasJSON_1    |         "fiware-servicepath": "/testalain",
idasJSON_1    |         "fiware-correlator": "d549eac2-ffb1-4d2a-91f9-2068c92225e2"
idasJSON_1    |     }
idasJSON_1    | } | comp=IoTAgent
idasJSON_1    | time=2018-09-25T15:17:13.251Z | lvl=ERROR | corr=d549eac2-ffb1-4d2a-91f9-2068c92225e2 | trans=d549eac2-ffb1-4d2a-91f9-2068c92225e2 | op=IoTAgentNGSI.DeviceService | srv=testv2 | subsrv=/testalain | msg=Protocol error connecting to the Context Broker [400]: [object Object] | comp=IoTAgent
idasJSON_1    | time=2018-09-25T15:17:13.251Z | lvl=DEBUG | corr=d549eac2-ffb1-4d2a-91f9-2068c92225e2 | trans=d549eac2-ffb1-4d2a-91f9-2068c92225e2 | op=IOTASON.HTTP.Binding | srv=testv2 | subsrv=/testalain | msg=Error [ENTITY_GENERIC_ERROR] handing request: Error accesing entity data for device: device_002 of type: chose | comp=IoTAgent
fgalan commented 5 years ago

when using NGSI V1, the behavior is OK, the device is created, as well the entity in Orion with the values.

You mean that:

Is that exactly the situation? Or is there any diference?

(Just to check if I'm understanding the issue correctly)

fgalan commented 5 years ago

Note the "assuming no data is in DB (i.e. no device previously created, etc.)" please... it is important from the point of testing cleaness (the status of the DB may influence in the result of the test).

agaldemas commented 5 years ago

Hello @fgalan yes I've tested starting from an empty database (iotagent and orion). and I confirm your right understanding of the issue !

dcalvoalonso commented 5 years ago

@agaldemas The problem is that you are using geo:json type for location attribute. You must note that Orion Context Broker expects a JSON object in the value field of attributes with such type and it's something not supported with the current version of https://github.com/telefonicaid/iotagent-node-lib (https://github.com/telefonicaid/iotagent-node-lib/issues/549).

Would be possible for you to use geo:point type?

agaldemas commented 5 years ago

Hello,

The reason we wanted to use NGSI V2 was to be able to use geo:json type for location (as we want to use polylines & polygons, to be forwarded from IOT agent to Orion... So we'll wait a bit for that.

arilwan commented 5 years ago

I guess the IoTAgent has an issue with NGSIv2 for device management. I am also having this error trying to provision my device. {"name":"ENTITY_GENERIC_ERROR","message":"Error accesing entity data for device: testlwm2mclient of type: Device"} Any Idea why this happens?

tzzed commented 1 year ago

It occurs when the headers are not correct. fiware-service and fiware-servicepath.

mapedraza commented 1 year ago

This is a quite old issue, and it shows an error on simple requests without any complex functionality. Even more, NGSIv1 support is deprecated from IoTA.

Since the error is quite non specific and there are multiples reasons why this error is given (as @tzzed mentioned above), it is better to close this issue.

@agaldemas if you still have this problem in latest IoTA version, feel free to create a new issue giving more details (curl requests, IOTA version etc)