Skip to content

Commit bd0f58f

Browse files
committed
mqtt: README.md updating
1 parent e966d29 commit bd0f58f

1 file changed

Lines changed: 30 additions & 15 deletions

File tree

README.md

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22

33
## Description
44

5-
MQTT module for the [OpenDAQ SDK](https://github.com/openDAQ/openDAQ). The module is designed for software communication via the *MQTT 3.1.1* protocol using an external broker. It allows publishing and subscribing to openDAQ signal data over MQTT. The module consists of four key openDAQ components: the *MQTT device* and its nested function blocks — the *publisher* (**@publisherMqttFb**), the *raw subscriber* (**@rawMqttFb**), and the *JSON subscriber* (**@jsonMqttFb**).
5+
MQTT module for the [OpenDAQ SDK](https://github.com/openDAQ/openDAQ). The module is designed for software communication via the *MQTT 3.1.1* protocol using an external broker. It allows publishing and subscribing to openDAQ signal data over MQTT. The module consists of five key openDAQ components: the *MQTT root function block* (**rootMqttFb**) and its nested function blocks — the *publisher* (**publisherMqttFb**) with its nested block *JSON decoder* (**jsonDecoderMqttFb**) , the *raw subscriber* (**rawMqttFb**), and the *JSON subscriber* (**jsonMqttFb**).
66

77
### Functional
88
- Connecting to an MQTT broker;
99
- Publishing openDAQ signals as MQTT messages (*publisher FB*);
10-
- Subscribing to MQTT topics and converting incoming messages into openDAQ signals (*raw FB and JSON FB*);
10+
- Subscribing to MQTT topics and converting incoming messages into openDAQ signals (*raw FB and JSON FB + JSON decoder FB*);
1111
- Support for multiple message types and formats for both publishing and subscribing;
1212
- A set of examples and *gtests* for verifying functionality.
1313

1414
### Key components
15-
1) **MQTT root Function Block (@rootMqttFb)**:
15+
1) **MQTT root Function Block (rootMqttFb)**:
1616
- **Where**: *mqtt_streaming_module/src/mqtt_root_fb_impl.cpp, include/mqtt_streaming_module/...*
1717
- **Purpose**: Represents the MQTT broker as an openDAQ function block - the connection point through which function blocks are created.
1818
- **Main properties:**
@@ -21,7 +21,7 @@ MQTT module for the [OpenDAQ SDK](https://github.com/openDAQ/openDAQ). The modul
2121
- *MqttUsername* (string) — Username for MQTT broker authentication. By default, it is empty.
2222
- *MqttPassword* (string) — Password for MQTT broker authentication. By default, it is empty.
2323
- *ConnectTimeout* (integer) — Timeout in milliseconds for the initial connection to the MQTT broker. If the connection fails, an exception is thrown. By default, it is set to *3000 ms*.
24-
2) **Publisher MQTT Function Block (@publisherMqttFb)**:
24+
2) **Publisher MQTT Function Block (publisherMqttFb)**:
2525
- **Where**: *include/mqtt_streaming_module/mqtt_publisher_fb_impl.h, src/mqtt_publisher_fb_impl.cpp*
2626
- **Purpose**: Publishes openDAQ signal data to MQTT topics. There are **four** general data publishing schemes:
2727
1) One MQTT message per signal / one message per sample / one topic per signal / one timestamp for each sample. Example: *{"AI0": 1.1, "timestamp": 1763716736100000}*
@@ -37,6 +37,7 @@ MQTT module for the [OpenDAQ SDK](https://github.com/openDAQ/openDAQ). The modul
3737
- **Main properties**:
3838
- *TopicMode* (list) — Selects whether to publish all signals to separate MQTT topics (one per signal, *single-topic mode*) or to a single topic (*multiple-topic mode*), one for all signals. Choose *0* for *single-topic* mode and *1* for *multiple-topic* mode. By default, it is set to *single-topic* mode.
3939
- *MqttQoS* (integer) — MQTT Quality of Service level. It can be *0* (at most once), *1* (at least once), or *2* (exactly once). By default, it is set to *1*.
40+
- *Topic* (string) — Topic name for publishing in multiple-topic mode. If left empty, the Publisher's *Global ID* is used as the topic name.
4041
- *SharedTimestamp* (bool) — Enables the use of a shared timestamp for all signals when publishing in *multiple-topic* mode. By default, it is set to *false*.
4142
- *GroupValues* (bool) — Enables the use of a sample pack for a signal when publishing in *single-topic* mode. By default, it is set to *false*.
4243
- *UseSignalNames* (bool) — Uses signal names as JSON field names instead of Global IDs. By default, it is set to *false*.
@@ -50,18 +51,22 @@ MQTT module for the [OpenDAQ SDK](https://github.com/openDAQ/openDAQ). The modul
5051
4) *TopicMode(1), SharedTimestamp(true), GroupValues(false)*;
5152

5253

53-
3) **Raw MQTT Function Block (@rawMqttFb)**:
54+
3) **Raw MQTT Function Block (rawMqttFb)**:
5455

