# Device

On the device part we need to open our Workbench 3.4.0 open either a new project or we can use the base program that bosch offer us named SendDataMQTT. Once we have we need to modify multiples files

The first one is : AppController.h

This file would help us to define each global variable, so we can set up our wifi connection, mqtt broker, mqtt channels, etc.

```
/* header definition ******************************************************** */
#ifndef APPCONTROLLER_H_
#define APPCONTROLLER_H_

/* local interface declaration ********************************************** */
#include "XDK_Utils.h"

/* local type and macro definitions */

/* WLAN configurations ****************************************************** */

/**
 * WLAN_SSID is the WIFI network name where user wants connect the XDK device.
 * Make sure to update the WLAN_PSK constant according to your required WIFI network.
 */

#define WLAN_SSID                           ""

#define WLAN_USRN                            ""

/**
 * WLAN_PSK is the WIFI router WPA/WPA2 password used at the Wifi network connection.
 * Make sure to update the WLAN_PSK constant according to your router password.
 */

#define WLAN_PSK                            ""

/**
 * WLAN_STATIC_IP is a boolean. If "true" then static IP will be assigned and if "false" then DHCP is used.
 */

#define WLAN_STATIC_IP                      false
/**
 * WLAN_IP_ADDR is the WIFI router WPA/WPA2 static IPv4 IP address (unused if WLAN_STATIC_IP is false)
 * Make sure to update the WLAN_IP_ADDR constant according to your required WIFI network,
 * if WLAN_STATIC_IP is "true".
 */
#define WLAN_IP_ADDR                        XDK_NETWORK_IPV4(0, 0, 0, 0)

/**
 * WLAN_GW_ADDR is the WIFI router WPA/WPA2 static IPv4 gateway address (unused if WLAN_STATIC_IP is false)
 * Make sure to update the WLAN_GW_ADDR constant according to your required WIFI network,
 * if WLAN_STATIC_IP is "true".
 */
#define WLAN_GW_ADDR                        XDK_NETWORK_IPV4(0, 0, 0, 0)

/**
 * WLAN_DNS_ADDR is the WIFI router WPA/WPA2 static IPv4 DNS address (unused if WLAN_STATIC_IP is false)
 * Make sure to update the WLAN_DNS_ADDR constant according to your required WIFI network,
 * if WLAN_STATIC_IP is "true".
 */
#define WLAN_DNS_ADDR                       XDK_NETWORK_IPV4(0, 0, 0, 0)

/**
 * WLAN_MASK is the WIFI router WPA/WPA2 static IPv4 mask address (unused if WLAN_STATIC_IP is false)
 * Make sure to update the WLAN_MASK constant according to your required WIFI network,
 * if WLAN_STATIC_IP is "true".
 */
#define WLAN_MASK                           XDK_NETWORK_IPV4(0, 0, 0, 0)

/* SNTP configurations ****************************************************** */

/**
 * SNTP_SERVER_URL is the SNTP server URL.
 */
#define SNTP_SERVER_URL                     "YourSNTPServerURL"

/**
 * SNTP_SERVER_PORT is the SNTP server port number.
 */
#define SNTP_SERVER_PORT                    UINT16_C(123)

/* MQTT server configurations *********************************************** */

/**
 * APP_MQTT_BROKER_HOST_URL is the MQTT broker host address URL.
 */
#define APP_MQTT_BROKER_HOST_URL            "broker.hivemq.com"

/**
 * APP_MQTT_BROKER_HOST_PORT is the MQTT broker host port.
 */
#define APP_MQTT_BROKER_HOST_PORT           UINT16_C(1883)

/**
 * APP_MQTT_CLIENT_ID is the device name
 */
#define APP_MQTT_CLIENT_ID                  "12345"

/**
 * APP_MQTT_TOPIC is the topic to subscribe and publish
 */
#define APP_MQTT_TOPIC                                "XDK/RFT/led/switch"
#define MQTT_TOPIC_TEMPERATURE                      "XDK/RFT/temperature/status"
#define MQTT_TOPIC_PRESSURE                            "XDK/RFT/pressure/status"
#define MQTT_TOPIC_HUMIDITY                            "XDK/RFT/humidity/status"
#define MQTT_TOPIC_LIGHT                             "XDK/RFT/light/status"
#define MQTT_TOPIC_NOISE                            "XDK/RFT/noise/status"

/**
 * APP_MQTT_SECURE_ENABLE is a macro to enable MQTT with security
 */
#define APP_MQTT_SECURE_ENABLE              0

/**
 * APP_MQTT_DATA_PUBLISH_PERIODICITY is time for MQTT to publish the sensor data
 */
#define APP_MQTT_DATA_PUBLISH_PERIODICITY   UINT32_C(1000)

/* local function prototype declarations */

/* local module global variable declarations */

/* local inline function definitions */

/**
 * @brief Gives control to the Application controller.
 *
 * @param[in] cmdProcessorHandle
 * Handle of the main command processor which shall be used based on the application needs
 *
 * @param[in] param2
 * Unused
 */
void AppController_Init(void * cmdProcessorHandle, uint32_t param2);

#endif /* APPCONTROLLER_H_ */

/** ************************************************************************* */
```

