XDK API  3.6.0
Documentation
Files | Macros | Functions | Variables
AwsSendDataOverMQTT

Demo application for using MQTT protocol for an AWS server using Amazon FreeRTOS. More...

+ Collaboration diagram for AwsSendDataOverMQTT:

Files

file  AppController.c
 

Macros

#define APP_CLIENT_CERT_KEY_BACKUP_FILE_NAME   "xdk-cert.bkp"
 
#define APP_CLIENT_CERT_KEY_FILE_NAME   "xdk-cert.der"
 
#define APP_CONFIGURATION_BACKUP_FILE_NAME   "config.bkp"
 
#define APP_CONFIGURATION_FILE_NAME   "config.txt"
 
#define APP_CONTROLLER_STEP1   UINT32_C(0)
 
#define APP_CONTROLLER_STEP2   UINT32_C(1)
 
#define APP_MQTT_DATA_BUFFER_SIZE   UINT32_C(256)
 
#define APP_PRIVATE_KEY_BACKUP_FILE_NAME   "xdk-priv.bkp"
 
#define APP_PRIVATE_KEY_FILE_NAME   "xdk-priv.der"
 
#define APP_RESPONSE_FROM_SNTP_SERVER_TIMEOUT   UINT32_C(10000)
 
#define APP_ROOT_CA_BACKUP_FILE_NAME   "rootCA.bkp"
 
#define APP_ROOT_CA_FILE_NAME   "rootCA.der"
 
#define APP_TEMPERATURE_OFFSET_CORRECTION   (-3459)
 
#define AWS_CONFIGURATION_FILE_NAME   "/config.txt"
 
#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(5000)
 
#define MQTT_SUBSCRIBE_TIMEOUT_IN_MS   UINT32_C(5000)
 
#define WIFI_CFG_FILE_READ_BUFFER   UINT32_C(2024)
 

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. It is done in 2 steps. In Step 1, the modules enabled are: More...
 
static void AppControllerFire (void *param1, uint32_t param2)
 To fire the necessary modules for the application. It is done in 2 steps. In Step 1, the modules run functionality are: More...
 