5556
- **Where**: *include/mqtt_streaming_module/mqtt_raw_receiver_fb_impl.h, src/mqtt_raw_receiver_fb_impl.cpp*
5657
- **Purpose**: Subscribes to raw MQTT messages and converts them into openDAQ signals (binary data) without any parsing — suitable for binary/unstructured messages or simple numeric values.
5758
- **Main properties**:
58-
- *SignalList* (list of strings) — List of MQTT topics to subscribe to for receiving raw binary data.
59+
- *Topic* (string) — MQTT topic to subscribe to for receiving raw binary data.
60+
- *MqttQoS* (integer) — MQTT Quality of Service level. It can be *0* (at most once), *1* (at least once), or *2* (exactly once). By default, it is set to *1*.
5961

60-
4) **JSON MQTT Function Block (@jsonMqttFb)**:
62+
4) **JSON MQTT Function Block (jsonMqttFb)**:
6163
- **Where**: *include/mqtt_streaming_module/mqtt_json_receiver_fb_impl.h, src/mqtt_json_receiver_fb_impl.cpp*
62-
- **Purpose**: Subscribes to MQTT topics, extracts values and timestamps from MQTT JSON messages, and converts them into openDAQ signal data samples.
64+
- **Purpose**: Subscribes to MQTT topics, extracts values and timestamps from MQTT JSON messages via nested *JSON decoder MQTT Function Blocks*.
6365
- **Main properties**:
64-
- *SignalList* (string) — **JSON configuration string** that defines the list of MQTT topics and the corresponding signals to subscribe to. A typical string structure:
66+
- *Topic* (string) — MQTT topic to subscribe to for receiving JSON data.
67+
- *MqttQoS* (integer) — MQTT Quality of Service level. It can be *0* (at most once), *1* (at least once), or *2* (exactly once). By default, it is set to *1*.
68+
- *JsonConfigFile* (string) — path to file with **JSON configuration string**. See the *JsonConfig* property for more details. This property could be set only at creation. It is not visible.
69+
- *JsonConfig* (string) — **JSON configuration string** that defines the MQTT topic and the corresponding signals to subscribe to. This property could be set only at creation. It is not visible. A typical string structure:
6570
```json
6671
{
6772
"<topic>":[
@@ -71,8 +76,8 @@ MQTT module for the [OpenDAQ SDK](https://github.com/openDAQ/openDAQ). The modul
7176
"Timestamp":"<field_name_in_JSON_MQTT_message_for_extracting_sample_timestamp>",
7277
"Unit":[
7378
"<unit_symbol>",
74-
"<unit_name>",
75-
"<unit_quantity>"
79+
"<unit_name>", // is not used
80+
"<unit_quantity>" // is not used
7681
]
7782
}
7883
},
@@ -112,11 +117,21 @@ MQTT module for the [OpenDAQ SDK](https://github.com/openDAQ/openDAQ). The modul
112117
]
113118
}
114119
```
115-
In this example, the *JSON MQTT Function Block* creates 3 signals, subscribes to the *"/mirip/UNet3AC2/sensor/data"* topic, and extracts 3 signal samples from each message (one sample per signal). The signals are named *“temp”*, *“humidity”*, and *“tds”*. The *“temp”* signal is created with a domain signal because the *“Timestamp”* field is present. Each domain-signal sample is extracted from the *“ts”* field of the JSON MQTT message. The value of the *“ts”* field (the timestamp field) may be in **ISO8601** format or **Unix epoch time** in seconds, milliseconds, or microseconds. The value of the *“temp”* signal sample is extracted from the *“temp”* field of the JSON message. The unit of the values is “°C”.
120+
In this example, the *JSON MQTT Function Block* creates 3 nested *jsonDecoderMqttFb*, subscribes to the *"/mirip/UNet3AC2/sensor/data"* topic, and extracts 3 signal samples from each message (one sample per *jsonDecoderMqttFb*). The signals are named *“temp”*, *“humidity”*, and *“tds”*. The *“temp”* signal is created with a domain signal because the *“Timestamp”* field is present. Each domain-signal sample is extracted from the *“ts”* field of the JSON MQTT message. The value of the *“ts”* field (the timestamp field) may be in **ISO8601** format or **Unix epoch time** in seconds, milliseconds, or microseconds. The value of the *“temp”* signal sample is extracted from the *“temp”* field of the JSON message. The unit of the values is “°C”.
116121
Example of JSON MQTT message for this configuration:
117122
```json
118123
{"ts":"2025-10-08 20:35:43", "bdn":"SanbonFishTank3", "temp":27.20,"humi":72.40, "tds_value":275.22, "fan_status":"off", "auto_mode":"on", "fan_comp":"26.3", "humi_comp":"55"}
119124
```
125+
126+
5) **JSON decoder MQTT Function Block (jsonDecoderMqttFb)**:
127+
128+
- **Where**: *include/mqtt_streaming_module/mqtt_json_decoder_fb_impl.h, src/mqtt_json_decoder_fb_impl.cpp*
129+
- **Purpose**: To parse JSON string data to extract a value and a timestamp, and to send data and domain samples based on this data.
130+
- **Main properties**:
131+
- *ValueName* (string) — indicates which JSON field contains the sample value.
132+
- *TimestampName* (string) — indicates which JSON field contains the timestamp.
133+
- *Unit* (string) — describes the unit symbol of the decoded signal value.
134+
- *SignalName* (string) — specifies the name to assign to the signal created by a *jsonDecoderMqttFb*.
120135
---
121136