The Second file that we need to modify is: AppController.c

```
/* module includes ********************************************************** */

/* own header files */
#include "XdkAppInfo.h"
#undef BCDS_MODULE_ID  /* Module ID define before including Basics package*/
#define BCDS_MODULE_ID XDK_APP_MODULE_ID_APP_CONTROLLER

/* own header files */
#include "AppController.h"

/* system header files */
#include <stdio.h>

/* additional interface header files */
#include "BCDS_BSP_Board.h"
#include "BCDS_CmdProcessor.h"
#include "BCDS_NetworkConfig.h"
#include "BCDS_Assert.h"
#include "XDK_WLAN.h"
#include "XDK_MQTT.h"
#include "XDK_Sensor.h"
#include "XDK_SNTP.h"
#include "XDK_ServalPAL.h"
#include "FreeRTOS.h"
#include "task.h"
#include "XDK_LED.h"

/* constant definitions ***************************************************** */

#define MQTT_CONNECT_TIMEOUT_IN_MS                  UINT32_C(60000)/**< Macro for MQTT connection timeout in milli-second */

#define MQTT_SUBSCRIBE_TIMEOUT_IN_MS                UINT32_C(5000)/**< Macro for MQTT subscription timeout in milli-second */

#define MQTT_PUBLISH_TIMEOUT_IN_MS                  UINT32_C(5000)/**< Macro for MQTT publication timeout in milli-second */

#define APP_TEMPERATURE_OFFSET_CORRECTION               (-3459)/**< Macro for static temperature offset correction. Self heating, temperature correction factor */
#define APP_MQTT_DATA_BUFFER_SIZE                   UINT32_C(256)/**< macro for data size of incoming subscribed and published messages */

#if APP_MQTT_SECURE_ENABLE
#define APP_RESPONSE_FROM_SNTP_SERVER_TIMEOUT       UINT32_C(10000)/**< Timeout for SNTP server time sync */
#endif /* APP_MQTT_SECURE_ENABLE */

/* local variables ********************************************************** */

/*
 * WIFI ENTERPRISE
static WLAN_Setup_T WLANSetupInfo =
        {
                .IsEnterprise = true,
                .IsHostPgmEnabled = true,
                .SSID = WLAN_SSID,
                .Username = WLAN_USRN,
                .Password = WLAN_PSK,
                .IsStatic = WLAN_STATIC_IP,
                .IpAddr = WLAN_IP_ADDR,
                .GwAddr = WLAN_GW_ADDR,
                .DnsAddr = WLAN_DNS_ADDR,
                .Mask = WLAN_MASK,
        };*< WLAN setup parameters
*/
// STANDAR WIFI
static WLAN_Setup_T WLANSetupInfo =
        {
                .IsEnterprise = false,
                .IsHostPgmEnabled = false,
                .SSID = WLAN_SSID,
                .Username = WLAN_USRN,
                .Password = WLAN_PSK,
                .IsStatic = WLAN_STATIC_IP,
                .IpAddr = WLAN_IP_ADDR,
                .GwAddr = WLAN_GW_ADDR,
                .DnsAddr = WLAN_DNS_ADDR,
                .Mask = WLAN_MASK,
        };/**< WLAN setup parameters */

static Sensor_Setup_T SensorSetup =
        {
                .CmdProcessorHandle = NULL,
                .Enable =
                        {
                                .Accel = false,
                                .Mag = false,
                                .Gyro = false,
                                .Humidity = true,
                                .Temp = true,
                                .Pressure = true,
                                .Light = true,
                                .Noise = true,
                        },
                .Config =
                        {
                                .Accel =
                                        {
                                                .Type = SENSOR_ACCEL_BMA280,
                                                .IsRawData = false,
                                                .IsInteruptEnabled = false,
                                                .Callback = NULL,
                                        },
                                .Gyro =
                                        {
                                                .Type = SENSOR_GYRO_BMG160,
                                                .IsRawData = false,
                                        },
                                .Mag =
                                        {
                                                .IsRawData = false
                                        },
                                .Light =
                                        {
                                                .IsInteruptEnabled = false,
                                                .Callback = NULL,
                                        },
                                .Temp =
                                        {
                                                .OffsetCorrection = APP_TEMPERATURE_OFFSET_CORRECTION,
                                        },
                        },
        };/**< Sensor setup parameters */

#if APP_MQTT_SECURE_ENABLE
static SNTP_Setup_T SNTPSetupInfo =
{
    .ServerUrl = SNTP_SERVER_URL,
    .ServerPort = SNTP_SERVER_PORT,
};/**< SNTP setup parameters */
#endif /* APP_MQTT_SECURE_ENABLE */

static MQTT_Setup_T MqttSetupInfo =
        {
                .MqttType = MQTT_TYPE_SERVALSTACK,
                .IsSecure = APP_MQTT_SECURE_ENABLE,
        };/**< MQTT setup parameters */

static MQTT_Connect_T MqttConnectInfo =
        {
                .ClientId = APP_MQTT_CLIENT_ID,
                .BrokerURL = APP_MQTT_BROKER_HOST_URL,
                .BrokerPort = APP_MQTT_BROKER_HOST_PORT,
                .CleanSession = true,
                .KeepAliveInterval = 100,
        };/**< MQTT connect parameters */

static void AppMQTTSubscribeCB(MQTT_SubscribeCBParam_T param);

static MQTT_Subscribe_T MqttSubscribeInfo =
        {
                .Topic = APP_MQTT_TOPIC,
                .QoS = 1UL,
                .IncomingPublishNotificationCB = AppMQTTSubscribeCB,
        };/**< MQTT subscribe parameters */

static MQTT_Publish_T MqttPublishHumidity =
        {
                .Topic = MQTT_TOPIC_HUMIDITY,
                .QoS = 1UL,
                .Payload = NULL,
                .PayloadLength = 0UL,
        };/**< MQTT publish parameters */

static MQTT_Publish_T MqttPublishPressure =
        {
                .Topic = MQTT_TOPIC_PRESSURE,
                .QoS = 1UL,
                .Payload = NULL,
                .PayloadLength = 0UL,
        };/**< MQTT publish parameters */

static MQTT_Publish_T MqttPublishTemperature =
        {
                .Topic = MQTT_TOPIC_TEMPERATURE,
                .QoS = 1UL,
                .Payload = NULL,
                .PayloadLength = 0UL,
        };/**< MQTT publish parameters */

static MQTT_Publish_T MqttPublishLight =
        {
                .Topic = MQTT_TOPIC_LIGHT,
                .QoS = 1UL,
                .Payload = NULL,
                .PayloadLength = 0UL,
        };/**< MQTT publish parameters */

static MQTT_Publish_T MqttPublishNoise =
        {
                .Topic = MQTT_TOPIC_NOISE,
                .QoS = 1UL,
                .Payload = NULL,
                .PayloadLength = 0UL,
        };/**< MQTT publish parameters */



static uint32_t AppIncomingMsgCount = 0UL;/**< Incoming message count */

static char AppIncomingMsgTopicBuffer[APP_MQTT_DATA_BUFFER_SIZE];/**< Incoming message topic buffer */

static char AppIncomingMsgPayloadBuffer[APP_MQTT_DATA_BUFFER_SIZE];/**< Incoming message payload buffer */

static CmdProcessor_T * AppCmdProcessor;/**< Handle to store the main Command processor handle to be used by run-time event driven threads */

static xTaskHandle AppControllerHandle = NULL;/**< OS thread handle for Application controller to be used by run-time blocking threads */

/* global variables ********************************************************* */

/* inline functions ********************************************************* */

/* local functions ********************************************************** */

static void AppMQTTSubscribeCB(MQTT_SubscribeCBParam_T param)
{
    AppIncomingMsgCount++;
    memset(AppIncomingMsgTopicBuffer, 0, sizeof(AppIncomingMsgTopicBuffer));
    memset(AppIncomingMsgPayloadBuffer, 0, sizeof(AppIncomingMsgPayloadBuffer));

    if (param.PayloadLength < sizeof(AppIncomingMsgPayloadBuffer))
    {
        strncpy(AppIncomingMsgPayloadBuffer, (const char *) param.Payload, param.PayloadLength);
    }
    else
    {
        strncpy(AppIncomingMsgPayloadBuffer, (const char *) param.Payload, (sizeof(AppIncomingMsgPayloadBuffer) - 1U));
    }
    if (param.TopicLength < (int) sizeof(AppIncomingMsgTopicBuffer))
    {
        strncpy(AppIncomingMsgTopicBuffer, param.Topic, param.TopicLength);
    }
    else
    {
        strncpy(AppIncomingMsgTopicBuffer, param.Topic, (sizeof(AppIncomingMsgTopicBuffer) - 1U));
    }

    printf("AppMQTTSubscribeCB : #%d, Incoming Message:\r\n"
            "\tTopic: %s\r\n"
            "\tPayload: \r\n\"\"\"\r\n%s\r\n\"\"\"\r\n", (int) AppIncomingMsgCount,
            AppIncomingMsgTopicBuffer, AppIncomingMsgPayloadBuffer);

    if (strcmp(AppIncomingMsgPayloadBuffer, "1") == 0) {
        LED_On(LED_INBUILT_RED);
        LED_On(LED_INBUILT_ORANGE);
        LED_On(LED_INBUILT_YELLOW);
    }else if(strcmp(AppIncomingMsgPayloadBuffer, "0") == 0){
        LED_Off(LED_INBUILT_RED);
        LED_Off(LED_INBUILT_ORANGE);
        LED_Off(LED_INBUILT_YELLOW);
    }

}

/**
 * @brief This will validate the WLAN network connectivity
 *
 * 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.
 */
static void AppControllerValidateWLANConnectivity(void)
{
    Retcode_T retcode = RETCODE_OK;
    NetworkConfig_IpStatus_T ipStatus = NETWORKCONFIG_IP_NOT_ACQUIRED;
    NetworkConfig_IpSettings_T ipAddressOnGetStatus;

    ipStatus = NetworkConfig_GetIpStatus();
    if (ipStatus == NETWORKCONFIG_IPV4_ACQUIRED)
    {
        retcode = NetworkConfig_GetIpSettings(&ipAddressOnGetStatus);
        if ((RETCODE_OK == retcode) && (UINT32_C(0) == (ipAddressOnGetStatus.ipV4)))
        {
            /* Our IP configuration is corrupted somehow in this case. No use in proceeding further. */
            retcode = RETCODE(RETCODE_SEVERITY_ERROR, RETCODE_NODE_IPV4_IS_CORRUPTED);
        }
    }
    else
    {
        /* Our network connection is lost. No use in proceeding further. */
        retcode = RETCODE(RETCODE_SEVERITY_ERROR, RETCODE_NODE_WLAN_CONNECTION_IS_LOST);
    }
    if (RETCODE_OK != retcode)
    {
        Retcode_RaiseError(retcode);
        printf("AppControllerValidateWLANConnectivity : Resetting the device. Check if network is available. Node will do a soft reset in 10 seconds.\r\n\r\n");
        vTaskDelay(pdMS_TO_TICKS(10000));
        BSP_Board_SoftReset();
        assert(false); /* Code must not reach here */
    }
}

/**
 * @brief Responsible for controlling the send data over MQTT application control flow.
 *
 * - 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
 *
 * @param[in] pvParameters
 * Unused
 */
static void AppControllerFire(void* pvParameters)
{
    BCDS_UNUSED(pvParameters);

    Retcode_T retcode = RETCODE_OK;
    Sensor_Value_T sensorValue;
    char publishBufferH[APP_MQTT_DATA_BUFFER_SIZE];
    char publishBufferP[APP_MQTT_DATA_BUFFER_SIZE];
    char publishBufferT[APP_MQTT_DATA_BUFFER_SIZE];
    char publishBufferL[APP_MQTT_DATA_BUFFER_SIZE];
    char publishBufferN[APP_MQTT_DATA_BUFFER_SIZE];


    const char *publishHumidity    = "%ld";
    const char *publishPressure    = "%ld";
    const char *publishTemperature = "%f";
    const char *publishLigth       = "%ld";
    const char *publishSound       = "%f";

    memset(&sensorValue, 0x00, sizeof(sensorValue));
#if APP_MQTT_SECURE_ENABLE

    uint64_t sntpTimeStampFromServer = 0UL;

    /* We Synchronize the node with the SNTP server for time-stamp.
     * Since there is no point in doing a HTTPS communication without a valid time */
    do
    {
        retcode = SNTP_GetTimeFromServer(&sntpTimeStampFromServer, APP_RESPONSE_FROM_SNTP_SERVER_TIMEOUT);
        if ((RETCODE_OK != retcode) || (0UL == sntpTimeStampFromServer))
        {
            printf("AppControllerFire : SNTP server time was not synchronized. Retrying...\r\n");
        }
    }while (0UL == sntpTimeStampFromServer);

    BCDS_UNUSED(sntpTimeStampFromServer); /* Copy of sntpTimeStampFromServer will be used be HTTPS for TLS handshake */
#endif /* APP_MQTT_SECURE_ENABLE */

    if (RETCODE_OK == retcode)
    {
        retcode = MQTT_ConnectToBroker(&MqttConnectInfo, MQTT_CONNECT_TIMEOUT_IN_MS);
    }

    if (RETCODE_OK == retcode)
    {
        retcode = MQTT_SubsribeToTopic(&MqttSubscribeInfo, MQTT_SUBSCRIBE_TIMEOUT_IN_MS);
    }

    if (RETCODE_OK != retcode)
    {
        /* We raise error and still proceed to publish data periodically */
        Retcode_RaiseError(retcode);
    }

    /* A function that implements a task must not exit or attempt to return to
     its caller function as there is nothing to return to. */
    while (1)
    {
        /* Resetting / clearing the necessary buffers / variables for re-use */
        retcode = RETCODE_OK;

        /* Check whether the WLAN network connection is available */
        AppControllerValidateWLANConnectivity();

        retcode = Sensor_GetData(&sensorValue);
        if (RETCODE_OK == retcode)
        {
            int32_t lengthH = snprintf((char *) publishBufferH, APP_MQTT_DATA_BUFFER_SIZE, publishHumidity,
                    (long int) sensorValue.RH);

            int32_t lengthP = snprintf((char *) publishBufferP, APP_MQTT_DATA_BUFFER_SIZE, publishPressure,
                                (long int) sensorValue.Pressure);

            int32_t lengthT = snprintf((char *) publishBufferT, APP_MQTT_DATA_BUFFER_SIZE, publishTemperature,
                                (sensorValue.Temp /= 1000));

            int32_t lengthL = snprintf((char *) publishBufferL, APP_MQTT_DATA_BUFFER_SIZE, publishLigth,
                                (long int) sensorValue.Light);

            int32_t lengthN = snprintf((char *) publishBufferN, APP_MQTT_DATA_BUFFER_SIZE, publishSound,
                                sensorValue.Noise);

            //Send Humidity
            MqttPublishHumidity.Payload = publishBufferH;
            MqttPublishHumidity.PayloadLength = lengthH;
            retcode = MQTT_PublishToTopic(&MqttPublishHumidity, MQTT_PUBLISH_TIMEOUT_IN_MS);

            //Publish Pressure
            MqttPublishPressure.Payload = publishBufferP;
            MqttPublishPressure.PayloadLength = lengthP;
            retcode = MQTT_PublishToTopic(&MqttPublishPressure, MQTT_PUBLISH_TIMEOUT_IN_MS);

            //Publish Temperature
            MqttPublishTemperature.Payload = publishBufferT;
            MqttPublishTemperature.PayloadLength = lengthT;
            retcode = MQTT_PublishToTopic(&MqttPublishTemperature, MQTT_PUBLISH_TIMEOUT_IN_MS);

            //Publish Light
            MqttPublishLight.Payload = publishBufferL;
            MqttPublishLight.PayloadLength = lengthL;
            retcode = MQTT_PublishToTopic(&MqttPublishLight, MQTT_PUBLISH_TIMEOUT_IN_MS);

            //Publish Light
            MqttPublishNoise.Payload = publishBufferN;
            MqttPublishNoise.PayloadLength = lengthN;
            retcode = MQTT_PublishToTopic(&MqttPublishNoise, MQTT_PUBLISH_TIMEOUT_IN_MS);

        }
        if (RETCODE_OK != retcode)
        {
            Retcode_RaiseError(retcode);
        }
        vTaskDelay(APP_MQTT_DATA_PUBLISH_PERIODICITY);
    }
}

/**
 * @brief To enable the necessary modules for the application
 * - WLAN
 * - ServalPAL
 * - SNTP (if secure communication)
 * - MQTT
 * - Sensor
 *
 * @param[in] param1
 * Unused
 *
 * @param[in] param2
 * Unused
 */
static void AppControllerEnable(void * param1, uint32_t param2)
{
    BCDS_UNUSED(param1);
    BCDS_UNUSED(param2);

    Retcode_T retcode = WLAN_Enable();
    if (RETCODE_OK == retcode)
    {
        retcode = ServalPAL_Enable();
    }
#if APP_MQTT_SECURE_ENABLE
    if (RETCODE_OK == retcode)
    {
        retcode = SNTP_Enable();
    }
#endif /* APP_MQTT_SECURE_ENABLE */
    if (RETCODE_OK == retcode)
    {
        retcode = MQTT_Enable();
    }
    if (RETCODE_OK == retcode)
    {
        retcode = Sensor_Enable();
    }
    if (RETCODE_OK == retcode)
    {
        if (pdPASS != xTaskCreate(AppControllerFire, (const char * const ) "AppController", TASK_STACK_SIZE_APP_CONTROLLER, NULL, TASK_PRIO_APP_CONTROLLER, &AppControllerHandle))
        {
            retcode = RETCODE(RETCODE_SEVERITY_ERROR, RETCODE_OUT_OF_RESOURCES);
        }
    }
    if (RETCODE_OK != retcode)
    {
        printf("AppControllerEnable : Failed \r\n");
        Retcode_RaiseError(retcode);
        assert(0); /* To provide LED indication for the user */
    }
}

/**
 * @brief To setup the necessary modules for the application
 * - WLAN
 * - ServalPAL
 * - SNTP (if secure communication)
 * - MQTT
 * - Sensor
 *
 * @param[in] param1
 * Unused
 *
 * @param[in] param2
 * Unused
 */
static void AppControllerSetup(void * param1, uint32_t param2)
{
    BCDS_UNUSED(param1);
    BCDS_UNUSED(param2);

    Retcode_T retcode = WLAN_Setup(&WLANSetupInfo);
    if (RETCODE_OK == retcode)
    {
        retcode = ServalPAL_Setup(AppCmdProcessor);
    }
#if APP_MQTT_SECURE_ENABLE
    if (RETCODE_OK == retcode)
    {
        retcode = SNTP_Setup(&SNTPSetupInfo);
    }
#endif /* APP_MQTT_SECURE_ENABLE */
    if (RETCODE_OK == retcode)
    {
        retcode = MQTT_Setup(&MqttSetupInfo);
    }
    if (RETCODE_OK == retcode)
    {
        SensorSetup.CmdProcessorHandle = AppCmdProcessor;
        retcode = Sensor_Setup(&SensorSetup);
    }
    if (RETCODE_OK == retcode)
    {
        retcode = CmdProcessor_Enqueue(AppCmdProcessor, AppControllerEnable, NULL, UINT32_C(0));
    }
    if (RETCODE_OK != retcode)
    {
        printf("AppControllerSetup : Failed \r\n");
        Retcode_RaiseError(retcode);
        assert(0); /* To provide LED indication for the user */
    }
}

/* global functions ********************************************************* */

/** Refer interface header for description */
void AppController_Init(void * cmdProcessorHandle, uint32_t param2)
{
    BCDS_UNUSED(param2);

    Retcode_T retcode = RETCODE_OK;

    if (cmdProcessorHandle == NULL)
    {
        printf("AppController_Init : Command processor handle is NULL \r\n");
        retcode = RETCODE(RETCODE_SEVERITY_ERROR, RETCODE_NULL_POINTER);
    }
    else
    {
        AppCmdProcessor = (CmdProcessor_T *) cmdProcessorHandle;
        retcode = CmdProcessor_Enqueue(AppCmdProcessor, AppControllerSetup, NULL, UINT32_C(0));
    }

    if (RETCODE_OK != retcode)
    {
        Retcode_RaiseError(retcode);
        assert(0); /* To provide LED indication for the user */
    }
}

/**@} */
/** ************************************************************************* */
```

