Ftp


#1

Hello everybody !!

I’ve got a big problem.
The sample Ftp doesn’t work. I use the last version of this sample and the handler of dtl_srvSubscribe function doesn’t receive any event.
I wonder if the sample really does the configuration of the IP connection and I think there is no connection function.
So have I added these functions in the sample but, after many tests, I have this message from the handler of dtl_srvSubscribe function:
“DTL_SRV_EVENT_IP_CONNECTION_FAILURE”. It corresponds to an “open gprs internal session failed” and I don’t understand my problem.
Please help me !!


#2

See below, an example on how to use the FTP (the comments are in portuguese, sorry about that) 8)

When you create this project, do not forget to add the following line at the wmnew field

-otherlib TCPIP/V3.02 (this is for Open AT 3.02)

/***************************************************************************
PI Componentes - Gustavo M. Nunes

Objetivo:  Enviar um arquivo texto para um servidor FTP

Descricao:
			1) Criar um comando "at+ftp" que inicia a trasnferencia FTP

Upgrades:  --//--

Data Criacao:		22-Fev-2006
Ultima Atualizacao: 22-Fev-2006
/***************************************************************************/

#include "adl_global.h"

#include "ed_gprs.h"
#include "ed_dialup.h"

#include "ed_ftp.h"
#include "ed_msgcodes.h"

/***************************************************************************
	Mandatory variables
----------------------------------------------------------------------------
	wm_apmCustomStack
	wm_apmCustomStackSize
----------------------------------------------------------------------------
****************************************************************************/

u32 wm_apmCustomStack [ 256 ];
const u16 wm_apmCustomStackSize = sizeof ( wm_apmCustomStack );

ed_gprsSetupParams_t	ParamsGPRS;	
ed_FTPSetupParams_t		ParamsFTP;
ed_FTPPutFileParams_t	ParamsFile;

/***************************************************************************
	Function   : Config
----------------------------------------------------------------------------
	Description: Setup every information for parameters
----------------------------------------------------------------------------
	Variable Name     |IN |OUT|GLB|  Utilisation
----------------------+---+---+---+-----------------------------------------
		              |   |   |   | 
----------------------+---+---+---+-----------------------------------------
****************************************************************************/
void Config (){

	//Configuracao da conexao GPRS com o operadora

	ParamsGPRS.Cid = 1; //Configura canal 1 de conexao (4 canais estao disponiveis)
	ParamsGPRS.Mode = 1; //Configura o modem para conexao GPRS

	wm_strcpy(ParamsGPRS.ApnServ,"tim.br");  //APN da servidora TIM

	wm_strcpy(ParamsGPRS.ApnUn,"tim");
	wm_strcpy(ParamsGPRS.ApnPw,"tim");

	//FTP configuration

	ParamsFTP.FtpPort = 21;
	ParamsFTP.FtpType = 'A';
	wm_strcpy(ParamsFTP.FtpServ,"200.162.41.205");
	wm_strcpy(ParamsFTP.FtpUn,"xx");
	wm_strcpy(ParamsFTP.FtpPw,"xx");

	wm_strcpy(ParamsFile.FtpPutFilename,"testeftp01.txt");
	wm_strcpy(ParamsFile.FtpPutPath,".");

}

/***************************************************************************
	Function   : FtpPutHandler
----------------------------------------------------------------------------
	Description: Callback dos eventos da conexao FTP
----------------------------------------------------------------------------
	Variable Name     |IN |OUT|GLB|  Utilisation
----------------------+---+---+---+-----------------------------------------
	ResponseCode      |   |   |   |  Report FTP status 
----------------------+---+---+---+-----------------------------------------
	id                |   |   |   |  Sempre retorna ED_ID_FTP_PUT
----------------------+---+---+---+-----------------------------------------
****************************************************************************/
void FtpPutHandler(s32 ResponseCode,TeDHandle id){

	char msg[20];

	sprintf(msg,"Put Handler: %d\n\r",ResponseCode);

	adl_atSendResponse ( ADL_AT_UNS, msg);

}

/***************************************************************************
	Function   : FtpPutData
----------------------------------------------------------------------------
	Description: Essa funcao é chamada quando o servidor FTP esta apto a 
				 receber arquivos
----------------------------------------------------------------------------
	Variable Name     |IN |OUT|GLB|  Utilisation
----------------------+---+---+---+-----------------------------------------
	MaxLen            |   |   |   |  Numero maximo de bytes que podem ser
					  |   |   |   |  enviados no momento
----------------------+---+---+---+-----------------------------------------
	id                |   |   |   |  Sempre retorna ED_ID_FTP_PUT
----------------------+---+---+---+-----------------------------------------
****************************************************************************/
void FtpPutData(u16 MaxLen,TeDHandle id){

	ascii teste[100]="Exemplo FTP - PI Componentes";

	u8	* ptr = NULL;

	ptr = teste;

	adl_atSendResponse ( ADL_AT_UNS, "FTP Put Data Event\n\r");

	ed_SendData(ptr,strlen(teste),TRUE);

}

