telefonicaid / sigfox-iotagent

IoT Agent for the Sigfox protocol
https://iotagent-sigfox.rtfd.io/
GNU Affero General Public License v3.0
11 stars 12 forks source link

DEVICE_NOT_FOUND error with Scorpio Broker #135

Open mohitNEC opened 1 year ago

mohitNEC commented 1 year ago

Hi,

I'm trying to integrate Scorpio Broker with FIWARE IoT Agent for Sigfox Protocol. In the device provisioning the NGSI-LD entity is created successfully. But when I am trying to send measurements to the Sigfox IoT Agent it is showing error. Firstly, I register the service and the device to the agent. As you can see from below:

Service Provisioning:

curl --location --request POST 'http://<Sigfox-IoTAgent>:4041/iot/services' \
--header 'fiware-service: dumbMordor' \
--header 'fiware-servicepath: /deserts' \
--header 'Content-Type: application/json' \
--data-raw '{
    "services": [
        {
            "cbroker": "http://scorpio:9090",
            "resource": "/sigfoxDev",
            "apikey": "23HJK3Y9090DSFL173209HV8801232",
            "type": "Device",
            "commands": [],
            "lazy": [],
            "active": []
        }
    ]
}'

Device Provisioning:

curl --location --request POST 'http://<Sigfox-IoTAgent>:4041/iot/devices' \
--header 'fiware-service: dumbMordor' \
--header 'fiware-servicepath: /deserts' \
--header 'Content-Type: application/json' \
--data-raw '{
    "devices": [
        {
            "device_id": "sigApp1",
            "entity_name": "urn:ngsi-ld:Device:sigApp1",
            "entity_type": "Device",
            "protocol": "SIGFOX",
            "timezone": "America/Santiago",
            "attributes": [
                {
                    "name": "time",
                    "type": "String"
                },
                {
                    "name": "statin",
                    "type": "String"
                },
                {
                    "name": "lng",
                    "type": "String"
                },
                {
                    "name": "lat",
                    "type": "String"
                },
                {
                    "name": "theCounter",
                    "type": "Integer"
                },
                {
                    "name": "theParam1",
                    "type": "Integer"
                },
                {
                    "name": "param2",
                    "type": "Integer"
                },
                {
                    "name": "tempDegreesCelsius",
                    "type": "Integer"
                },
                {
                    "name": "voltage",
                    "type": "Integer"
                }
            ],
            "lazy": [],
            "static_attributes": [],
            "commands": [],
            "internal_attributes": [
                {
                    "mapping": "theCounter::uint:32  theParam1::uint:32 param2::uint:8 tempDegreesCelsius::uint:8  voltage::uint:16"
                }
            ]
        }
    ]
}'

After that, the NGSI-LD entity in Scorpio Broker is:

{
    "id": "urn:ngsi-ld:Device:sigApp1",
    "type": "Device"
}

After follow these steps, when I try to send measures using the following GET callback:

curl --location -g --request GET 'http://<Sigfox-IP>:17428/update?id=urn:ngsi-ld:Device:sigApp1&data={theCounter: 2, theparam1: 0,param2: 0,tempDegreesCelsius: 35,voltage: 3183}' \
--header 'fiware-service: dumbMordor' \
--header 'fiware-servicepath: /deserts' \
--header 'Content-Type: application/json' \
--data-raw ''

RESPONSE:

{
    "name": "DEVICE_NOT_FOUND",
    "message": "No device was found with id:urn:ngsi-ld:Device:sigApp1",
    "code": 404
}

Sigfox IoT Agent Logs:

time=2023-07-18T06:20:50.705Z | lvl=DEBUG | corr=0e5fbb1c-ec9a-44a9-b0a5-f618dfcfef18 | trans=0e5fbb1c-ec9a-44a9-b0a5-f618dfcfef18 | op=IoTAgentSIGFOX.SigfoxServer | from=n/a | srv=dumbmordor | subsrv=/deserts | msg=Request for path [/update] from [172.30.48.45:17428] | comp=IoTAgent
time=2023-07-18T06:20:50.705Z | lvl=DEBUG | corr=0e5fbb1c-ec9a-44a9-b0a5-f618dfcfef18 | trans=0e5fbb1c-ec9a-44a9-b0a5-f618dfcfef18 | op=IoTAgentSIGFOX.SigfoxServer | from=n/a | srv=dumbmordor | subsrv=/deserts | msg=Body:

undefined

 | comp=IoTAgent
time=2023-07-18T06:20:50.706Z | lvl=DEBUG | corr=0e5fbb1c-ec9a-44a9-b0a5-f618dfcfef18 | trans=0e5fbb1c-ec9a-44a9-b0a5-f618dfcfef18 | op=IoTAgentSIGFOX.SigfoxHandlers | from=n/a | srv=dumbmordor | subsrv=/deserts | msg=Handling request with query [{"id":"urn:ngsi-ld:Device:sigApp1","data":"{theCounter: 2, theparam1: 0,param2: 0,tempDegreesCelsius: 35,voltage: 3183}"}] | comp=IoTAgent
time=2023-07-18T06:20:50.706Z | lvl=DEBUG | corr=0e5fbb1c-ec9a-44a9-b0a5-f618dfcfef18 | trans=0e5fbb1c-ec9a-44a9-b0a5-f618dfcfef18 | op=IoTAgentNGSI.MongoDBDeviceRegister | from=n/a | srv=howtoService | subsrv=/howto | msg=Looking for device with id [urn:ngsi-ld:Device:sigApp1]. | comp=IoTAgent
time=2023-07-18T06:20:50.711Z | lvl=DEBUG | corr=0e5fbb1c-ec9a-44a9-b0a5-f618dfcfef18 | trans=0e5fbb1c-ec9a-44a9-b0a5-f618dfcfef18 | op=IoTAgentNGSI.MongoDBDeviceRegister | from=n/a | srv=howtoService | subsrv=/howto | msg=Device [urn:ngsi-ld:Device:sigApp1] not found. | comp=IoTAgent
time=2023-07-18T06:20:50.711Z | lvl=ERROR | corr=0e5fbb1c-ec9a-44a9-b0a5-f618dfcfef18 | trans=0e5fbb1c-ec9a-44a9-b0a5-f618dfcfef18 | op=IoTAgentNGSI.Alarms | from=n/a | srv=dumbmordor | subsrv=/deserts | msg=Raising [MONGO-ALARM]: {"name":"DEVICE_NOT_FOUND","message":"No device was found with id:urn:ngsi-ld:Device:sigApp1","code":404} | comp=IoTAgent

