thin-edge / thin-edge.io

The open edge framework for lightweight IoT devices
https://thin-edge.io
Apache License 2.0
221 stars 54 forks source link

tedge-mapper-c8y: registered child-device does not receive data anymore after restart #3051

Closed ButKor closed 2 months ago

ButKor commented 2 months ago

Describe the bug I have a connected thin-edge.io instance and registered a child-device via a dedicated registration message. Everything works fine - until I restart tedge-mapper-c8y. After restart the child-device does not receive data anymore in Cumulocity.

To Reproduce

$ tedge --version
tedge 1.2.0
$ sudo tedge config set c8y.url example.eu-latest.cumulocity.com
$ sudo tedge config set c8y.entity_store.auto_register false
$ sudo tedge cert create --device-id "my-tedge-main-device"
$ sudo tedge cert upload c8y --user "john.doe"
...
$ sudo tedge connect c8y
...
$ tedge mqtt pub "te/device/main///e/heartbeat" '{ "text": "Heartbeat event" }' # works fine
$ tedge mqtt pub "te/device/my-child-1//" '{
    "@type": "child-device",
    "@id": "my-child-1-id",
    "name": "my-child-1-name",
    "type": "my-child-1-type"
}' # successfully created a Cumulocity Device with name=my-child-1-name, type=my-child-1-type, external-id (c8y_Serial) = my-child-1-id
$ tedge mqtt pub "te/device/my-child-1///e/heartbeat" '{ "text": "Heartbeat event" }' # works fine
$ sudo systemctl restart tedge-mapper-c8y
$ tedge mqtt pub "te/device/my-child-1///e/heartbeat" '{ "text": "Heartbeat event" }' # nothing received by the platform anymore

Expected behavior Expected to still send events towards the platform via tedge mqtt pub "te/device/my-child-1///e/heartbeat" '{ "text": "Heartbeat event" }' after restart of tedge-mapper-c8y.

Environment (please complete the following information):

Additional context

After restart, same event:

$ mosquitto_sub -t '#' -h localhost -v
te/device/my-child-1///e/heartbeat { "text": "Heartbeat event" }

Not seeing an error - missing the event towards c8y/event/events/create though.

Is that a bug - or am I missing a step here?

reubenmiller commented 2 months ago

@ButKor registration messages need to be published with the retain flag so they are persisted on the mqtt broker, so I’m pretty sure that is why the mapper does not know of the child device after being restarted.

So retest with the retain flag (as it might be something else)

Update (for other people)

Below is an example of publishing a registration message with the retail flag (using tedge mqtt pub):

tedge mqtt pub -r "te/device/my-child-1//" '{
    "@type": "child-device",
    "@id": "my-child-1-id",
    "name": "my-child-1-name",
    "type": "my-child-1-type"
}'
ButKor commented 2 months ago

Thanks, that explains it! Retested and adding -r to registration message solved my problem.