Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can’t[Provisioning a Smart Lamp] #32

Open
hsakamoto123 opened this issue Dec 29, 2022 · 1 comment
Open

Can’t[Provisioning a Smart Lamp] #32

hsakamoto123 opened this issue Dec 29, 2022 · 1 comment

Comments

@hsakamoto123
Copy link

hsakamoto123 commented Dec 29, 2022

Execution of the tutorial command results in an error.

$ 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",
>       "protocol": "PDI-IoTA-UltraLight",
>       "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: e2dfb1c9-f8fb-458c-8f53-ebc569e4fa87
Content-Type: application/json; charset=utf-8
Content-Length: 108
ETag: W/"6c-MXV0ASHmZcVgSm+giF5KNzT8oKg"
Date: Thu, 29 Dec 2022 13:41:59 GMT
Connection: keep-alive
Keep-Alive: timeout=5

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

The details of lamp001 at this time are as follows.

$ curl -iX GET \
>   'http://localhost:4041/iot/devices/lamp001' \
>   -H 'Content-Type: application/json' \
>   -H 'fiware-service: openiot' \
>   -H 'fiware-servicepath: /'
HTTP/1.1 200 OK
X-Powered-By: Express
Fiware-Correlator: 9137758e-ffec-4183-b2cb-64764bac4582
Content-Type: application/json; charset=utf-8
Content-Length: 170
ETag: W/"aa-DtkbAvlQAzPkTzVDNEWEFDN2uS0"
Date: Thu, 29 Dec 2022 14:23:32 GMT
Connection: keep-alive
Keep-Alive: timeout=5

{"device_id":"lamp001","service":"openiot","service_path":"/","entity_name":"Thing:lamp001","entity_type":"Thing","transport":"HTTP","commands":[],"static_attributes":[]}

I deleted lamp001 and tried again but got the same error.

$ 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: 13850b76-210f-4fea-b43f-cd6922988d06
Date: Thu, 29 Dec 2022 14:21:27 GMT
Connection: keep-alive
Keep-Alive: timeout=5
-----
$ curl -iX GET \
>   'http://localhost:4041/iot/devices/lamp001' \
>   -H 'Content-Type: application/json' \
>   -H 'fiware-service: openiot' \
>   -H 'fiware-servicepath: /'
HTTP/1.1 404 Not Found
X-Powered-By: Express
Fiware-Correlator: 7969f9a8-8126-42c3-adf9-4e6ab03075c7
Content-Type: application/json; charset=utf-8
Content-Length: 75
ETag: W/"4b-K4b3wKcdA3xs//EOZUi47GwR6k0"
Date: Thu, 29 Dec 2022 14:21:52 GMT
Connection: keep-alive
Keep-Alive: timeout=5

{"name":"DEVICE_NOT_FOUND","message":"No device was found with id:lamp001"}

Please let me know how I can avoid this.

Added 2023/1/4:
I don't know if it's directly related, but the container log has the following error.

{"log":"time=2023-01-04T14:15:51.229Z | lvl=ERROR | corr=ebf236d8-e24d-4dbd-9cfc-20fd509c4213 | trans=ebf236d8-e24d-4dbd-9cfc-20fd509c4213 | op=IOTAUL.AMQP.Binding | from=n/a | srv=n/a | subsrv=n/a | msg=connect ECONNREFUSED 127.0.0.1:5672 | comp=IoTAgent\n","stream":"stdout","time":"2023-01-04T14:15:51.234099317Z"}
@hsakamoto123
Copy link
Author

I was able to avoid it in the same way as the issue answer below.
However, if you follow the steps in the tutorial in order, this event will occur.
Therefore, I would like to change the order of the tutorials or add a note of caution.

FIWARE/tutorials.IoT-Agent-JSON#7

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](https://iotagent-node-lib.readthedocs.io/en/latest/getting-started.html#receiving-a-measure-from-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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant