Skip to content

Commit a8d7d12

Browse files
simensrostadjorgenmk
authored andcommitted
samples: net: MQTT: Documentation update
Explain why sample doesnt have a main function. Signed-off-by: Simen S. Røstad <[email protected]>
1 parent 03355c3 commit a8d7d12

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

samples/net/mqtt/doc/architecture.rst

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,27 @@ See the :file:`src/common/channel.c` and :file:`src/common/channel.h` files for
2323

2424
.. note::
2525
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.
2630
To follow the typical flow of the application, see the :ref:`mqtt_sample_sequence_diagram` section.
2731

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+
2847
Modules
2948
*******
3049

@@ -60,10 +79,10 @@ The following code snippet shows how a module thread polls for incoming messages
6079
Especially if the module thread can block for some time.
6180
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``.
6281

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.
6483
The difference between a listener and a subscriber is that listeners do not require a dedicated thread to process incoming messages.
6584
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:
6786

6887
.. code-block:: c
6988

0 commit comments

Comments
 (0)