Files | Macros | Functions | Variables
SendDataOverMQTT

Demo application for using MQTT protocol. More...

+ Collaboration diagram for SendDataOverMQTT:

Files

file  AppController.c
 

Macros

#define APP_MQTT_DATA_BUFFER_SIZE   UINT32_C(256)
 
#define APP_TEMPERATURE_OFFSET_CORRECTION   (-3459)
 
#define BCDS_MODULE_ID   XDK_APP_MODULE_ID_APP_CONTROLLER
 
#define MQTT_CONNECT_TIMEOUT_IN_MS   UINT32_C(60000)
 
#define MQTT_PUBLISH_TIMEOUT_IN_MS   UINT32_C(20000)
 
#define MQTT_SUBSCRIBE_TIMEOUT_IN_MS   UINT32_C(20000)
 

Functions

void AppController_Init (void *cmdProcessorHandle, uint32_t param2)
 Gives control to the Application controller. More...
 
static void AppControllerEnable (void *param1, uint32_t param2)
 To enable the necessary modules for the application. More...
 
static void AppControllerFire (void *pvParameters)
 Responsible for controlling the send data over MQTT application control flow. More...
 
static void AppControllerSetup (void *param1, uint32_t param2)
 To setup the necessary modules for the application. More...
 
static Retcode_T AppControllerValidateWLANConnectivity (void)
 This will validate the WLAN network connectivity. More...
 
static void AppMQTTSubscribeCB (MQTT_SubscribeCBParam_T param)
 

Variables

static CmdProcessor_TAppCmdProcessor
 
static xTaskHandle AppControllerHandle = NULL
 
static uint32_t AppIncomingMsgCount = 0UL
 
static char AppIncomingMsgPayloadBuffer [APP_MQTT_DATA_BUFFER_SIZE]
 
static char AppIncomingMsgTopicBuffer [APP_MQTT_DATA_BUFFER_SIZE]
 
static MQTT_Connect_T MqttConnectInfo
 
static MQTT_Publish_T MqttPublishInfo
 
static MQTT_Setup_T MqttSetupInfo
 
static MQTT_Subscribe_T MqttSubscribeInfo
 
static Sensor_Setup_T SensorSetup
 
static WLAN_Setup_T WLANSetupInfo
 

Detailed Description

This example shows how to use the MQTT protocol to transfer the environmental data.

You need to add your WLAN-Credentials in AppController.h
When running the program keep the USB plugged in to the PC. You can see in the console output of the XDK-Workbench the content of the environmental data.

Macro Definition Documentation

#define APP_MQTT_DATA_BUFFER_SIZE   UINT32_C(256)

macro for data size of incoming subscribed and published messages

#define APP_TEMPERATURE_OFFSET_CORRECTION   (-3459)

Macro for static temperature offset correction. Self heating, temperature correction factor

#define BCDS_MODULE_ID   XDK_APP_MODULE_ID_APP_CONTROLLER
#define MQTT_CONNECT_TIMEOUT_IN_MS   UINT32_C(60000)

Macro for MQTT connection timeout in milli-second

#define MQTT_PUBLISH_TIMEOUT_IN_MS   UINT32_C(20000)

Macro for MQTT publication timeout in milli-second

#define MQTT_SUBSCRIBE_TIMEOUT_IN_MS   UINT32_C(20000)

Macro for MQTT subscription timeout in milli-second

Function Documentation

void AppController_Init ( void *  cmdProcessorHandle,
uint32_t  param2 
)

This is a template function where the user can write his custom application.

Refer interface header for description

+ Here is the call graph for this function:

static void AppControllerEnable ( void *  param1,
uint32_t  param2 
)
static
  • WLAN
  • ServalPAL
  • SNTP (if secure communication)
  • MQTT
  • Sensor
Parameters
[in]param1Unused
[in]param2Unused

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void AppControllerFire ( void *  pvParameters)
static
  • Synchronize SNTP time stamp for the system if MQTT communication is secure
  • Connect to MQTT broker
  • Subscribe to MQTT topic
  • Read environmental sensor data
  • Publish data periodically for a MQTT topic
Parameters
[in]pvParametersUnused

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void AppControllerSetup ( void *  param1,
uint32_t  param2 
)
static
  • WLAN
  • ServalPAL
  • SNTP (if secure communication)
  • MQTT
  • Sensor
Parameters
[in]param1Unused
[in]param2Unused

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static Retcode_T AppControllerValidateWLANConnectivity ( void  )
static

If there is no connectivity then it will scan for the given network and try to reconnect

Returns
RETCODE_OK on success, or an error code otherwise.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void AppMQTTSubscribeCB ( MQTT_SubscribeCBParam_T  param)
static

Variable Documentation

CmdProcessor_T* AppCmdProcessor
static

Handle to store the main Command processor handle to be used by run-time event driven threads

xTaskHandle AppControllerHandle = NULL
static

OS thread handle for Application controller to be used by run-time blocking threads

uint32_t AppIncomingMsgCount = 0UL
static

Incoming message count

char AppIncomingMsgPayloadBuffer[APP_MQTT_DATA_BUFFER_SIZE]
static

Incoming message payload buffer

char AppIncomingMsgTopicBuffer[APP_MQTT_DATA_BUFFER_SIZE]
static

Incoming message topic buffer

MQTT_Connect_T MqttConnectInfo
static
Initial value:
=
{
.ClientId = APP_MQTT_CLIENT_ID,
.CleanSession = true,
.KeepAliveInterval = 100,
}
#define APP_MQTT_BROKER_HOST_URL
Definition: AppController.h:127
#define APP_MQTT_CLIENT_ID
Definition: AppController.h:137
#define APP_MQTT_BROKER_HOST_PORT
Definition: AppController.h:132

MQTT connect parameters

MQTT_Publish_T MqttPublishInfo
static
Initial value:
=
{
.Topic = APP_MQTT_TOPIC,
.QoS = 1UL,
.Payload = NULL,
.PayloadLength = 0UL,
}
#define NULL
Definition: BCDS_Basics.h:80
#define APP_MQTT_TOPIC
Definition: AppController.h:142

MQTT publish parameters

MQTT_Setup_T MqttSetupInfo
static
Initial value:
=
{
.MqttType = MQTT_TYPE_SERVALSTACK,
}
#define APP_MQTT_SECURE_ENABLE
Definition: AppController.h:144
Definition: XDK_MQTT.h:62

MQTT setup parameters

MQTT_Subscribe_T MqttSubscribeInfo
static
Initial value:
=
{
.Topic = APP_MQTT_TOPIC,
.QoS = 1UL,
.IncomingPublishNotificationCB = AppMQTTSubscribeCB,
}
static void AppMQTTSubscribeCB(MQTT_SubscribeCBParam_T param)
Definition: AppController.c:212
#define APP_MQTT_TOPIC
Definition: AppController.h:142

MQTT subscribe parameters

Sensor_Setup_T SensorSetup
static

Sensor setup parameters

WLAN_Setup_T WLANSetupInfo
static
Initial value:
=
{
.IsEnterprise = false,
.IsHostPgmEnabled = false,
.SSID = WLAN_SSID,
.Username = WLAN_PSK,
.Password = WLAN_PSK,
.IsStatic = WLAN_STATIC_IP,
.IpAddr = WLAN_IP_ADDR,
.GwAddr = WLAN_GW_ADDR,
.DnsAddr = WLAN_DNS_ADDR,
.Mask = WLAN_MASK,
}
#define WLAN_DNS_ADDR
Definition: AppController.h:101
#define WLAN_PSK
Definition: AppController.h:75
#define WLAN_GW_ADDR
Definition: AppController.h:94
#define WLAN_IP_ADDR
Definition: AppController.h:87
#define WLAN_SSID
Definition: AppController.h:69
#define WLAN_STATIC_IP
Definition: AppController.h:80
#define WLAN_MASK
Definition: AppController.h:108

WLAN setup parameters


This documentation file has been automatically generated on Fri Oct 4 2019 03:47:43 by doxygen 1.8.8