Skip to content

Commit 50b841c

Browse files
authored
Merge pull request #1494 from jona42-ui/docs/mqtt-qos-retain
docs(binding-mqtt): Document QoS and retain form parameters
2 parents 7bda06d + 82c12cd commit 50b841c

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

packages/binding-mqtt/README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,62 @@ try {
176176
}
177177
```
178178

179+
### MQTT Form Parameters: QoS and Retain
180+
181+
The MQTT binding supports Quality of Service (QoS) and message retention through form parameters. These parameters control how messages are delivered and stored by the broker.
182+
183+
#### Quality of Service (QoS)
184+
185+
QoS determines the guarantee level for message delivery:
186+
187+
- `mqv:qos` = `"0"` (default): At most once - messages are delivered with no guarantee
188+
- `mqv:qos` = `"1"`: At least once - messages are guaranteed to be delivered at least once
189+
- `mqv:qos` = `"2"`: Exactly once - messages are guaranteed to be delivered exactly once
190+
191+
When a consumer reads or writes to a Thing, it will use the QoS level specified in the form. For example:
192+
193+
```js
194+
{
195+
"properties": {
196+
"temperature": {
197+
"type": "number",
198+
"forms": [
199+
{
200+
"href": "mqtt://broker.example.com/sensor/temperature",
201+
"mqv:qos": "1"
202+
}
203+
]
204+
}
205+
}
206+
}
207+
```
208+
209+
#### Message Retention
210+
211+
The `mqv:retain` parameter controls whether the broker retains the last message published to a topic:
212+
213+
- `mqv:retain` = `true`: The broker stores the last message and sends it to new subscribers
214+
- `mqv:retain` = `false` (default): Messages are not retained
215+
216+
This is useful for properties that represent state, ensuring new consumers immediately receive the current value:
217+
218+
```js
219+
{
220+
"properties": {
221+
"status": {
222+
"type": "string",
223+
"forms": [
224+
{
225+
"href": "mqtt://broker.example.com/device/status",
226+
"mqv:qos": "1",
227+
"mqv:retain": true
228+
}
229+
]
230+
}
231+
}
232+
}
233+
```
234+
179235
### Hosting your own MQTT Broker
180236

181237
Instead of connecting to an external MQTT broker, you can host your own MQTT broker within your node-wot application by setting the `selfHost` option to `true`. This is useful for testing, development, or when you want to run a self-contained application.

0 commit comments

Comments
 (0)