You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: samples/net/mqtt/doc/architecture.rst
+21-2Lines changed: 21 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,8 +23,27 @@ See the :file:`src/common/channel.c` and :file:`src/common/channel.h` files for
23
23
24
24
.. note::
25
25
The sample does not include a :file:`main.c` file.
26
+
Instead, the application uses a modular architecture where each module defines its own thread using the :c:macro:`K_THREAD_DEFINE` macro.
27
+
This approach eliminates the need for a traditional ``main()`` function and allows each module to initialize and run independently.
28
+
The modules communicate with each other through the :ref:`zbus` message passing system.
29
+
This creates a loosely coupled, event-driven architecture.
26
30
To follow the typical flow of the application, see the :ref:`mqtt_sample_sequence_diagram` section.
27
31
32
+
Application Entry Points
33
+
************************
34
+
35
+
Instead of a single ``main()`` function, the MQTT sample uses multiple entry points:
36
+
37
+
* Trigger Module - Creates a thread that periodically sends trigger messages and handles button presses.
38
+
* Sampler Module - Creates a thread that responds to trigger messages by sampling data.
39
+
* Transport Module - Creates a thread that manages MQTT connections and handles message publishing/subscribing.
40
+
* Network Module - Creates a thread that manages network connectivity (LTE or Wi-Fi®).
41
+
* LED Module - Uses a listener callback (no dedicated thread) to control LEDs based on network status.
42
+
* Error Module - Uses a listener callback (no dedicated thread) to handle fatal errors.
43
+
44
+
Each module's thread is defined using :c:macro:`K_THREAD_DEFINE` and starts automatically during system initialization.
45
+
This distributed approach provides better modularity, easier testing, and clearer separation of concerns compared to a monolithic ``main()`` function.
46
+
28
47
Modules
29
48
*******
30
49
@@ -60,10 +79,10 @@ The following code snippet shows how a module thread polls for incoming messages
60
79
Especially if the module thread can block for some time.
61
80
To increase the message queue associated with a subscriber, increase the value of the corresponding Kconfig option, ``CONFIG_MQTT_SAMPLE_SAMPLER_MESSAGE_QUEUE_SIZE`` or ``CONFIG_MQTT_SAMPLE_TRANSPORT_MESSAGE_QUEUE_SIZE``.
62
81
63
-
Modules that are setup as listeners have dedicated callbacks that are invoked every time there is a change to an observing channel.
82
+
Modules that are set up as listeners have dedicated callbacks that are invoked every time there is a change to an observing channel.
64
83
The difference between a listener and a subscriber is that listeners do not require a dedicated thread to process incoming messages.
65
84
The callbacks are called in the context of the thread that published the message.
66
-
The following code snippet shows how a listener is setup in order to listen to changes to the ``NETWORK`` channel:
85
+
The following code snippet shows how a listener is set up in order to listen to changes to the ``NETWORK`` channel:
0 commit comments