/***************************************************************************
	Function   : ConexaoFTP
----------------------------------------------------------------------------
	Description: Inicia conexao com o FTP e trasmissao do arquivo
----------------------------------------------------------------------------
****************************************************************************/
void ConexaoFTP ()
{

	//Variaveis
	char msg[20];
	s8 sreturnCode;

	sreturnCode = ed_FTPSetConfig(&ParamsFTP);

	if(sreturnCode==0)
	{

		//FTP configuration ok

		adl_atSendResponse ( ADL_AT_UNS, "FTP configurado com sucesso\n\r");

		sreturnCode = ed_FTPPutFileSetConfig(&ParamsFile);

		if(sreturnCode==0){

			//Paramentros do arquivo configurado com sucesso
			adl_atSendResponse ( ADL_AT_UNS, "Arquivo FTP configurado com sucesso\n\r");
				
			//Iniciar transferencia FTP
			ed_FTPPut(FtpPutHandler,FtpPutData);

		}else{

			//Falha na configuracao do arquivo
			adl_atSendResponse ( ADL_AT_UNS, "Erro na configuracao do arquivo FTP\n\r");

		}

	}else{

		//FTP configuration failed

		adl_atSendResponse ( ADL_AT_UNS, "Erro nos parametros FTP\n\r");

		sprintf(msg,"+Erro: %d\n\r",sreturnCode);

		adl_atSendResponse ( ADL_AT_UNS, msg);

	}
}

/***************************************************************************
	Function   : DialupHandler
----------------------------------------------------------------------------
	Description: ed_DialupConnectionStart Handler
----------------------------------------------------------------------------
	Variable Name     |IN |OUT|GLB|  Utilisation
----------------------+---+---+---+-----------------------------------------
	ResponseCode      |   |   |   |  Report Dialup status 
----------------------+---+---+---+-----------------------------------------
****************************************************************************/
void DialupHandler(s32 ResponseCode){

	char msg[20];
	s8 sreturnCode;

	switch (ResponseCode){

	case ED_OK_GPRS_SESSION_SET:  // GPRS online


		adl_atSendResponse ( ADL_AT_UNS, "GPRS conectado\n\r");

		//Inicia conexao FTP
		ConexaoFTP();

		break;
	default:

		//Erro na conexao GPRS
		adl_atSendResponse ( ADL_AT_UNS, "Erro na conexao GPRS\n\r");

		break;
	}
}

/***************************************************************************
	Function   : TimerHandler
----------------------------------------------------------------------------
	Description: adl_tmrSubscribe Handler
----------------------------------------------------------------------------
	Variable Name     |IN |OUT|GLB|  Utilisation
----------------------+---+---+---+-----------------------------------------
	tmerId            |   |   |   |  Say which time Id is running at the
					  |   |   |   |	 moment
----------------------+---+---+---+-----------------------------------------
****************************************************************************/
void TimerHandler(u8 timerId){

	char msg[20];
	s8	sreturnCode;

	sreturnCode = ed_DialupConnectionStart(DialupHandler);

	if(sreturnCode == 0){

		//GPRS Conectado

		adl_atSendResponse ( ADL_AT_UNS, "Diaul up Ok\n\r");

	}else{

		//Verifica se GPRS ja nao esta conectado
		if(sreturnCode == ED_ERR_MODEM_RUNNING)
		{
			adl_atSendResponse ( ADL_AT_UNS, "GPRS ja conectado\n\r");

			ConexaoFTP ();

		}else{

			//Falha na conexao GPRS

			adl_atSendResponse ( ADL_AT_UNS, "Falha no Dial Up\n\r");

			sprintf(msg,"+Erro: %d\n\r",sreturnCode);

			adl_atSendResponse ( ADL_AT_UNS, msg);
		}

	}
}

/***************************************************************************
	Function   : GPRSHandler
----------------------------------------------------------------------------
	Description: Callback do comando "at+cgatt=1" que é enviado pela funcao
				 GPRSConnection
----------------------------------------------------------------------------
	Variable Name     |IN |OUT|GLB|  Utilisation
----------------------+---+---+---+-----------------------------------------
	paras             |   |   |   |  CmdCreate answer
----------------------+---+---+---+-----------------------------------------
****************************************************************************/
bool GPRSHandler(adl_atResponse_t *paras){

	s8		sreturnCode = ERROR;
	char	msg[20];

	if( !wm_strncmp(paras->StrData,"\r\nOK",4)){

		//Comando AT+CGATT executado com sucesso

		sreturnCode = ed_GprsSetConfig(&ParamsGPRS);

		if (sreturnCode == 0){

			//Parametros OK
			adl_atSendResponse ( ADL_AT_UNS, "Parametros Ok\n\r");

			adl_tmrSubscribe(FALSE,10,ADL_TMR_TYPE_100MS,TimerHandler);
			
		}else{

			//Parametros com erro
			adl_atSendResponse ( ADL_AT_UNS, "Erro nos parametros GPRS\n\r");

			sprintf(msg,"+Erro: %d\n\r",sreturnCode);

			adl_atSendResponse ( ADL_AT_UNS, msg);
		}
	}else{

		//Erro ao tentar usar o comando AT+CGATT
		adl_atSendResponse ( ADL_AT_UNS, "Falha na conexao GPRS\n\r");
	}	

	return TRUE;
}

