Examples Description
Initialization example
The file app_mqtt-c_init.c
shows the way to initialize the MQTT-client stack and all of the structure (MQTTc_CONN
, MQTTc_MSG
, etc) needed to be able to send a valid CONNECT
message to the server and know that the server has correctly received it.
On the broker side, nothing particular needs to be done. The server only needs to be up and running. If the server used displays when a device connects, it should show that a device is now connected.
Publish example
The file app_mqtt-c_publish.c
does everything the initialization example does and then sends a PUBLISH
message to the server, repeating it again and again.
On the broker side (or using a web client), subscribe to the topic defined by APP_MQTTc_DOMAIN_PUBLISH
(domain/publish_topic
, in the default example), to be able to see when the device publishes a message. The content of the message is defined by APP_MQTTc_PUBLISH_TEST_MSG
(test publish
, by default).
Subscribe example
The file app_mqtt-c_subscribe.c
does everything the initialization example does and then sends a SUBSCRIBE
message to the server, to be notified when a message is published on the topic defined by APP_MQTTc_DOMAIN_SUBSCRIBE
(domain/subscribe_topic
, in the default example).
On the broker side (or using a web client), publish to that same topic. The device will detect that it has received a PUBLISH
message and execute the AppMQTTc_OnPublishRxCallbackFnct
, where it will provide information about the message that has just been received.
Echo example
The file app_mqtt-c_echo.c
does everything the initialization example does and then subscribes to the APP_MQTTc_DOMAIN_SUBSCRIBE_LISTEN
topic (domain/listen
, in the default example). It will also publish statuses on APP_MQTTc_DOMAIN_PUBLISH_STATUS
(domain/status
, by default). Also, whenever the device is notified that a message has been received, it will echo that same message on the APP_MQTTc_DOMAIN_PUBLISH_ECHO
(domain/echo
, by default) topic. If the device has not completed the processing of the previous echo message, it will send a message on the status topic, telling that it is skipping this message.
On the broker side (or using a web client), subscribe to both the APP_MQTTc_DOMAIN_PUBLISH_STATUS
and APP_MQTTc_DOMAIN_PUBLISH_ECHO
topics, to interact with the device. Then, publish to the APP_MQTTc_DOMAIN_SUBSCRIBE_LISTEN
(domain/listen
) topic. The device will detect that it has received a PUBLISH
message, execute the AppMQTTc_OnPublishRxCallbackFnct
, where it will provide information about the message that has just been received and echo it to the echo topic.
N.B. Please note that this example is intended to demonstrate the capabilities of the MQTT-client stack, and that echoing every message is not something an application should normally do.