Building and Running Example Application
Working Project with µC/TCP-IP
The first step before including µC/MQTT-client is to have a working project with µC/TCP-IP. As previously mentioned, Micriµm may offer an example with the µC/OS-III kernel, µC/TCP-IP and even µC/MQTT-client for many evalboards.
If no project with µC/TCP-IP is available for your platform, you should follow the µC/TCP-IP Getting Started Guide to ensure you have a working project before installing µC/MQTT-client. Then you can follow the steps to build and run your first µC/MQTT-client sample application shown below.
Including µC/MQTT-client Stack Source Code
All the files in the "Source" folder of the "Client" directory must be added to your project tree.
Furthermore, all files in the "Common" folder under the "MQTT" parent directory must be added to your project tree.
Configuring Compiler settings
Add the following include paths to your project’s C compiler settings:
\Micrium\Software\uC-MQTT
Copying and Modifying Template Files
Copy the files from the uC-MQTT-client configuration folder (uC-MQTT/Client/Cfg
) into your application folder.
Adding µC/MQTT-client Example Application Code
The code below presents a simple MQTT client application where the µC/MQTT-client suite is initialized. Depending on the chosen example, this initialization call will also start publishing on a given topic, subscribe to a topic, do both, etc.
It is also assumed that all prerequisite modules have been initialized before calling the µC/MQTT-client example function.
The function AppMQTTc_Init()
is an example function that can be retrieve in the Examples directory of µC/MQTT-client.
#include "app_mqtt-c.h" [...] static void AppTaskStart (void *p_arg) { /* Initialize BSP */ /* Initialize CPU */ /* Initialize Memory */ /* Initialize TCP-IP */ /* Initialize DNSc if necessary */ success = AppMQTTc_Init(); if (success == DEF_FAIL) { printf("Error with MQTTc Initialization.\n"); CPU_SW_EXCEPTION(;); } }