Skip to content

Commit a6dd6b3

Browse files
committed
docs: Document commands to de-register entities #2700
1 parent 0581a31 commit a6dd6b3

File tree

2 files changed

+104
-0
lines changed

2 files changed

+104
-0
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
---
2+
title: Deregister entities
3+
tags: [Child-Device, Registration]
4+
sidebar_position: 1
5+
description: Deregister child devices and services from %%te%%
6+
---
7+
8+
# Deregister entities
9+
10+
All the entities (devices and services) registered with %%te%% are stored with the MQTT broker as retained messages,
11+
with their metadata spread across multiple topics.
12+
For example, for a child device `child01`, the registration message is stored on the `te/device/child01//` topic,
13+
its twin data is stored across several `te/device/child01///twin/<twin-data-type>` topics,
14+
its command metadata stored across several `te/device/child01///cmd/<cmd-type>` topics and so on.
15+
16+
On top of that, when a device has services associated with it, or has nested child devices,
17+
they all have their own respective registration topics and other metadata topics.
18+
So, deregistering a device involves deregistering itself, its metadata and
19+
the complete entity hierarchy that is associated with it.
20+
21+
Even though %%te%% doesn't provide a direct API for this yet, this can be easily be done using third-party tools
22+
like `mosquitto_sub` that supports clearing multiple retained messages together using the `--remove-retained` option.
23+
24+
## Deregister a child device and its services
25+
26+
When the topic ids of the devices and services follow the default topic scheme,
27+
which maintains the service topic ids (`te/device/<device-id>/service/<service-id>`)
28+
directly under the device topic id (`te/device/<device-id>//`) in the hierarchy,
29+
a child device along with all of its services can be deleted as follows:
30+
31+
```sh
32+
mosquitto_sub --remove-retained -W 3 -t "te/device/child01/+/+/#"
33+
```
34+
35+
* The topic filter `te/device/child01/+/+` covers the registration messages of the device and all of its services,
36+
and the trailing `#` covers their their metadata messages as well.
37+
* The `--remove-retained` clears all the retained messages matching that topic filter.
38+
Running the same command without the `remove-retained` option shows the list of messages
39+
that would be cleared with this command, which can be used for dry runs before the entities are really removed.
40+
* The `-W 3` option is used to stop the command after a timeout period of 3 seconds, without which the command will not exit.
41+
Adjust this timeout value based on the number of entities in your deployment.
42+
43+
:::note
44+
The entities in the cloud must also be removed separately as deregistrations on the device
45+
are not propagated to the cloud.
46+
The Cumulocity mapper must also be restarted if the same entity is to be recreated after deregistration.
47+
:::
48+
49+
A single service of a device (main or child), can be deregistered as follows:
50+
51+
```sh
52+
mosquitto_sub --remove-retained -W 3 -t "te/device/main/service/service01/#"
53+
```
54+
55+
All the services associated to a device can be deregistered together, as follows:
56+
57+
```sh
58+
mosquitto_sub --remove-retained -W 3 -t "te/device/child01/service/+/#"
59+
```
60+
61+
:::note
62+
De-registering parent and child entities together with a single command only works
63+
when the parent and children are hierarchically linked via the topics, which can be queried with a single topic filter,
64+
as in the case of services while following the default topic scheme.
65+
While using custom topic schemes, that do not maintain the same topic prefix for a device and its services,
66+
querying and deregistering them may not be a on-liner as in the examples listed above.
67+
:::
68+
69+
## Deregister all child devices and services
70+
71+
All the child devices and services can be deregistered using a wildcard topic filter that covers all the entities
72+
combined with a topic exclusion filter for the main device, as follows:
73+
74+
```sh
75+
mosquitto_sub -v -t "te/device/+/#" -T "te/device/main/#"
76+
```
77+
78+
## Unsupported cases
79+
80+
While using the default topic scheme, the following use-cases are not supported as it's not possible to define
81+
wildcard topic filters for the same, as the topic scheme does not capture the parent-child relationship of devices:
82+
83+
* Deregister all child devices of a given device
84+
* Deregister the entire nested child device hierarchy of a device
85+
86+
## Custom topic schemes
87+
88+
Most of the commands listed above are applicable only when the default topic scheme is used.
89+
The same rules, especially the ones involving multiple entities, do not apply to custom topic schemes,
90+
as different entities would be linked differently based on the topic scheme that's used.
91+
The filtering capabilities would also very from scheme to scheme.
92+
As long as you can define topic filters to select individual entities or a set of entities,
93+
the same can be used for deregistering as well.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
title: Registration
3+
tags: [Registration, Deregistration]
4+
sidebar_position: 11
5+
---
6+
7+
import DocCardList from '@theme/DocCardList';
8+
9+
Managing registration and deregistration of child devices and services on %%te%%.
10+
11+
<DocCardList />

0 commit comments

Comments
 (0)