FIWARE / tutorials.IoT-Agent-JSON

:orange_book: FIWARE 204: Provisioning the JSON IoT Agent
https://fiware-iotagent-json.readthedocs.io/
MIT License
6 stars 9 forks source link

Can't [Provisioning a Smart Lamp] #7

Closed hsakamoto123 closed 1 year ago

hsakamoto123 commented 1 year ago

Execution of request 10 results in the following.

$ curl -iX POST \
>   'http://localhost:4041/iot/devices' \
>   -H 'Content-Type: application/json' \
>   -H 'fiware-service: openiot' \
>   -H 'fiware-servicepath: /' \
>   -d '{
>   "devices": [
>     {
>       "device_id": "lamp001",
>       "entity_name": "urn:ngsi-ld:Lamp:001",
>       "entity_type": "Lamp",
>       "transport": "HTTP",
>       "endpoint": "http://iot-sensors:3001/iot/lamp001",
>       "commands": [
>         {"name": "on","type": "command"},
>         {"name": "off","type": "command"}
>        ],
>        "attributes": [
>         {"object_id": "s", "name": "state", "type":"Text"},
>         {"object_id": "l", "name": "luminosity", "type":"Integer"}
>        ],
>        "static_attributes": [
>          {"name":"refStore", "type": "Relationship","value": "urn:ngsi-ld:Store:001"}
>       ]
>     }
>   ]
> }
> '
HTTP/1.1 409 Conflict
X-Powered-By: Express
Fiware-Correlator: 65266c6f-9212-4c18-ae9c-8d383ec892d4
Content-Type: application/json; charset=utf-8
Content-Length: 108
ETag: W/"6c-MXV0ASHmZcVgSm+giF5KNzT8oKg"
Date: Fri, 06 Jan 2023 13:01:54 GMT
Connection: keep-alive
Keep-Alive: timeout=5

{"name":"DUPLICATE_DEVICE_ID","message":"A device with the same pair (Service, DeviceId) was found:lamp001"}

Immediately after deleting lamp001, it becomes as follows.

$ curl -iX DELETE \
>   'http://localhost:4041/iot/devices/lamp001' \
>   -H 'fiware-service: openiot' \
>   -H 'fiware-servicepath: /' \
>
HTTP/1.1 204 No Content
X-Powered-By: Express
Fiware-Correlator: fcdd1899-28d1-4468-9bb0-213ba9e7bf00
Date: Fri, 06 Jan 2023 13:40:36 GMT
Connection: keep-alive
Keep-Alive: timeout=5

$ curl -iX GET \
>   'http://localhost:4041/iot/devices' \
>   -H 'fiware-service: openiot' \
>   -H 'fiware-servicepath: /' \
>
HTTP/1.1 200 OK
X-Powered-By: Express
Fiware-Correlator: ad6ae953-d1ef-45ba-8ca3-6f262bbc2735
Content-Type: application/json; charset=utf-8
Content-Length: 2621
ETag: W/"a3d-CuISSZ2Ndsk6eFBH0qVwv/pnFM8"
Date: Fri, 06 Jan 2023 13:40:52 GMT
Connection: keep-alive
Keep-Alive: timeout=5

{"count":9,"devices":[{"device_id":"motion001","service":"openiot","service_path":"/","entity_name":"urn:ngsi-ld:Motion:001","entity_type":"Motion","polling":true,"transport":"HTTP","attributes":[{"object_id":"c","name":"count","type":"Integer"}],"lazy":[],"commands":[],"static_attributes":[{"name":"refStore","type":"Relationship","value":"urn:ngsi-ld:Store:001"}],"explicitAttrs":false},{"device_id":"bell001","service":"openiot","service_path":"/","entity_name":"urn:ngsi-ld:Bell:001","entity_type":"Bell","endpoint":"http://iot-sensors:3001/iot/bell001","polling":false,"transport":"HTTP","attributes":[],"lazy":[],"commands":[{"object_id":"ring","name":"ring","type":"command"}],"static_attributes":[{"name":"refStore","type":"Relationship","value":"urn:ngsi-ld:Store:001"}],"explicitAttrs":false},{"device_id":"lamp002","service":"openiot","service_path":"/","entity_name":"Thing:lamp002","entity_type":"Thing","transport":"HTTP","attributes":[],"lazy":[],"commands":[],"static_attributes":[]},{"device_id":"lamp003","service":"openiot","service_path":"/","entity_name":"Thing:lamp003","entity_type":"Thing","transport":"HTTP","attributes":[],"lazy":[],"commands":[],"static_attributes":[]},{"device_id":"lamp004","service":"openiot","service_path":"/","entity_name":"Thing:lamp004","entity_type":"Thing","transport":"HTTP","attributes":[],"lazy":[],"commands":[],"static_attributes":[]},{"device_id":"motion002","service":"openiot","service_path":"/","entity_name":"Thing:motion002","entity_type":"Thing","transport":"HTTP","attributes":[],"lazy":[],"commands":[],"static_attributes":[]},{"device_id":"motion003","service":"openiot","service_path":"/","entity_name":"Thing:motion003","entity_type":"Thing","transport":"HTTP","attributes":[],"lazy":[],"commands":[],"static_attributes":[]},{"device_id":"motion004","service":"openiot","service_path":"/","entity_name":"Thing:motion004","entity_type":"Thing","transport":"HTTP","attributes":[],"lazy":[],"commands":[],"static_attributes":[]},{"device_id":"door001","service":"openiot","service_path":"/","entity_name":"urn:ngsi-ld:Door:001","entity_type":"Door","endpoint":"http://iot-sensors:3001/iot/door001","polling":false,"transport":"HTTP","attributes":[{"object_id":"s","name":"state","type":"Text"}],"lazy":[],"commands":[{"object_id":"unlock","name":"unlock","type":"command"},{"object_id":"open","name":"open","type":"command"},{"object_id":"close","name":"close","type":"command"},{"object_id":"lock","name":"lock","type":"command"}],"static_attributes":[{"name":"refStore","type":"Relationship","value":"urn:ngsi-ld:Store:001"}],"explicitAttrs":false}]}