static void AppControllerFireTask (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. It is done in 2 steps. In Step 1, the modules setup are: More...
 
static void AppControllerValidateWLANConnectivity (void)
 This will validate the WLAN network connectivity. More...
 
static void AppMQTTSubscribeCB (MQTT_SubscribeCBParam_T param)
 
static Retcode_T AppParseConfigFile (void)
 

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 uint8_t FileReadBuffer [WIFI_CFG_FILE_READ_BUFFER] = { 0 }
 
static cJSONJsonParserHandle = NULL
 
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 SNTP_Setup_T SNTPSetupInfo
 
static Storage_Setup_T StorageSetup
 
static WLAN_Setup_T WLANSetupInfo
 

Detailed Description

This example shows how to use the MQTT protocol to transfer the sensor data to an AWS server using Amazon FreeRTOS.

You need to have the below 4 valid files for the first time in SD card

Macro Definition Documentation

#define APP_CLIENT_CERT_KEY_BACKUP_FILE_NAME   "xdk-cert.bkp"
#define APP_CLIENT_CERT_KEY_FILE_NAME   "xdk-cert.der"
#define APP_CONFIGURATION_BACKUP_FILE_NAME   "config.bkp"
#define APP_CONFIGURATION_FILE_NAME   "config.txt"
#define APP_CONTROLLER_STEP1   UINT32_C(0)
#define APP_CONTROLLER_STEP2   UINT32_C(1)
#define APP_MQTT_DATA_BUFFER_SIZE   UINT32_C(256)

Macro for data size of incoming subscribed and published messages

#define APP_PRIVATE_KEY_BACKUP_FILE_NAME   "xdk-priv.bkp"
#define APP_PRIVATE_KEY_FILE_NAME   "xdk-priv.der"
#define APP_RESPONSE_FROM_SNTP_SERVER_TIMEOUT   UINT32_C(10000)

Timeout for SNTP server time sync

#define APP_ROOT_CA_BACKUP_FILE_NAME   "rootCA.bkp"
#define APP_ROOT_CA_FILE_NAME   "rootCA.der"
#define APP_TEMPERATURE_OFFSET_CORRECTION   (-3459)

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

#define AWS_CONFIGURATION_FILE_NAME   "/config.txt"
#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(5000)

Macro for MQTT publication timeout in milli-second

#define MQTT_SUBSCRIBE_TIMEOUT_IN_MS   UINT32_C(5000)

Macro for MQTT subscription timeout in milli-second

#define WIFI_CFG_FILE_READ_BUFFER   UINT32_C(2024)

Macro for wifi config file read buffer

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 caller graph for this function:

static void AppControllerEnable ( void *  param1,
uint32_t  param2 
)
static
  • Storage In Step 2, the modules enabled are:
  • WLAN
  • ServalPAL
  • SNTP
  • LWM2M
  • MQTT
  • Sensor
Parameters
[in]param1Unused
[in]param2Step to be enabled

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void AppControllerFire ( void *  param1,
uint32_t  param2 
)
static
  • Validate if SD Card storage if available
    • If available, then copy the below files to WiFi file system and rename the same in SD card
      • APP_ROOT_CA_FILE_NAME
      • APP_PRIVATE_KEY_FILE_NAME
      • APP_CLIENT_CERT_KEY_FILE_NAME
      • APP_CONFIGURATION_FILE_NAME
  • Read APP_CONFIGURATION_FILE_NAME from the WiFi file system and store the contents to a global memory
  • Parse the APP_CONFIGURATION_FILE_NAME content In Step 2, the modules run functionality are:
  • Create a task to perform the following
    • Sync SNTP server time
    • Trigger a MQTT connect, subscribe and periodic publish
Parameters
[in]param1Unused
[in]param2Step to be fired

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void AppControllerFireTask ( void *  pvParameters)
static
  • Synchronize SNTP time stamp for the WLAN chip
  • Connect to MQTT broker
  • Subscribe to MQTT topic
  • Read 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
  • Storage In Step 2, the modules setup are:
  • WLAN
  • ServalPAL
  • SNTP
  • LWM2M
  • MQTT
  • Sensor
Parameters
[in]param1Unused
[in]param2Step to be setup

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void AppControllerValidateWLANConnectivity ( void  )
static

Currently, upon abrupt disconnection the event from the WiFi chip is not propagated / notified to the application. Until then, we manually validate prior to ever HTTP Rest Client POST/GET cycle to make sure that the possibility of software break is reduced. We check if the IP is valid to validate the same.

If there is no connectivity we will restart the node after 10 seconds.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void AppMQTTSubscribeCB ( MQTT_SubscribeCBParam_T  param)
static
static Retcode_T AppParseConfigFile ( void  )
static

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

uint8_t FileReadBuffer[WIFI_CFG_FILE_READ_BUFFER] = { 0 }
static

Buffer to store the configuration file from the SD card / WiFi storage

cJSON* JsonParserHandle = NULL
static
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 = 0UL,
.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:
=
{
.CmdProcessorHandle = NULL,
.MqttType = MQTT_TYPE_AWS,
.IsSecure = true,
}
#define NULL
Definition: BCDS_Basics.h:80
Definition: XDK_MQTT.h:63

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:255
#define APP_MQTT_TOPIC
Definition: AppController.h:142

MQTT subscribe parameters

Sensor_Setup_T SensorSetup
static

Sensor setup parameters

SNTP_Setup_T SNTPSetupInfo
static
Initial value:
=
{
.ServerUrl = SNTP_SERVER_URL,
.ServerPort = SNTP_SERVER_PORT,
}
#define SNTP_SERVER_PORT
Definition: AppController.h:120
#define SNTP_SERVER_URL
Definition: AppController.h:115

SNTP setup parameters

Storage_Setup_T StorageSetup
static
Initial value:
=
{
.SDCard = true,
.WiFiFileSystem = true,
}

Storage 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


All rights reserved. The use is subject to the XDK SDK EULA by Bosch Connected Devices and Solutions GmbH.
This documentation file has been automatically generated on Thu Mar 14 2019 19:12:54 by doxygen 1.8.8