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

This is an example about how to send a file using the cellular 2G device.

/* @file main.c
* @author TST
* @version 0.1
* @date 28/01/2013
* @brief This is an example of how to send a file using the cellular 2G device.
*
* The cellular 2G in use is a SL6087 2G module manufactured by Sierra wireless.
* This example sends a file to remote FTP server using the FTP protocol working
* with a 2G network.
*
*
* @note To run this application it's necessary to set some network parameters:
* - PIN code -------> Personal identification number.
* - APN ------------> Access Point Name.
* - Login ----------> Network user name.
* - Password -------> Network password.
*
* And the remote FTP parameters:
* - IP ----------> Remote FTP IP address.
* - Folder ------> Enabled folder to receive a FTP file.
* - User --------> FTP user.
* - Password ----> FTP password.
*
* User shall set them in the definitions below.
*
*
*/
/* Platform headers */
#include "tsmart.h"
/* Specific configuration for cellullar 2g, Set definitions */
/* Set SIM configuration */
#define PIN_CODE "<SET PIN CODE>"
/* Access point network parameters */
#define APN "<SET APN>"
#define LOGIN "<SET LOGIN>"
#define PASSWORD "<SET PASSWORD>"
/* Set FTP server parameters */
#define FTP_SERVER_IP "<SET REMOTE FTP ADDRESS>" /* IP address of the remote FTP server */
#define FTP_SERVER_PORT 21 /* Remote FTP server port. Port = 21 is the most usual port, change it if your FTP server works with other port */
#define FTP_SERVER_USER "<SET USER>" /* User */
#define FTP_SERVER_PASSWORD "<SET PASSWORD>" /* Password */
#define FTP_SERVER_FOLDER "<SET FOLDER>" /* Folder. i.e.: "./cel" */
/* File Settings */
#define FTP_FILE_TYPE 0
#define FTP_FILE_MODE 1
#define FTP_FILE_NAME "cellular_2g.txt"
#define FTP_FILE_MESSAGE "TSmarT makes it happen"
/* @brief vCEL2G_FTP_send task
*
* This task turns on and sets the stack TCP/IP and the network parameters for
* the cellular 2g device for this application. After that it create a FTP
* client. Then it sends a file to the remote FTP server and the client will be
* closed.
*
*
* @param pvParameters
*/
void vCEL2G_FTP_SEND(void *pvParameters) {
/* Variables */
/* Turn On */
if(TSMART_CELLULAR_2G_TurnOn(&tsmart_cellular_2g, PIN_CODE) != TSMART_PASS){
for(;;);
}
/* Configure module */
if( TSMART_CELLULAR_2G_ConfigDevice(&tsmart_cellular_2g, &device_config) != TSMART_PASS){
for(;;);
}
/* Start stack */
/* Stop stack */
for(;;);
}
/* Start stack */
for(;;);
}
}
/* 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){
for(;;);
}
/* 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){
for(;;);
}
/* Start Bearer */
for(;;);
}
do{
/* Wait to register in GPRS network */
/* Wait for 1 second to try again */
vTaskDelay(1000/portTICK_RATE_MS);
/* Debug message */
do{
/* Check Attach */
/* Wait for 1 second to try again */
vTaskDelay(1000/portTICK_RATE_MS);
}while( attach != TSMART_CELLULAR_2G_ATTACHED );
/* Open FTP client */
ftp_client.id_session = 1;
ftp_client.remote_ip = FTP_SERVER_IP;
ftp_client.remote_port = FTP_SERVER_PORT;
ftp_client.user = FTP_SERVER_USER;
ftp_client.password = FTP_SERVER_PASSWORD;
ftp_client.file_type = FTP_FILE_TYPE;
ftp_client.mode = FTP_FILE_MODE;
if( TSMART_CELLULAR_2G_CreateFtpClient(&tsmart_cellular_2g, &ftp_client, 20000) != TSMART_PASS){
for(;;);
}
/* Send ASCII information */
if(TSMART_CELLULAR_2G_SendFtpFile(&tsmart_cellular_2g, ftp_client.id_session, FTP_SERVER_FOLDER, FTP_FILE_NAME, FTP_FILE_MESSAGE, sizeof(FTP_FILE_MESSAGE)) != TSMART_PASS){
for(;;);
}
for(;;);
}
/* Wait forever */
while(1);
}
/* @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 */
portBASE_TYPE xReturn;
/* ************************************************************************* */
/* Debug Mode */
/* ************************************************************************* */
/* ************************************************************************* */
/* Initialize resources */
/* ************************************************************************* */
/* The specific hardware for this application: cellular 2G
*/
return TSMART_FAIL;
}
/* ************************************************************************* */
/* Application task */
/* ************************************************************************* */
/* This examples will need one task:
*
* - vCEL2G_FTP_SEND task: This task turn on the cellular 2g, configures it and sends
* a file to the remote FTP server.
*
*/
/* Create GPRS_FTP_SEND Task */
xReturn = xTaskCreate(vCEL2G_FTP_SEND, "GPRS_FTP_SEND", 512, NULL, 7, NULL);
if (xReturn != pdPASS) {
return TSMART_FAIL;
}
/* Everything OK */
return TSMART_PASS;
}