FIWARE / tutorials.Custom-IoT-Agent

:orange_book: FIWARE 205: Creating a Custom IoT Agent
https://iotagent-node-lib.readthedocs.io/
MIT License
4 stars 3 forks source link

Can’t[Provisioning a Sensor] #6

Open hsakamoto123 opened 1 year ago

hsakamoto123 commented 1 year ago

Provisioning a Sensor 3️⃣ Request: will result in the following error: Please tell me how to avoid it.

$ curl -iX POST \
>   'http://localhost:4041/iot/devices' \
>   -H 'Content-Type: application/json' \
>   -H 'fiware-service: openiot' \
>   -H 'fiware-servicepath: /' \
>   -d '{
>  "devices": [
>    {
>      "device_id":   "motion001",
>      "entity_name": "urn:ngsi-ld:Motion:001",
>      "entity_type": "Motion",
>      "timezone":    "Europe/Berlin",
>      "attributes": [
>        { "object_id": "c", "name": "count", "type": "Integer" }
>      ],
>      "static_attributes": [
>        { "name":"refStore", "type": "Relationship", "value": "urn:ngsi-ld:Store:001"}
>      ]
>    }
>  ]
> }
> '
HTTP/1.1 500 Internal Server Error
X-Powered-By: Express
Fiware-Correlator: 463d0a57-1870-48c2-b709-d14766ea674f
Content-Type: application/json; charset=utf-8
Content-Length: 83
ETag: W/"53-yJOco57zUHHICXOIMQuA66DVpBQ"
Date: Thu, 12 Jan 2023 15:35:41 GMT
Connection: keep-alive
Keep-Alive: timeout=5

{"name":"TypeError","message":"Cannot read properties of undefined (reading 'id')"}
hsakamoto123 commented 1 year ago

Any new information on how to avoid it?

jason-fox commented 1 year ago

I am unable to reproduce your error.

tutorials.Custom-IoT-Agent % curl -iX POST \
  'http://localhost:4041/iot/devices' \
  -H 'Content-Type: application/json' \
  -H 'fiware-service: openiot' \
  -H 'fiware-servicepath: /' \
  -d '{
 "devices": [
   {
     "device_id":   "motion001",
     "entity_name": "urn:ngsi-ld:Motion:001",
     "entity_type": "Motion",
     "timezone":    "Europe/Berlin",
     "attributes": [
       { "object_id": "c", "name": "count", "type": "Integer" }
     ],
     "static_attributes": [
       { "name":"refStore", "type": "Relationship", "value": "urn:ngsi-ld:Store:001"}
     ]
   }
 ]
}'

I receive the following:

HTTP/1.1 201 Created
X-Powered-By: Express
Fiware-Correlator: b10c1fef-6077-489a-a38b-83b5143c4e02
Content-Type: application/json; charset=utf-8
Content-Length: 2
ETag: W/"2-vyGp6PvFo4RvsFtPoIWeCReyIC8"
Date: Mon, 20 Feb 2023 08:48:00 GMT
Connection: keep-alive
Keep-Alive: timeout=5

{}
jason-fox commented 1 year ago

When I run

docker logs fiware-iot-agent  

I receive:

ime=2023-02-20T08:48:00.883Z | lvl=DEBUG | corr=6ce179d9-927e-4e5c-a9b2-ddf0472f6fcf | trans=6ce179d9-927e-4e5c-a9b2-ddf0472f6fcf | op=IoTAgentNGSI.DeviceService | from=n/a | srv=n/a | subsrv=n/a | msg=deviceData after merge with conf: {"id":"motion001","type":"Motion","name":"urn:ngsi-ld:Motion:001","service":"openiot","subservice":"/","active":[{"object_id":"c","name":"count","type":"Integer"}],"staticAttributes":[{"name":"refStore","type":"Relationship","value":"urn:ngsi-ld:Store:001"}],"lazy":null,"commands":[],"timezone":"Europe/Berlin","transport":"HTTP","internalId":null,"subscriptions":[],"polling":true} | comp=IoTAgent
time=2023-02-20T08:48:00.883Z | lvl=DEBUG | corr=6ce179d9-927e-4e5c-a9b2-ddf0472f6fcf | trans=6ce179d9-927e-4e5c-a9b2-ddf0472f6fcf | op=IoTAgentNGSI.DeviceService | from=n/a | srv=n/a | subsrv=n/a | msg=Registering device into NGSI Service:
{
    "id": "motion001",
    "type": "Motion",
    "name": "urn:ngsi-ld:Motion:001",
    "service": "openiot",
    "subservice": "/",
    "active": [
        {
            "object_id": "c",
            "name": "count",
            "type": "Integer"
        }
    ],
    "staticAttributes": [
        {
            "name": "refStore",
            "type": "Relationship",
            "value": "urn:ngsi-ld:Store:001"
        }
    ],
    "lazy": null,
    "commands": [],
    "timezone": "Europe/Berlin",
    "transport": "HTTP",
    "internalId": null,
    "subscriptions": [],
    "polling": true
} | comp=IoTAgent
time=2023-02-20T08:48:00.884Z | lvl=DEBUG | corr=6ce179d9-927e-4e5c-a9b2-ddf0472f6fcf | trans=6ce179d9-927e-4e5c-a9b2-ddf0472f6fcf | op=IoTAgentNGSI.Registration | from=n/a | srv=n/a | subsrv=n/a | msg=Registration with Context Provider is not needed. Device without lazy atts or commands | comp=IoTAgent
time=2023-02-20T08:48:00.884Z | lvl=DEBUG | corr=6ce179d9-927e-4e5c-a9b2-ddf0472f6fcf | trans=6ce179d9-927e-4e5c-a9b2-ddf0472f6fcf | op=IoTAgentNGSI.Devices-v2 | from=n/a | srv=n/a | subsrv=n/a | msg=deviceData: {"id":"motion001","type":"Motion","name":"urn:ngsi-ld:Motion:001","service":"openiot","subservice":"/","active":[{"object_id":"c","name":"count","type":"Integer"}],"staticAttributes":[{"name":"refStore","type":"Relationship","value":"urn:ngsi-ld:Store:001"}],"lazy":null,"commands":[],"timezone":"Europe/Berlin","transport":"HTTP","internalId":null,"subscriptions":[],"polling":true} | comp=IoTAgent
time=2023-02-20T08:48:00.884Z | lvl=DEBUG | corr=6ce179d9-927e-4e5c-a9b2-ddf0472f6fcf | trans=6ce179d9-927e-4e5c-a9b2-ddf0472f6fcf | op=IoTAgentNGSI.Devices-v2 | from=n/a | srv=n/a | subsrv=n/a | msg=config.timestamp undefined true | comp=IoTAgent
time=2023-02-20T08:48:00.885Z | lvl=DEBUG | corr=6ce179d9-927e-4e5c-a9b2-ddf0472f6fcf | trans=6ce179d9-927e-4e5c-a9b2-ddf0472f6fcf | op=IoTAgentNGSI.Devices-v2 | from=n/a | srv=n/a | subsrv=n/a | msg=Creating initial entity in the Context Broker:
 {
    "url": "http://orion:1026/v2/entities?options=upsert",
    "method": "POST",
    "json": {
        "id": "urn:ngsi-ld:Motion:001",
        "type": "Motion",
        "count": {
            "type": "Integer",
            "value": null
        },
        "refStore": {
            "type": "Relationship",
            "value": "urn:ngsi-ld:Store:001"
        },
        "TimeInstant": {
            "type": "DateTime",
            "value": "2023-02-20T08:48:00.884Z"
        }
    },
    "headers": {
        "fiware-service": "openiot",
        "fiware-servicepath": "/",
        "fiware-correlator": "6ce179d9-927e-4e5c-a9b2-ddf0472f6fcf"
    }
} | comp=IoTAgent
jason-fox commented 1 year ago

I assume that when you do so, you are receiving something different - could you post it.