I didn't do anything, but when I checked after a while, lamp001 was registered.

$ curl -iX GET \
>   'http://localhost:4041/iot/devices' \
>   -H 'fiware-service: openiot' \
>   -H 'fiware-servicepath: /' \
HTTP/1.1 200 OK
X-Powered-By: Express
Fiware-Correlator: 4d209a38-cc1f-4d4c-bfda-b98565d910e5
Content-Type: application/json; charset=utf-8
Content-Length: 2819
ETag: W/"b03-fXReqz7ee1wiQFiiR5UKDMKhxsg"
Date: Fri, 06 Jan 2023 13:42:15 GMT
Connection: keep-alive
Keep-Alive: timeout=5

{"count":10,"devices":[{"device_id":"motion001","service":"openiot","service_path":"/","entity_name":"urn:ngsi-ld:Motion:001","entity_type":"Motion","polling":true,"transport":"HTTP","attributes":[{"object_id":"c","name":"count","type":"Integer"}],"lazy":[],"commands":[],"static_attributes":[{"name":"refStore","type":"Relationship","value":"urn:ngsi-ld:Store:001"}],"explicitAttrs":false},{"device_id":"bell001","service":"openiot","service_path":"/","entity_name":"urn:ngsi-ld:Bell:001","entity_type":"Bell","endpoint":"http://iot-sensors:3001/iot/bell001","polling":false,"transport":"HTTP","attributes":[],"lazy":[],"commands":[{"object_id":"ring","name":"ring","type":"command"}],"static_attributes":[{"name":"refStore","type":"Relationship","value":"urn:ngsi-ld:Store:001"}],"explicitAttrs":false},{"device_id":"lamp002","service":"openiot","service_path":"/","entity_name":"Thing:lamp002","entity_type":"Thing","transport":"HTTP","attributes":[],"lazy":[],"commands":[],"static_attributes":[]},{"device_id":"lamp003","service":"openiot","service_path":"/","entity_name":"Thing:lamp003","entity_type":"Thing","transport":"HTTP","attributes":[],"lazy":[],"commands":[],"static_attributes":[]},{"device_id":"lamp004","service":"openiot","service_path":"/","entity_name":"Thing:lamp004","entity_type":"Thing","transport":"HTTP","attributes":[],"lazy":[],"commands":[],"static_attributes":[]},{"device_id":"motion002","service":"openiot","service_path":"/","entity_name":"Thing:motion002","entity_type":"Thing","transport":"HTTP","attributes":[],"lazy":[],"commands":[],"static_attributes":[]},{"device_id":"motion003","service":"openiot","service_path":"/","entity_name":"Thing:motion003","entity_type":"Thing","transport":"HTTP","attributes":[],"lazy":[],"commands":[],"static_attributes":[]},{"device_id":"motion004","service":"openiot","service_path":"/","entity_name":"Thing:motion004","entity_type":"Thing","transport":"HTTP","attributes":[],"lazy":[],"commands":[],"static_attributes":[]},{"device_id":"door001","service":"openiot","service_path":"/","entity_name":"urn:ngsi-ld:Door:001","entity_type":"Door","endpoint":"http://iot-sensors:3001/iot/door001","polling":false,"transport":"HTTP","attributes":[{"object_id":"s","name":"state","type":"Text"}],"lazy":[],"commands":[{"object_id":"unlock","name":"unlock","type":"command"},{"object_id":"open","name":"open","type":"command"},{"object_id":"close","name":"close","type":"command"},{"object_id":"lock","name":"lock","type":"command"}],"static_attributes":[{"name":"refStore","type":"Relationship","value":"urn:ngsi-ld:Store:001"}],"explicitAttrs":false},{"device_id":"lamp001","service":"openiot","service_path":"/","entity_name":"Thing:lamp001","entity_type":"Thing","transport":"HTTP","attributes":[],"lazy":[],"commands":[],"static_attributes":[]}]}

How can I enable provisioning of lamp001 (request 10)?

jason-fox commented 1 year ago

DUPLICATE_DEVICE_ID would indicate that the device has already been correctly provisioned. Deleting it will remove it as you can see the count is reduced. What I suspect is happened here, is that the Lamp was ON and streaming data, once it was deleted the next request from the lamp (which had a known API Key) recreated the lamp as an anonymous device. IIRC if the tutorial is running and any actuation has occurred dummy measures are sent periodically once a minute.

The key takeaway here is not to send measures to the IoT Agent until all devices are fully provisioned.

hsakamoto123 commented 1 year ago

Thank you Jason Fox. After ./services start I was able to get it to work by only provisioning 4 devices.