This section describes the examples application provided for the MQTT Client module of Micrium OS.
MQTT Client Initialization Example
Description
This is a generic example that shows how to initialize the MQTT client module. It accomplishes the following tasks:
- Change default task's stacks size, if specified by the example configuration
- Initialize the MQTTClient module
- Change default the task's priority, if specified by the example configuration
Configuration
Mandatory
The following #define
must be added in ex_description.h to allow other examples to initialize the HTTP Server module correctly:
#define | Description |
---|---|
EX_MQTT_CLIENT_INIT_AVAIL | Lets the upper example layer know that the Network Initialization example is present and must be called by other examples. |
Location
/examples/net/mqtt/ex_mqtt_client_init.c
/examples/net/mqtt/ex_mqtt_client.h
API
API | Description |
---|---|
Ex_MQTT_Client_Init() | Initialize the MQTT Client stack for the example application. |
Notes
None.
MQTT Client Connect Example
Description
This is a generic example for the MQTT Client module. It shows how to connect to a broker.
Configuration
Optional
The following #define
can be added to ex_description.h
, as described in Example Applications section, to change default configuration value used by the example:
#define | Default value | Description |
---|---|---|
EX_MQTTc_BROKER_NAME | "mqtt.micrium.com" | Specify the broker hostname |
EX_MQTTc_USERNAME | "micrium" | Specify the username |
EX_MQTTc_PASSWORD | "micrium" | Specify the password |
EX_MQTTc_CLIENT_ID_NAME | "micrium-example-basic" | Specify another client ID |
EX_MQTTc_MSG_LEN_MAX | 128 | Specify the message maximum length |
EX_TRACE | printf(__VA_ARGS__) | Specify where to output information about the example |
Location
/examples/net/mqtt/ex_mqtt_client_connect.c
/examples/net/mqtt/ex_mqtt_client.h
API
API | Description |
---|---|
Ex_MQTT_Client_Connect() | Connect the client to the broker. |
Notes
None.
MQTT Client Publish Example
Description
This is a generic example for the MQTT Client module. It accomplishes the following tasks:
- Connect to a broker
- Publish message on a topic
Configuration
Optional
The following #define
can be added to ex_description.h, as described in Example Applications section, to change default configuration value used by the example:
#define | Default value | Description |
---|---|---|
EX_MQTTc_BROKER_NAME | "mqtt.micrium.com" | Specify the broker hostname |
EX_MQTTc_USERNAME | "micrium" | Specify the username |
EX_MQTTc_PASSWORD | "micrium" | Specify the password |
EX_MQTTc_CLIENT_ID_NAME | "micrium-example-publish" | Specify another client ID |
Location
/examples/net/mqtt/ex_mqtt_client_publish.c
/examples/net/mqtt/ex_mqtt_client.h
API
API | Description |
---|---|
Ex_MQTT_Client_Publish() | Open a connection and publish message from the callback |
Notes
None.
MQTT Client Subscribe Example
Description
This is a generic example for the MQTT Client module. It accomplishes the following tasks:
- Connect to a broker
- Subscribe to a topic
Configuration
Optional
The following #define
can be added to ex_description.h, as described in Example Applications section, to change default configuration value used by the example:
#define | Default value | Description |
---|---|---|
EX_MQTTc_BROKER_NAME | "mqtt.micrium.com" | Specify the broker hostname |
EX_MQTTc_USERNAME | "micrium" | Specify the username |
EX_MQTTc_PASSWORD | "micrium" | Specify the password |
EX_MQTTc_CLIENT_ID_NAME | "micrium-example-sub" | Specify another client ID |
Location
/examples/net/mqtt/ex_mqtt_client_subscribe.c
/examples/net/mqtt/ex_mqtt_client.h
API
API | Description |
---|---|
| Open a connection and subscribe to a topic. |
Notes
None.
MQTT Client Echo Example
Description
This is a generic example for the MQTT Client module. It accomplishes the following tasks:
- Connect to a broker
- Subscribe to a topic
- Publish on the subscribed topic
Configuration
Optional
The following #define
can be added to ex_description.h, as described in Example Applications section, to change default configuration value used by the example:
#define | Default value | Description |
---|---|---|
EX_MQTTc_BROKER_NAME | "mqtt.micrium.com" | Specify the broker hostname |
EX_MQTTc_USERNAME | "micrium" | Specify the username |
EX_MQTTc_PASSWORD | "micrium" | Specify the password |
EX_MQTTc_CLIENT_ID_NAME | "micrium-example-echo" | Specify another client ID |
Location
/examples/net/mqtt/ex_mqtt_client_echo.c
/examples/net/mqtt/ex_mqtt_client.h
API
API | Description |
---|---|
Ex_MQTT_Client_Echo() | Open a connection and publish message from the callback and receive message using subscribe. |
Notes
None.