/***************************************************************************
	Function   : GPRSConnection
----------------------------------------------------------------------------
	Description: Inicia conexao GPRS
----------------------------------------------------------------------------
****************************************************************************/
void GPRSConnection (){

	adl_atSendResponse ( ADL_AT_UNS, "Abrindo conexao GPRS...\n\r");

	adl_atCmdCreate("AT+CGATT=1",TRUE,GPRSHandler,"*",NULL);
}

/***************************************************************************
	Function   : AtFTP
----------------------------------------------------------------------------
	Description: Callback do comando "at+ftp"
----------------------------------------------------------------------------
	Variable Name     |IN |OUT|GLB|  Utilisation
----------------------+---+---+---+-----------------------------------------
	paras             |   |   |   | Parametros do comando
----------------------+---+---+---+-----------------------------------------
****************************************************************************/
void AtFTP(adl_atCmdPreParser_t * paras)
{
	//Inicia conexao GPRS
	GPRSConnection();

	//Mensagem de retorno do comando AT
	adl_atSendResponse ( ADL_AT_RSP, "OK\n\r");
}

/***************************************************************************
	Function   : SimCard
----------------------------------------------------------------------------
	Description: Display the SimCard Events
----------------------------------------------------------------------------
	Variable Name     |IN |OUT|GLB|  Utilisation
----------------------+---+---+---+-----------------------------------------
	Event             |   |   |   | Sim Card Events
----------------------+---+---+---+-----------------------------------------
****************************************************************************/
void SimCard (u8 Event){

	switch(Event){

	//Normal Events
	case ADL_SIM_EVENT_PIN_OK:
			adl_atSendResponse ( ADL_AT_UNS, "PIN Code Ok\n\rConectando...\n\r");
	break;
	case ADL_SIM_EVENT_REMOVED:
			adl_atSendResponse ( ADL_AT_UNS, "SimCard Removido\n\r");
	break;
	case ADL_SIM_EVENT_INSERTED:
			adl_atSendResponse ( ADL_AT_UNS, "SimCard Inserido\n\r");
	break;
	case ADL_SIM_EVENT_FULL_INIT:
			adl_atSendResponse ( ADL_AT_UNS, "Conectado !\n\r");

			//Cria comando para conectar no servidor FTP
			adl_atCmdSubscribe("at+ftp",AtFTP,ADL_CMD_TYPE_ACT);
	break;

	//Error Events
	case ADL_SIM_EVENT_PIN_ERROR:
			adl_atSendResponse ( ADL_AT_UNS, "PIN Code Incorreto\n\r");
	break;

	/*Erro quando se e necessario inserir o PIN Code.
	  Por comandos AT, insera o PIN Code usando
	  AT+CPIN="xxxx", onde xxxx e o codigo de 4 digitos*/
	case ADL_SIM_EVENT_PIN_WAIT:
			adl_atSendResponse ( ADL_AT_UNS, "Entre com o PIN Code\n\r");
	break;
	}
}

/***************************************************************************
	Function   : adl_main
----------------------------------------------------------------------------
	Description: Main function
----------------------------------------------------------------------------
	Variable Name     |IN |OUT|GLB|  Utilisation
----------------------+---+---+---+-----------------------------------------
	InitType          |   |   |   | Application start mode reason
----------------------+---+---+---+-----------------------------------------
****************************************************************************/
void adl_main ( adl_InitType_e InitType )
{
	//Inicio da aplicacao
	adl_atSendResponse(ADL_AT_UNS, "\n\rInicio da aplicacao\n\r");

	//Executa a funcao SimCard a cada evento que ocorrer
	adl_simSubscribe(SimCard,NULL);

	//Inicializaçao das bibliotecas IP
	ed_Init();

	//Configura parametros diversos
	Config();
	
}

#3

Hi Gmnvh !!
Thank you for your sample. No problem for the comments in portuguese, it’s not too far from my own language (French :smiley: ).
I’ll try to run this program…


#4

Hi fanfan,

Did you get the example (in portuguese)working?

Mark


#5

hey guys ,
i tried same example but getting many erros… cant includes the header files
#include “ed_gprs.h”
#include “ed_dialup.h”

#include “ed_ftp.h”
#include “ed_msgcodes.h”


#6

Those are headers for the old, withdrawn, ED-Lib TCP/IP stuff - not WIP.


#7

I have a Fastrack Supreme with FW7.1b. Are there any sample FTP programs that works with latest WIP APIs? Are there any sample code which parses AT commands from SMS received and then executes an FTP_GET (server name, login password parameters sent via SMS)? Any help is appreciated.

Thanks
Yash