Same issue has been raised before with Orion-v2. Can anyone help me sending measure to the IoT Agent Sigfox?

Thanks.

fgalan commented 1 year ago

Maybe @jason-fox could provide feedback on this.

jason-fox commented 1 year ago

The provisioning of the device is incorrect. On provisioning you stated:

 "device_id": "sigApp1",
"entity_name": "urn:ngsi-ld:Device:sigApp1",

BUT

curl --location -g --request GET 'http://<Sigfox-IP>:17428/update?id=urn:ngsi-ld:Device:sigApp1&data={theCounter: 2, theparam1: 0,param2: 0,tempDegreesCelsius: 35,voltage: 3183}' \
--header 'fiware-service: dumbMordor' \
--header 'fiware-servicepath: /deserts' \
--header 'Content-Type: application/json' \
--data-raw ''

It looks like the IoT Agent is expecting to map device id=sigApp1 in the real world to URN urn:ngsi-ld:Device:sigApp within the context broker. You are then sending a SigFox request with id=urn:ngsi-ld:Device:sigApp which hasn't got a mapping key.

I assume:

curl --location -g --request GET 'http://<Sigfox-IP>:17428/update?id=sigApp1&data={theCounter: 2, theparam1: 0,param2: 0,tempDegreesCelsius: 35,voltage: 3183}' \
--header 'fiware-service: dumbMordor' \
--header 'fiware-servicepath: /deserts' \
--header 'Content-Type: application/json' \
--data-raw ''

Would work for you.

mohitNEC commented 1 year ago

Hi @jason-fox ,

Thank You for the continuous support.

I have followed the same steps to provision device in Sigfox IoT Agent with entity_name same as device_id, like as:

curl --location --request POST 'http://<Sigfox-IoTAgent>:4041/iot/devices' \
--header 'fiware-service: dumbMordor' \
--header 'fiware-servicepath: /deserts' \
--header 'Content-Type: application/json' \
--data-raw '{
    "devices": [
        {
            "device_id": "sigApp1",
            "entity_name": "sigApp1",
            "entity_type": "Device",
            "protocol": "SIGFOX",
            "timezone": "America/Santiago",
            "attributes": [
                {
                    "name": "time",
                    "type": "String"
                },
                {
                    "name": "statin",
                    "type": "String"
                },
                {
                    "name": "lng",
                    "type": "String"
                },
                {
                    "name": "lat",
                    "type": "String"
                },
                {
                    "name": "theCounter",
                    "type": "Integer"
                },
                {
                    "name": "theParam1",
                    "type": "Integer"
                },
                {
                    "name": "param2",
                    "type": "Integer"
                },
                {
                    "name": "tempDegreesCelsius",
                    "type": "Integer"
                },
                {
                    "name": "voltage",
                    "type": "Integer"
                }
            ],
            "lazy": [],
            "static_attributes": [],
            "commands": [],
            "internal_attributes": [
                {
                    "mapping": "theCounter::uint:32  theParam1::uint:32 param2::uint:8 tempDegreesCelsius::uint:8  voltage::uint:16"
                }
            ]
        }
    ]
}'

After that, when I try to send measures using the following GET callback that you suggested:

curl --location -g --request GET 'http://<Sigfox-IoTAgent>:17428/update?id=sigApp1&data={theCounter: 2, theparam1: 0,param2: 0,tempDegreesCelsius: 35,voltage: 3183}' \
--header 'fiware-service: dumbMordor' \
--header 'fiware-servicepath: /deserts' \
--header 'Content-Type: application/json'

Still I'm getting the same error as :

{
    "name": "DEVICE_NOT_FOUND",
    "message": "No device was found with id:sigApp1",
    "code": 404
}
jason-fox commented 1 year ago

I think

"device_id": "sigApp1",
 "entity_name": "urn:ngsi-ld:Device:sigApp1",

With http://<Sigfox-IoTAgent>:17428/update?id=sigApp1&data={theCounter: 2, theparam1: 0,param2: 0,tempDegreesCelsius: 35,voltage: 3183}

is more likely to work -- entities within Scorpio should be urns.

mohitNEC commented 1 year ago

Hi, Still getting the same error.

mohitNEC commented 1 year ago

Hi, Any update regarding this issue. We are still getting the same issue.

BR, Mohit Chauhan

mohitNEC commented 1 year ago

Hi, Is there any update regarding this issue?

Best Regards, Mohit Chauhan

mohitNEC commented 1 year ago

Hi, Is there any update regarding this issue?

mohitNEC commented 11 months ago

Hi, Is there any update regarding this issue. We are still getting the same error.

fgalan commented 11 months ago

Maybe @jason-fox could provide some feedback on this?

jason-fox commented 11 months ago

I'm not actively working with the SigFox protocol.