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

This is an example of how to manage the SIGFOX Network using the Sigfox TD device.

/* @file sigfox_td.c
* @author TST
* @version 0.2
* @date 10/04/2014
* @brief This is an example of how to manage the SIGFOX Network using the Sigfox TD device.
*
* This example shows users how to get start with the SIGFOX TD device library to send information
* to the Sigfox Network.
* This example configures the Sigfox TD module and does two differents sendings:
* - Information frame: it's a frame with user information.
* - Test frame: it's a test frame. It only send a sequence number.
*
*
* @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
*
*/
/* ------------------------------------------------ Platform headers ------------------------------------------------ */
#include "tsmart.h"
/* ------------------------------------------------ Debug UART Parameters ------------------------------------------- */
#define DEBUG_UART tsmart_uart2
#define APP_RX_BUFFER_SZ 1
uint8_t app_rx_buf[APP_RX_BUFFER_SZ];
uint8_t debug_buffer[1000];
/* ------------------------------------------------ Sigfox parameters ----------------------------------------------- */
#define FREQUENCY 868000000 /* MHz */
#define MAX_TIMEOUT_TO_SEND_SIGFOX_TEST_MESSAGES 40000 /* 20 seconds */
uint8_t sigfox_cmd_answer[1000];
void vSIGFOX(void *pvParameters) {
/* Variables */
uint8_t payload[18];
uint8_t payload_size;
uint8_t i = 0;
TSMART_UART_Send(&DEBUG_UART, "\r\n\r\n>----- Sigfox Example -----<\r\n", strlen("\r\n\r\n>----- Sigfox Example -----<\r\n"), 1000/portTICK_RATE_MS);
/* **************************************************************************************************************************** */
/* Configure Sigfox TD device */
/* **************************************************************************************************************************** */
TSMART_UART_Send(&DEBUG_UART, "Configuring SIGFOX device......", strlen("Configuring SIGFOX device......"), 1000/portTICK_RATE_MS);
vTaskDelay(1000/portTICK_RATE_MS);
for(;;);
}
}
TSMART_UART_Send(&DEBUG_UART, "OK\r\n", strlen("OK\r\n"), 1000/portTICK_RATE_MS);
/* **************************************************************************************************************************** */
/* Send Command */
/* **************************************************************************************************************************** */
for(i=0; i<= 11; i++){
memset(sigfox_cmd_answer, 0x00, sizeof(sigfox_cmd_answer));
/* Display */
if(TSMART_SIGFOX_TD_SendCommand(&tsmart_sigfox_td, i, sigfox_cmd_answer) != TSMART_PASS){
for(;;);
}
switch(i){
case 0:
sprintf(debug_buffer, "Manufacturer: %s\r\n", sigfox_cmd_answer);
break;
case 1:
sprintf(debug_buffer, "Firmware date: %s\r\n", sigfox_cmd_answer);
break;
case 2:
sprintf(debug_buffer, "RF Serial Number: %s\r\n", sigfox_cmd_answer);
break;
case 3:
sprintf(debug_buffer, "Baseband unique id: %s\r\n", sigfox_cmd_answer);
break;
case 4:
sprintf(debug_buffer, "HW rev: %s\r\n", sigfox_cmd_answer);
break;
case 5:
sprintf(debug_buffer, "FW rev: %s\r\n", sigfox_cmd_answer);
break;
case 6:
sprintf(debug_buffer, "RF chip part number: %s\r\n", sigfox_cmd_answer);
break;
case 7:
sprintf(debug_buffer, "RF Chip ROM ID: %s\r\n", sigfox_cmd_answer);
break;
case 8:
sprintf(debug_buffer, "Module Temperature: %s\r\n", sigfox_cmd_answer);
break;
case 9:
sprintf(debug_buffer, "Module Idle power supply voltage: %s\r\n", sigfox_cmd_answer);
break;
case 10:
sprintf(debug_buffer, "Module RF active power supply voltage: %s\r\n", sigfox_cmd_answer);
break;
case 11:
sprintf(debug_buffer, "\r\n\r\n<------- Configuration ------->\r\n%s\r\n\r\n", sigfox_cmd_answer);
break;
}
TSMART_UART_Send(&DEBUG_UART, debug_buffer, strlen(debug_buffer), 1000/portTICK_RATE_MS);
vTaskDelay(10/portTICK_RATE_MS);
}
/* **************************************************************************************************************************** */
/* Check device */
/* **************************************************************************************************************************** */
TSMART_UART_Send(&DEBUG_UART, "Check device...............................", strlen("Check device..............................."), 1000/portTICK_RATE_MS);
for(;;);
}
TSMART_UART_Send(&DEBUG_UART, "OK\r\n", strlen("OK\r\n"), 1000/portTICK_RATE_MS);
/* **************************************************************************************************************************** */
/* Set working frecuency */
/* **************************************************************************************************************************** */
TSMART_UART_Send(&DEBUG_UART, "Setting working frequency..................", strlen("Setting working frequency.................."), 1000/portTICK_RATE_MS);
if( TSMART_SIGFOX_TD_SetFrequency(&tsmart_sigfox_td, FREQUENCY) != TSMART_PASS){
for(;;);
}
TSMART_UART_Send(&DEBUG_UART, "OK\r\n", strlen("OK\r\n"), 1000/portTICK_RATE_MS);
/* **************************************************************************************************************************** */
/* Sigfox Keep-AliveS300 */
/* **************************************************************************************************************************** */
TSMART_UART_Send(&DEBUG_UART, "SIGFOX Keep Alive S300.....................", strlen("SIGFOX Keep Alive S300....................."), 1000/portTICK_RATE_MS);
for(;;);
}
TSMART_UART_Send(&DEBUG_UART, "OK\r\n", strlen("OK\r\n"), 1000/portTICK_RATE_MS);
/* **************************************************************************************************************************** */
/* Sigfox Keep-AliveS301 */
/* **************************************************************************************************************************** */
TSMART_UART_Send(&DEBUG_UART, "SIGFOX Keep Alive S301.....................", strlen("SIGFOX Keep Alive S301....................."), 1000/portTICK_RATE_MS);
for(;;);
}
TSMART_UART_Send(&DEBUG_UART, "OK\r\n", strlen("OK\r\n"), 1000/portTICK_RATE_MS);
/* **************************************************************************************************************************** */
/* Sigfox Power Level */
/* **************************************************************************************************************************** */
TSMART_UART_Send(&DEBUG_UART, "SIGFOX RF power level......................", strlen("SIGFOX RF power level......................"), 1000/portTICK_RATE_MS);
for(;;);
}
TSMART_UART_Send(&DEBUG_UART, "OK\r\n", strlen("OK\r\n"), 1000/portTICK_RATE_MS);
/* **************************************************************************************************************************** */
/* Sigfox Send Data */
/* **************************************************************************************************************************** */
payload[0] = 0x00; /* Byte 1 */
payload[1] = 0x01; /* Byte 2 */
payload[2] = 0x02; /* Byte 3 */
payload[3] = 0x03; /* Byte 4 */
payload[4] = 0x04; /* Byte 5 */
payload[5] = 0x05; /* Byte 6 */
payload[6] = 0x06; /* Byte 7 */
payload[7] = 0x07; /* Byte 8 */
payload[8] = 0x08; /* Byte 9 */
payload[9] = 0x09; /* Byte 10 */
payload[10] = 0x0A; /* Byte 11 */
payload[11] = 0x0B; /* Byte 12 */
payload_size = 12;
TSMART_UART_Send(&DEBUG_UART, "SIGFOX Send RF message(12 Bytes)...........", strlen("SIGFOX Send RF message(12 Bytes)..........."), 1000/portTICK_RATE_MS);
if(TSMART_SIGFOX_TD_SfSendRfMesssage(&tsmart_sigfox_td, payload, payload_size) != TSMART_PASS){
for(;;);
}
TSMART_UART_Send(&DEBUG_UART, "OK\r\n", strlen("OK\r\n"), 1000/portTICK_RATE_MS);
/* **************************************************************************************************************************** */
/* SIGFOX Send Test RF message */
/* **************************************************************************************************************************** */
TSMART_UART_Send(&DEBUG_UART, "SIGFOX Send RF test message................", strlen("SIGFOX Send RF test message................"), 1000/portTICK_RATE_MS);
if(TSMART_SIGFOX_TD_SfSendRfTestMesssage(&tsmart_sigfox_td, 5, 2, -1, MAX_TIMEOUT_TO_SEND_SIGFOX_TEST_MESSAGES) != TSMART_PASS){
for(;;);
}
TSMART_UART_Send(&DEBUG_UART, "OK\r\n", strlen("OK\r\n"), 1000/portTICK_RATE_MS);
for(;;);
}
/* @brief "Init()" function.
*
* This is the first thing that the user must do for using TSmarT.
* It initializes specific hardware resources (GPRS, 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 */
static tsmart_uart_config_t uart_config;
/* ************************************************************************* */
/* Debug Mode */
/* ************************************************************************* */
/* ************************************************************************* */
/* Initialize resources */
/* ************************************************************************* */
/* Initialize Debug UART */
uart_config.baud_rate = 115200;
uart_config.flow_control = TSMART_UART_FC_NONE;
uart_config.parity_bit = TSMART_UART_PARITY_NONE;
uart_config.word_length = TSMART_UART_WORDLENGTH_8B;
uart_config.stop_bit = TSMART_UART_STOPBITS_1;
uart_config.rx_buf_sz = APP_RX_BUFFER_SZ;
uart_config.rx_buf = app_rx_buf;
uart_config.use_dma = TSMART_UART_DMA_RX_TX;
uart_config.use_tim = TSMART_UART_TIM_SW;
TSMART_UART_Init(&DEBUG_UART, &uart_config);
/* Initilize Sigfox TD device */
return TSMART_FAIL;
}
/* ************************************************************************* */
/* Application task */
/* ************************************************************************* */
/* Create Sigfox task */
if(xTaskCreate(vSIGFOX, "Sigfox", 1024, NULL, 7, NULL) != pdPASS){
return TSMART_FAIL;
}
/* Everything OK */
return TSMART_PASS;
}