API  2.2
TSmarT Software Library
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
mqtt_cellular_2g_subscriber.c

This is an example of how to manage the MQTT protocol using the cellular 2g device.

/* @file mqtt_cellular_2g_subscriber.c
* @author TST
* @version 0.2
* @date 10/04/2014
* @brief This is an example of how to manage the MQTT library using the
* cellular 2g interface.
*
*
* This example is based on using a cellular 2g network using a cellular 2g
* interface. The cellular 2G in use is a SL6087 2G module manufactured by
* Sierra wireless.. This device has an embedded TCP/IP controller that enables
* easier internet connection.
*
* This example shows users how to be subscribed to a topic with QoS(quality of
* service) 0. To achive it, the example uses a MQTT open-source library based
* on the embedded C version of Paho from IBM and Eclipse foundation.
*
* Finally, to run this example users must have a server running so that this
* example can be subscribed to a specific topic.
* This topic is "tst/tsmart", located in the root of your MQTT server, but
* users can change it, changing the proper definition: MQTT_TOPIC.
*
*
* @note Users shall configure the MQTT connection parameters:
* - PIN ------------> Set your personal identification number, PIN code (line 86).
* - APN ------------> Set your access point name (line 88).
* - LOGIN ----------> Set your network user name (line 89).
* - PASSWORD -------> set your network password (line 90).
*
* User shall set them in the definitions below.
*
* @note Users shall configure the MQTT connection parameters:
* - MQTT IP server ------> Set your MQTT IP server address in numeric format.
* - MQTT_SERVER_IP0_ADDRESS --> 1 value of the MQTT server IP address (line 97).
* - MQTT_SERVER_IP1_ADDRESS --> 2 value of the MQTT server IP address (line 98).
* - MQTT_SERVER_IP2_ADDRESS --> 3 value of the MQTT server IP address (line 99).
* - MQTT_SERVER_IP3_ADDRESS --> 4 value of the MQTT server IP address (line 100).
*
* - MQTT port server --------> The MQTT port server enabled to connect.
* - MQTT_PORT - Port number (line 96).
*
* - MQTT Client parameters --> MQTT parameters to stablish a MQTT connection:
* - MQTT_CLIENT_ID -----------> Client identifier (line 101).
* - MQTT_USER ----------------> User name (line 102).
* - MQTT_PASSWORD ------------> Password (line 103).
*
*
* @note This example uses a debug UART to display some debug information like
* ip address asigned.
* The Debug UART is located in the UART 1 of the TSmarT platform.
* All users who want to see these debug messages shall use a serial
* communication program. In addition, the serial communication
* program shall be set as follows:
* - Baud rate -----> 115200
* - Word length ---> 8 bits
* - Parity --------> none
* - Stop bit ------> 1
* - Flow control --> none
*
*/
/*-------------------------------------------------------- System headers -------------------------------------------------*/
#include "tsmart.h"
/* MQTT protocol headers */
#include "mqtt/include/MQTTPacket.h"
#include "mqtt/include/MQTTConnect.h"
#include "mqtt/include/MQTTPublish.h"
#include "mqtt/include/MQTTSubscribe.h"
#include "mqtt/include/MQTTUnsubscribe.h"
#include "mqtt/include/StackTrace.h"
/*-------------------------------------------------------- UART Debug -----------------------------------------------------*/
#define DEBUG_UART tsmart_uart1
#define APP_RX_BUFFER_SZ 1
static uint8_t app_rx_buf[APP_RX_BUFFER_SZ];
static uint8_t debug_buffer[2000];
/*-------------------------------------------------------- Cellular 2G network parameters ---------------------------------*/
/* Set SIM configuration */
#define PIN_CODE "\0" /* PIN code */
/* Access point network parameters */
#define APN "gprs.pepephone.com\0" /* APN */
#define LOGIN "\0" /* Login */
#define PASSWORD "\0" /* Password */
/* Cellular state machine */
#define CEL_2G_ON 0
#define CEL_2G_OFF 1
#define CEL_2G_ATTACH 2
/*-------------------------------------------------------- MQTT parameters ------------------------------------------------*/
#define MQTT_PORT 1883 /* MQTT port number */
#define MQTT_SERVER_IP0_ADDRESS 0 /* 1 value of the MQTT server IP address */
#define MQTT_SERVER_IP1_ADDRESS 0 /* 2 value of the MQTT server IP address */
#define MQTT_SERVER_IP2_ADDRESS 0 /* 3 value of the MQTT server IP address */
#define MQTT_SERVER_IP3_ADDRESS 0 /* 4 value of the MQTT server IP address */
#define MQTT_CLIENT_ID "2G_S\0" /* Client identifier */
#define MQTT_USER "\0" /* User name */
#define MQTT_PASSWORD "\0" /* Password */
#define MQTT_TOPIC "tst/tsmart\0" /* Topic name */
#define MQTT_KEEP_ALIVE 0 /* Keep alive: 30 seconds */
#define MQTT_CLEAN_SESSION 1 /* Clean session: enabled */
#define MQTT_MQTT_VERSION 3 /* MQTT version in use: 3 */
/* MQTT Connection states */
#define CONNECTION_ACCEPTED 0x00
#define CONNECTION_REFUSE_UNACCEPTABLE_PROTOCOL_VERSION 0x01
#define CONNECTION_REFUSE_IDENTIFIER_REJECTED 0x02
#define CONNECTION_REFUSE_SERVER_UNAVAILABLE 0x03
#define CONNECTION_REFUSE_BAD_USER_NAME_OR_PASSWORD 0x04
#define CONNECTION_REFUSE_NOT_AUTORIZED 0x05
/* MQTT_Connetion state Messages */
#define CONNECTION_ACCEPTED_M " MQTT: Connection Accepted\r\n\0"
#define CONNECTION_REFUSE_UNACCEPTABLE_PROTOCOL_VERSION_M " MQTT: Connestion Refused: unacceptabl protocol version\r\n\0"
#define CONNECTION_REFUSE_IDENTIFIER_REJECTED_M " MQTT: Connection Refused: identifier rejected\r\n\0"
#define CONNECTION_REFUSE_SERVER_UNAVAILABLE_M " MQTT: Connection Refused: server unavailable\r\n\0"
#define CONNECTION_REFUSE_BAD_USER_NAME_OR_PASSWORD_M " MQTT: Connection Refused: bad user name or passwod\r\n\0"
#define CONNECTION_REFUSE_NOT_AUTORIZED_M " MQTT: Connection Refused: not authorized\r\n\0"
#define CONNECTION_DEFAULT_M " MQTT: Bad Connection State\r\n\0"
/* SUBSCRIPTION VALUES */
#define NUMBER_OF_TOPIC_TO_BE_SUBSCRIPTED 1
/*-------------------------------------------------------- MQTT variables -------------------------------------------------*/
static char mqtt_serial_buffer_tx[200];
static char mqtt_serial_buffer_rx[200];
/*-------------------------------------------------------- Application Task -----------------------------------------------*/
/* @brief CELLULAR_2G task.
*
* This task initiliazes the cellular 2g device with the user network
* parameters. It will connect with the MQTT server and it will subscribe to a
* specific topic with QoS: 0. After that, the example will wait for new
* publications as consequence of the subscription.
*
* @note: This example doesn't do a error management so if the example gets
* some error it will be blocked in a loop.
*
* @param pvParameters
*/
void vCELLULAR_2G(void *pvParameters){
/* Variables */
uint8_t state = CEL_2G_ON;
uint8_t cel_2g_ready = TSMART_FAIL;
uint8_t mqtt_remote_ip_server[30];
int8_t counter = 3;
int ret;
int socket_mqtt = 0;
int length_mqtt_frame = 0;
int connack_code = 0;
MQTTPacket_connectData data = MQTTPacket_connectData_initializer;
int rcvd_packetid;
int rcvd_count;
int rcvd_grantedQoSs[NUMBER_OF_TOPIC_TO_BE_SUBSCRIPTED];
uint8_t s_publish_lenght;
int s_dup;
int s_retained;
int s_packetid;
int s_qos;
MQTTString s_received_topic[NUMBER_OF_TOPIC_TO_BE_SUBSCRIPTED];
MQTTString s_topic[NUMBER_OF_TOPIC_TO_BE_SUBSCRIPTED];
int s_requested_qoss[NUMBER_OF_TOPIC_TO_BE_SUBSCRIPTED];
int s_payloadlen_in;
char* s_payload_in;
uint8_t topic_recived_buffer[30];
TSMART_UART_Send(&DEBUG_UART, "----------- MQTT(CELLULAR 2G interface) example -----------\r\n", strlen("----------- MQTT(CELLULAR 2G interface) example -----------\r\n"), 1000/portTICK_RATE_MS);
/* ******************************************************************************************************************* */
/* INITIALIZE CELLULAR 2G INTERFACE */
/* ******************************************************************************************************************* */
for(;;){
switch(state){
case CEL_2G_ON:
/* Turn On */
TSMART_UART_Send(&DEBUG_UART, "Turning on device 2G...", strlen("Turning on device 2G..."), 1000/portTICK_RATE_MS);
if(TSMART_CELLULAR_2G_TurnOn(&tsmart_cellular_2g, PIN_CODE) != TSMART_PASS){
/* Update state */
state = CEL_2G_OFF;
break;
}
/* Configure module */
if( TSMART_CELLULAR_2G_ConfigDevice(&tsmart_cellular_2g, &device_config) != TSMART_PASS){
/* Update state */
state = CEL_2G_OFF;
break;
}
/* Start stack */
/* Update state */
state = CEL_2G_OFF;
break;
}
/* Stack TCP/IP configuration */
tcp_ip_stack_config.ip_ttl = 64;
tcp_ip_stack_config.ip_frag_timeo = 60;
tcp_ip_stack_config.tcp_maxinitwin = 0;
tcp_ip_stack_config.tcp_rexmt_max = 64;
tcp_ip_stack_config.tcp_rexmt_maxcnt = 12;
if(TSMART_CELLULAR_2G_ConfigTcpIpStack(&tsmart_cellular_2g, &tcp_ip_stack_config) != TSMART_PASS){
/* Update state */
state = CEL_2G_OFF;
break;
}
TSMART_UART_Send(&DEBUG_UART, "OK\r\n", strlen("OK\r\n"), 1000/portTICK_RATE_MS);
/* Update state */
state = CEL_2G_ATTACH;
break;
case CEL_2G_OFF:
TSMART_UART_Send(&DEBUG_UART, "\r\nTurning off device 2G...", strlen("\r\nTurning off device 2G..."), 1000/portTICK_RATE_MS);
/* Probably unknow state: do a reset to set in known state */
}
/* Now Turn Off */
/* Wait to stabilize */
vTaskDelay(1000/portTICK_RATE_MS);
TSMART_UART_Send(&DEBUG_UART, "OK\r\n", strlen("OK\r\n"), 1000/portTICK_RATE_MS);
/* Update state */
state = CEL_2G_ON;
break;
case CEL_2G_ATTACH:
TSMART_UART_Send(&DEBUG_UART, "Attaching to 2G network...", strlen("Attaching 2G network..."), 1000/portTICK_RATE_MS);
do{
/* Bearer parameters */
bearer_config.apn = APN;
bearer_config.login = LOGIN;
bearer_config.password = PASSWORD;
bearer_config.time_to_connect = 1200;
if(TSMART_CELLULAR_2G_ConfigBearer(&tsmart_cellular_2g, &bearer_config) == TSMART_PASS){
break;
}
}
TSMART_UART_Send(&DEBUG_UART, "...", strlen("..."), 1000/portTICK_RATE_MS);
vTaskDelay(1000/portTICK_RATE_MS);
counter--;
}while(counter > 0);
if(counter == 0){
TSMART_UART_Send(&DEBUG_UART, "fail\r\n", strlen("fail\r\n"), 1000/portTICK_RATE_MS);
/* Re-load counter */
counter = 3;
/* Expired retries */
state = CEL_2G_OFF;
break;
}
do{
TSMART_UART_Send(&DEBUG_UART, ".", strlen("."), 1000/portTICK_RATE_MS);
/* Wait to register in GPRS network */
/* Wait for 1 second to try again */
vTaskDelay(1000/portTICK_RATE_MS);
do{
TSMART_UART_Send(&DEBUG_UART, ".", strlen("."), 1000/portTICK_RATE_MS);
/* Check Attach */
/* Wait for 1 second to try again */
vTaskDelay(1000/portTICK_RATE_MS);
}while( attach != TSMART_CELLULAR_2G_ATTACHED );
TSMART_UART_Send(&DEBUG_UART, "OK\r\n", strlen("OK\r\n"), 1000/portTICK_RATE_MS);
/* Read Local IP address */
if(TSMART_CELLULAR_2G_ReadIp(&tsmart_cellular_2g, &local_ip) != TSMART_PASS){
/* Wait for reading again */
vTaskDelay(500/portTICK_RATE_MS);
if(TSMART_CELLULAR_2G_ReadIp(&tsmart_cellular_2g, &local_ip) != TSMART_PASS){
/* Expired retries */
state = CEL_2G_OFF;
break;
}
}
sprintf(debug_buffer, "Local IP: %d.%d.%d.%d\r\n", local_ip.ip0, local_ip.ip1, local_ip.ip2, local_ip.ip3);
TSMART_UART_Send(&DEBUG_UART, debug_buffer, strlen(debug_buffer), 1000/portTICK_RATE_MS);
/* Set exit condition */
cel_2g_ready = TSMART_PASS;
break;
default:
/* Unknown state */
break;
}
if(cel_2g_ready == TSMART_PASS){
/* Exit */
break;
}
}
/* ******************************************************************************************************************* */
/* MQTT CONNECT */
/* ******************************************************************************************************************* */
TSMART_UART_Send(&DEBUG_UART, "Connecting to MQTT server...", strlen("Connecting to MQTT server..."), 1000/portTICK_RATE_MS);
memset(mqtt_remote_ip_server, 0x00, sizeof(mqtt_remote_ip_server));
sprintf(mqtt_remote_ip_server, "%d.%d.%d.%d", MQTT_SERVER_IP0_ADDRESS, MQTT_SERVER_IP1_ADDRESS, MQTT_SERVER_IP2_ADDRESS, MQTT_SERVER_IP3_ADDRESS);
/*------------------------------------------------ CELULLAR 2G Interface ----------------------------------------------*/
tcp_client.id_session = 1;
tcp_client.remote_port = MQTT_PORT;
tcp_client.remote_ip = mqtt_remote_ip_server;
if( TSMART_CELLULAR_2G_CreateTcpClient(&tsmart_cellular_2g, &tcp_client, 10000) != TSMART_PASS){
TSMART_UART_Send(&DEBUG_UART, "fail 1\r\n", strlen("fail 1\r\n"), 1000/portTICK_RATE_MS);
for(;;);
}
TSMART_UART_Send(&DEBUG_UART, "fail 2\r\n", strlen("fail 2\r\n"), 1000/portTICK_RATE_MS);
for(;;);
}
/*---------------------------------------------------------------------------------------------------------------------*/
TSMART_UART_Send(&DEBUG_UART, "OK\r\n", strlen("OK\r\n"), 1000/portTICK_RATE_MS);
/* Fill MQTT Connect structure */
data.clientID.cstring = MQTT_CLIENT_ID;
data.username.cstring = MQTT_USER;
data.password.cstring = MQTT_PASSWORD;
data.keepAliveInterval = MQTT_KEEP_ALIVE;
data.cleansession = MQTT_CLEAN_SESSION;
data.MQTTVersion = MQTT_MQTT_VERSION;
/* Create a MQTT connect frame */
length_mqtt_frame = MQTTSerialize_connect(mqtt_serial_buffer_tx, sizeof(mqtt_serial_buffer_tx), &data);
/*------------------------------------------------ CELULLAR 2G Interface ----------------------------------------------*/
/* Send */
ret = TSMART_CELLULAR_2G_SendTcpData(&tsmart_cellular_2g, mqtt_serial_buffer_tx, length_mqtt_frame);
/* Receive */
memset(mqtt_serial_buffer_rx, 0x00, sizeof(mqtt_serial_buffer_rx));
ret = TSMART_CELLULAR_2G_ReceiveTcpData(&tsmart_cellular_2g, mqtt_serial_buffer_rx, 2000);
/*---------------------------------------------------------------------------------------------------------------------*/
/* Parse Connack */
if(MQTTDeserialize_connack(&connack_code, mqtt_serial_buffer_rx, ret) != 1){
TSMART_UART_Send(&DEBUG_UART, "BAD CONNACK RECEIVED\r\n", strlen("BAD CONNACK RECEIVED\r\n"), 1000/portTICK_RATE_MS);
for(;;);
}
/* Check connection state */
switch(connack_code){
case CONNECTION_ACCEPTED:
/* Connection Accepted */
TSMART_UART_Send(&DEBUG_UART, CONNECTION_ACCEPTED_M, strlen(CONNECTION_ACCEPTED_M), 1000/portTICK_RATE_MS);
break;
case CONNECTION_REFUSE_UNACCEPTABLE_PROTOCOL_VERSION:
/* Connestion Refused: unacceptabl protocol version */
TSMART_UART_Send(&DEBUG_UART, CONNECTION_REFUSE_UNACCEPTABLE_PROTOCOL_VERSION_M, strlen(CONNECTION_REFUSE_UNACCEPTABLE_PROTOCOL_VERSION_M), 1000/portTICK_RATE_MS);
for(;;);
break;
case CONNECTION_REFUSE_IDENTIFIER_REJECTED:
/* Connection Refused: identifier rejected */
TSMART_UART_Send(&DEBUG_UART, CONNECTION_REFUSE_IDENTIFIER_REJECTED_M, strlen(CONNECTION_REFUSE_IDENTIFIER_REJECTED_M), 1000/portTICK_RATE_MS);
for(;;);
break;
case CONNECTION_REFUSE_SERVER_UNAVAILABLE:
/* Connection Refused: server unavailable */
TSMART_UART_Send(&DEBUG_UART, CONNECTION_REFUSE_SERVER_UNAVAILABLE_M, strlen(CONNECTION_REFUSE_SERVER_UNAVAILABLE_M), 1000/portTICK_RATE_MS);
for(;;);
break;
case CONNECTION_REFUSE_BAD_USER_NAME_OR_PASSWORD:
/* Connection Refused: bad user name or passwod */
TSMART_UART_Send(&DEBUG_UART, CONNECTION_REFUSE_BAD_USER_NAME_OR_PASSWORD_M, strlen(CONNECTION_REFUSE_BAD_USER_NAME_OR_PASSWORD_M), 1000/portTICK_RATE_MS);
for(;;);
break;
case CONNECTION_REFUSE_NOT_AUTORIZED:
/* Connection Refused: not authorized */
TSMART_UART_Send(&DEBUG_UART, CONNECTION_REFUSE_NOT_AUTORIZED_M, strlen(CONNECTION_REFUSE_NOT_AUTORIZED_M), 1000/portTICK_RATE_MS);
for(;;);
break;
default:
/* Default: Reserved for future use */
TSMART_UART_Send(&DEBUG_UART, CONNECTION_DEFAULT_M, strlen(CONNECTION_DEFAULT_M), 1000/portTICK_RATE_MS);
for(;;);
break;
}
/* ******************************************************************************************************************* */
/* MQTT SUBSCRIBE QoS: 0 */
/* ******************************************************************************************************************* */
TSMART_UART_Send(&DEBUG_UART, " MQTT: Subscribe with QoS: 0...", strlen(" MQTT: Subscribe with QoS: 0..."), 1000/portTICK_RATE_MS);
/* MQTT Subscriptions */
s_topic[0].cstring = MQTT_TOPIC;
s_topic[0].lenstring.len = 0;
s_topic[0].lenstring.data = NULL;
s_requested_qoss[0] = 0;
s_packetid = 1;
s_dup = 0;
length_mqtt_frame = MQTTSerialize_subscribe(mqtt_serial_buffer_tx, sizeof(mqtt_serial_buffer_rx), s_dup, s_packetid, NUMBER_OF_TOPIC_TO_BE_SUBSCRIPTED, s_topic, s_requested_qoss);
/*------------------------------------------------ CELULLAR 2G Interface ----------------------------------------------*/
/* Send */
ret = TSMART_CELLULAR_2G_SendTcpData(&tsmart_cellular_2g, mqtt_serial_buffer_tx, length_mqtt_frame);
/* Receive */
memset(mqtt_serial_buffer_rx, 0x00, sizeof(mqtt_serial_buffer_rx));
ret = TSMART_CELLULAR_2G_ReceiveTcpData(&tsmart_cellular_2g, mqtt_serial_buffer_rx, 2000);
/*---------------------------------------------------------------------------------------------------------------------*/
if(MQTTDeserialize_suback(&rcvd_packetid, NUMBER_OF_TOPIC_TO_BE_SUBSCRIPTED, &rcvd_count, rcvd_grantedQoSs, mqtt_serial_buffer_rx, ret) != 1){
TSMART_UART_Send(&DEBUG_UART, "SUBACK ERROR\r\n", strlen("SUBACK ERROR\r\n"), 1000/portTICK_RATE_MS);
for(;;);
}
/* Check SUBACK */
if(rcvd_packetid != s_packetid){
sprintf(debug_buffer, "SUBACK ERROR\r\n");
TSMART_UART_Send(&DEBUG_UART, debug_buffer, strlen(debug_buffer), 1000/portTICK_RATE_MS);
for(;;);
}
TSMART_UART_Send(&DEBUG_UART, "OK\r\n", strlen("OK\r\n"), 1000/portTICK_RATE_MS);
/* ******************************************************************************************************************* */
/* MQTT WAIT FOR SUBSCRIPTION QoS: 0 */
/* ******************************************************************************************************************* */
while(1){
TSMART_UART_Send(&DEBUG_UART, "\r\nWaiting for a new message...\r\n", strlen("\r\nWaiting for a new message...\r\n"), 1000/portTICK_RATE_MS);
/*------------------------------------------------ CELULLAR 2G Interface ----------------------------------------------*/
/* Receive */
memset(mqtt_serial_buffer_rx, 0x00, sizeof(mqtt_serial_buffer_rx));
ret = TSMART_CELLULAR_2G_ReceiveTcpData(&tsmart_cellular_2g, mqtt_serial_buffer_rx, 0xFFFFFFFF);
/*-----------------------------------------------------------------------------------------------------------*/
if(ret > 0){
if(mqtt_serial_buffer_rx[0]>>4 == PUBLISH){
/* Get subscription payload length */
s_publish_lenght = mqtt_serial_buffer_rx[1];
/* Deserialize publish subscription */
if(MQTTDeserialize_publish(&s_dup, &s_qos, &s_retained, &s_packetid, s_received_topic, &s_payload_in, &s_payloadlen_in, mqtt_serial_buffer_rx, s_publish_lenght) == 1){
/* Get topic */
memset(topic_recived_buffer, 0x00, sizeof(topic_recived_buffer));
memcpy(topic_recived_buffer, s_received_topic->lenstring.data, s_received_topic->lenstring.len);
/* Display information received */
sprintf(debug_buffer,
"---- message received ----\r\n"
"lenght: %d DUP: %d Retain: %d\r\n"
"PacketId: %d QoS: %d Topic: %s\r\n"
"Data(%d bytes): %s \r\n"
"-------------------------------\r\n",
s_publish_lenght, s_dup, s_retained,
s_packetid, s_qos, topic_recived_buffer,
s_payloadlen_in, s_payload_in);
TSMART_UART_Send(&DEBUG_UART, debug_buffer, strlen(debug_buffer), 1000/portTICK_RATE_MS);
}
}
}
}
/* Wait forever */
for(;;);
}/* End task */
/*
* @brief init() function
*
* This is the first thing that the user must do for using TSmarT.
* It initializes the specific hardware resources (CELLULAR, GPS, AI, DIO, MODBUS, MSA...)
* and software resources (queues, mutex, tasks...) for the user application.
*
* The way to fill in this function properly is to initialize first
* hardware resources and after that software resources.
*
* This function must return: TSMART_PASS when every thing is OK or
* TSMART_FAIL when a failure happened.
*
* @return
* @arg TSMART_PASS
* @arg TSMART_FAIL
*/
int32_t init() {
/* Variables */
tsmart_uart_config_t tsmart_uart_config;
/*----------------------- Debug Mode ----------------------------------------*/
/*----------------------- Initialize resources ------------------------------*/
/* Initilialize cellular 2g */
return TSMART_FAIL;
}
/* Initialize Debug UART */
tsmart_uart_config.baud_rate = 115200;
tsmart_uart_config.flow_control = TSMART_UART_FC_NONE;
tsmart_uart_config.parity_bit = TSMART_UART_PARITY_NONE;
tsmart_uart_config.word_length = TSMART_UART_WORDLENGTH_8B;
tsmart_uart_config.stop_bit = TSMART_UART_STOPBITS_1;
tsmart_uart_config.rx_buf_sz = APP_RX_BUFFER_SZ;
tsmart_uart_config.rx_buf = app_rx_buf;
tsmart_uart_config.use_dma = TSMART_UART_DMA_RX_TX;
tsmart_uart_config.use_tim = TSMART_UART_TIM_SW;
TSMART_UART_Init(&DEBUG_UART, &tsmart_uart_config);
/*----------------------- Application task ----------------------------------*/
/* Create cellular 2g task */
if(xTaskCreate(vCELLULAR_2G, "CELLULAR_2G", 2048, NULL, 8, NULL) != pdPASS){
return TSMART_FAIL;
}
/* Everything OK */
return TSMART_PASS;
}