Then we we flash this project in our device would give us an error:

WORKBENCH : 3.4.0

Common Errors:

1. Method don't exits:

   SDK/xdk110/Libraries/FreeRTOS/mqtt/aws\_mqtt\_agent.c

   \*xQueueCreateStatic

   \*xTaskCreateStatic

Solution:

```
  Go to FreeRTOS Line 813 and replace for this:
```

```
      #ifndef configSUPPORT_STATIC_ALLOCATION
      /*Defaults to 0 for backward compatibility */
       #define
        configSUPPORT_STATIC_ALLOCATION 1
       #endif
```

1. Tcp\_connectSecure, Tls\_getSocketStatus, Tls\_receive, Tls\_prepareForSending, Tls\_send, Tls\_retrySendingLater, Tls\_close, Tls\_delete

   Go to Serval\_Defines.h Line 214

```
      #ifndef SERVAL_ENABLE_TLS_SERVER
      /**
      *Enable SERVAL_ENABLE_TLS_SERVER in order to enable
      *the Tranport Layer Security (TLS) code/Feature 
      */
      #define SERVAL_ENABLE_TLS_SERVER 1
      #endif
```

Enhancement:

SDK/XDK110/Libraries/ServalStack/src/Msg/tcpmsg.c

Line 90

Old:

```
      assert(Tcp_isValidSokcet(conn))
```

New:

```
       if(Tcp_isValidSocket(conn)){}
       else{
        return TCP_RECEIVE_ERROR;
       }
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://alfredo-reyes-montero.gitbook.io/iot-bosch/devices/bosch-xdk-110/applications/language-c/combinesensor/device.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