122137
## Building MQTTStreamingModule
@@ -164,13 +179,13 @@ cmake --build .
164179
## Examples
165180

166181
There are 3 example C++ application:
167-
- **custom-mqtt-sub** - demonstrates how to work with the *JSON MQTT FB*. The application creates an *MQTT root FB* and a *JSON MQTT FB* to receive JSON MQTT messages, parse them, and create openDAQ signals to send the parsed data. The application also creates *packet readers* for all FB signals and prints the samples to standard output. The *SignalList* property of the JSON MQTT FB is set to the value read from a file whose path is provided as a command-line argument when the application starts (see the **Key components** section). Usage:
182+
- **custom-mqtt-sub** - demonstrates how to work with the *JSON receiver MQTT FB* and *JSON decoder MQTT FB*. The application creates an *MQTT root FB* and a *JSON MQTT FB* to receive JSON MQTT messages, parse them, and create openDAQ signals to send the parsed data. The application also creates *packet readers* for all FB signals and prints the samples to standard output. The *JsonConfigFile* property of the JSON MQTT FB is set to the value of path whose is provided as a command-line argument when the application starts (see the **Key components** section). Usage:
168183
```bash
169184
./custom-mqtt-sub --address broker.emqx.io examples/custom-mqtt-sub/public-example0.json
170185
```
171-
- **raw-mqtt-sub** - demonstrates how to work with the *raw MQTT FB*. The application creates an *MQTT root FB* and a *raw MQTT FB* to receive MQTT messages and create openDAQ signals to send the data as binary packets. The application also creates packet readers for all FB signals and prints the binary packets as strings to standard output. The *SignalList* property of the raw MQTT FB is filled from the application arguments. Usage:
186+
- **raw-mqtt-sub** - demonstrates how to work with the *raw MQTT FB*. The application creates an *MQTT root FB* and a *raw MQTT FB* to receive MQTT messages and create openDAQ signals to send the data as binary packets. The application also creates packet readers for all FB signals and prints the binary packets as strings to standard output. The *Topic* property of the raw MQTT FB is filled from the application arguments. Usage:
172187
```bash
173-
./raw-mqtt-sub --address broker.emqx.io /agvstate /mirip/UNet3AC2/sensor/data
188+
./raw-mqtt-sub --address broker.emqx.io /mirip/UNet3AC2/sensor/data
174189
```
175190
- **ref-dev-mqtt-pub** - demonstrates how to work with the *publisher MQTT FB*. The application creates an *openDAQ ref-device* with four channels, an *MQTT root FB*, and a *publisher MQTT FB* to publish JSON MQTT messages with the channels’ data. The properties of the *publisher MQTT FB* are set according to the selected mode, which can be specified via the *--mode* option. Posible values are:
176191
- 0 - One MQTT message per signal / one message per sample / one topic per signal / one timestamp for each sample;

0 commit comments

Comments
 (0)