Treating Connection Status


#1

Hi, I am as others have already been… through problems treating problems wiith connection.

I´m using ed_lib and after calling a “SocketStart” function sometimes I can´t place a connection with the server.

How are you treating these problems?

Here´s what I´m doing:

void SocketResponseCbk (s32 ResponseCode, TeDHandle id)
{
	ascii Buff[50];

	adl_atSendResponse(ADL_AT_UNS, "\r\nSocketResponseCbk();\r\n");
	
	wm_sprintf(Buff, "\n\r SocketResponseCbk :%d\n\r", ResponseCode);
	adl_atSendResponse(ADL_AT_RSP, Buff);

	switch(ResponseCode)
	{
		case ED_OK_TCP_CLOSED :	
								SocketOk = FALSE;
								adl_atSendResponse(ADL_AT_RSP,"\n\rSOCKET FECHADO - REABRINDO !\n\r");
								//ed_SocketTCPStart(ED_ID_TCPSOCKET_1, CLIENT, (ed_ResponseCbk_f) SocketResponseCbk,
												 //(ed_DataHandler_f) SocketDataHnd, (ed_DataRequest_f) SocketDataRequest);	
			TimeToStartSocketHandle = adl_tmrSubscribe (TRUE,50,ADL_TMR_TYPE_100MS, (adl_tmrHandler_t)TimeToStartSocket);
			
								break;
		case ED_INFO_WAITING_FOR_DATA :
								SocketOk = TRUE;
								adl_atSendResponse(ADL_AT_RSP,"\n\rSOCKET ESPERANDO DADOS\n\r");
								adl_tmrUnSubscribe (TimeToStartSocketHandle,(adl_tmrHandler_t)TimeToStartSocket,ADL_TMR_TYPE_100MS);
								break;
		case ED_INFO_LISTEN_SET:
								adl_atSendResponse(ADL_AT_UNS, "\r\nSOCKET CRIADO\r\n");
								adl_tmrUnSubscribe (TimeToStartSocketHandle,(adl_tmrHandler_t)TimeToStartSocket,ADL_TMR_TYPE_100MS);
								FirstTime = TRUE;
								SocketOk = TRUE;
								break;
		case ED_ERR_NO_HIGH_LEVEL_INTERNET:
			TRACE((1, "ED_ERR_NO_HIGH_LEVEL_INTERNET"));
			break;
		case ED_ERR_TCPIP_ALREADYUSED:  
			TRACE((1, "ED_ERR_TCPIP_ALREADYUSED"));
			break;
		case ED_ERR_PARAM_WRITE_E2P:  
			TRACE((1, "ED_ERR_PARAM_WRITE_E2P"));
			break;
		case ED_ERR_PARAM_READ_E2P:  
			TRACE((1, "ED_ERR_PARAM_READ_E2P"));
			break;
		case ED_ERR_PARAM_BAD_VALUE:   
			TRACE((1, "ED_ERR_PARAM_BAD_VALUE"));
			break;
		case ED_ERR_PARAM_TOO_LONG:   
			TRACE((1, "ED_ERR_PARAM_TOO_LONG"));
			break;
		case ED_ERR_INVALID_ARG:    
			TRACE((1, "ED_ERR_INVALID_ARG"));
            break;
		case ED_ERR_MODEM_RUNNING:    
			TRACE((1, "ED_ERR_MODEM_RUNNING"));
			break;
		case ED_ERR_INVALID_RING_TYPE: 
			TRACE((1, "ED_ERR_INVALID_RING_TYPE"));
			break;
		case ED_ERR_PIN_NOT_ENTERED:     
			TRACE((1, "ED_ERR_PIN_NOT_ENTERED"));
			break;
		case ED_ERR_PHY_NOT_ACTIVATED:     
			TRACE((1, "ED_ERR_PHY_NOT_ACTIVATED"));
			break;
		case ED_ERR_STACK_BAD_CONFIG:   
			TRACE((1, "ED_ERR_STACK_BAD_CONFIG"));
			break;
		case ED_ERR_STACK_BUSY:         
			TRACE((1, "ED_ERR_STACK_BUSY"));
			break;
		case ED_ERR_NETWORK_KO:         
			TRACE((1, "ED_ERR_NETWORK_KO"));
			break;
		case ED_ERR_SIM_REMOVED:        
			TRACE((1, "ED_ERR_SIM_REMOVED"));
			break;
		case ED_ERR_ON_HOOK:             
			TRACE((1, "ED_ERR_ON_HOOK"));
			break;
		case ED_ERR_BUSY:            
			TRACE((1, "ED_ERR_BUSY"));
			break;
		case ED_ERR_NO_CARRIER: 
			adl_atSendResponse(ADL_AT_UNS, "\r\n**ERRO: No Carrier**\r\n");
			break;
		case ED_ERR_PPP_ERROR: 
			adl_atSendResponse(ADL_AT_UNS, "\r\n**ERRO: PPP**\r\n");
			break;
		case ED_ERR_PPP_TIMEOUT:  
			adl_atSendResponse(ADL_AT_UNS, "\r\n**ERRO: PPP TimeOut**\r\n");
			break;
		case ED_ERR_INVALID_EVENT:  
            TRACE((1, "ED_ERR_INVALID_EVENT"));
			break;
		case ED_ERR_PHY_TIMEOUT:   
			TRACE((1, "ED_ERR_PHY_TIMEOUT"));
			break;
		case ED_ERR_GPRS_ABORTED: 
			adl_atSendResponse(ADL_AT_UNS, "\r\n**ERRO: Connection with GPRS network aborted**\r\n");
			break;
		case ED_ERR_WM_UNABLE_SUBS_EVENT:   
			TRACE((1, "ED_ERR_WM_UNABLE_SUBS_EVENT"));
			break;
		case ED_ERR_WM_FLOW_OPEN:  
			TRACE((1, "ED_ERR_FLOW_OPEN"));
			break;
		case ED_ERR_WM_FLOW_CLOSE:   
			TRACE((1, "ED_ERR_WM_FLOW_CLOSE"));
			break;
		case ED_ERR_WM_PARSER_FLOW:   
			TRACE((1, "ED_ERR_WM_PARSER_FLOW"));
			break;
		case ED_ERR_WM_GPRS_OPEN:     
			TRACE((1, "ED_ERR_WM_GPRS_OPEN"));
			break;
		case ED_ERR_WM_GPRS_AUTH:  
			TRACE((1, "ED_ERR_WM_GPRS_AUTH"));
			break;
		case ED_ERR_WM_GPRS_IPCP:   
			TRACE((1, "ED_ERR_WM_GPRS_IPCP"));
			break;
		case ED_ERR_STACK_INTERNAL:     
			TRACE((1, "ED_ERR_STACK_INTERNAL"));
			break;
		case ED_ERR_DISTANT_DNS:         
			TRACE((1, "ED_ERR_INSTANT_DNS"));
			break;
		case ED_ERR_DISTANT_NO_RESP: 
			adl_atSendResponse(ADL_AT_UNS, "\r\n**ERROR: No answer from the server**\r\n");

			SocketOk = FALSE;
			ed_SocketTCPStart(ED_ID_TCPSOCKET_1, CLIENT, (ed_ResponseCbk_f) SocketResponseCbk,
						(ed_DataHandler_f) SocketDataHnd, (ed_DataRequest_f) SocketDataRequest);
			break;
		case ED_ERR_DISTANT_OPEN: 

			TRACE((1, "ED_ERR_DISTANT_OPEN"));

			adl_atSendResponse(ADL_AT_UNS, "\r\nED_ERR_DISTANT_OPEN\r\n");

			ServerIndex++;
			ServerIndex = ServerIndex%10;
			SocketFail = TRUE;

			SocketOk = FALSE;
			//ed_SocketTCPStart(ED_ID_TCPSOCKET_1, CLIENT, (ed_ResponseCbk_f) SocketResponseCbk,
						//(ed_DataHandler_f) SocketDataHnd, (ed_DataRequest_f) SocketDataRequest);
			TimeToStartSocketHandle = adl_tmrSubscribe (TRUE,200,ADL_TMR_TYPE_100MS, (adl_tmrHandler_t)TimeToStartSocket);
			break;
		case ED_ERR_DISTANT_CLOSE:   
			adl_atSendResponse(ADL_AT_RSP,"\n\rED_ERR_DISTANT_CLOSE\r\n");
			TRACE((1, "ED_ERR_DISTANT_CLOSE"));
			break;
		case ED_ERR_DISTANT_CCREC_ADDR:    
			TRACE((1, "ED_ERR_DISTANT_CCREC_ADDR"));
			break;
		case ED_ERR_DISTANT_REC_ADDR:       
			TRACE((1, "ED_ERR_DISTANT_REC_ADDR"));
			break;
		case ED_ERR_DISTANT_SENDER_ADDR:    
			TRACE((1, "ED_ERR_DISTANT_SENDER_ADDR"));
			break;
		case ED_ERR_DISTANT_BODY:           
			TRACE((1, "ED_ERR_DISTANT_BODY"));
			break;
		case ED_ERR_DISTANT_SEND:         
			TRACE((1, "ED_ERR_DISTANT_SEND"));
			break;
		case ED_ERR_DISTANT_TCP_CLOSED:     
			adl_atSendResponse(ADL_AT_UNS, "\r\n**ERROR: TCP connection closed / can´t find server**\r\n");
			SocketOk = FALSE;

			ed_SocketTCPStart(ED_ID_TCPSOCKET_1, CLIENT, (ed_ResponseCbk_f) SocketResponseCbk,
						(ed_DataHandler_f) SocketDataHnd, (ed_DataRequest_f) SocketDataRequest);
			break;
		case ED_ERR_DISTANT_TCP_CLOSED_BY_PEER: 
			adl_atSendResponse(ADL_AT_UNS, "\r\n**ERROR: TCP Connection closed by the server**\r\n");
			SocketOk = FALSE;
			ed_SocketTCPStart(ED_ID_TCPSOCKET_1, CLIENT, (ed_ResponseCbk_f) SocketResponseCbk,
						(ed_DataHandler_f) SocketDataHnd, (ed_DataRequest_f) SocketDataRequest);
			break;
		case ED_ERR_DISTANT_USERNAME: 
			TRACE((1, "ED_ERR_DISTANT_USERNAME"));
			break;
		case ED_ERR_DISTANT_PASSWORD: 
			TRACE((1, "ED_ERR_DISTANT_PASSWORD"));
			break;
		case ED_ERR_DISTANT_DATA_RETR:       
			TRACE((1, "ED_ERR_DISTANT_DATA_RETR"));
			break;
		case ED_ERR_DISTANT_EMAIL_RETR:      
			TRACE((1, "ED_ERR_DISTANT_EMAIL_RETR"));
			break;
		case ED_ERR_DISTANT_EMAIL_HDR_RETR:    
			TRACE((1, "ED_ERR_DISTANT_EMAIL_HDR_RETR"));
			break;
		case ED_ERR_DISTANT_DEL:              
			TRACE((1, "ED_ERR_DISTANT_DEL"));
			break;
		case ED_ERR_DISTANT_CD:          
			TRACE((1, "ED_ERR_DISTANT_CD"));
			break;
		case ED_ERR_INVALID_SIZE:   
			TRACE((1, "ED_ERR_INVALID_SIZA"));
            break;
		case ED_ERR_INVALID_CALL:  
			TRACE((1, "ED_ERR_INVALID_CALL"));
			break;
		case ED_ERR_NOT_INIT:     
			TRACE((1, "ED_ERR_NOT_INIT"));
			break;
		case ED_ERR_LISTEN_STOP:
			TRACE((1, "ED_ERR_LISTEN_STOP"));
			break;
		case ED_ERR_NO_LISTEN:	 
			TRACE((1, "ED_ERR_NO_LISTEN"));
			break;
		case ED_ERR_NO_GPRS: 
			adl_atSendResponse(ADL_AT_UNS, "\r\n**ERRO: No GPRS Network**\r\n");
			SocketOk = FALSE;
			ed_SocketTCPStart(ED_ID_TCPSOCKET_1, CLIENT, (ed_ResponseCbk_f) SocketResponseCbk,
						(ed_DataHandler_f) SocketDataHnd, (ed_DataRequest_f) SocketDataRequest);
			break;
		case ED_ERR_NO_ANSWER:   
			TRACE((1, "ED_ERR_NO_ASNWER"));
			break;
		case ED_ERR_CLI_INVALID:  
			TRACE((1, "ED_ERR_CLI_INVALID"));
            break;
		case ED_ERR_NO_REPLY:  
			TRACE((1, "ED_ERR_NO_REPLY"));
			break;
		case ED_ERR_PARAM_BAD_MAILIDX:  
			TRACE((1, "ED_ERR_PARAM_BAD_MAILIDX"));
			break;
		case ED_ERR_GPRS_SESSION_LOST:  
			adl_atSendResponse(ADL_AT_UNS, "\r\n**ERRO: GPRS Session Lost**\r\n");
			SocketOk = FALSE;
			ed_SocketTCPStart(ED_ID_TCPSOCKET_1, CLIENT, (ed_ResponseCbk_f) SocketResponseCbk,
						(ed_DataHandler_f) SocketDataHnd, (ed_DataRequest_f) SocketDataRequest);
			break;
		case ED_ERR_SERVICE_ALREADY_RUNNING:  
			TRACE(( 1, "**ERRO: Service Already Running**"));
			break;
		case ED_ERR_INVALID_ID: 
			TRACE((1, "ED_ERR_INVALID_ID"));
			break;
		case ED_ERR_ID_INACTIVE: 
			TRACE((1, "ED_ERR_ID_INACTIVE"));
            break;
		case ED_ERR_MEMALLOC_FAILED:
			TRACE(( 1, "**ERRO: Memmory Allocation Failed**"));
			break;
		case ED_ERR_SOCKET_CREATION_BUSY:  
			TRACE((1, "ED_ERR_SOCKET_CREATION_BUSY"));
			break;
		case ED_INFO_CONNECT:  
			TRACE((1, "ED_INFO_CONNECT"));
			break;
		case ED_INFO_MAIL:       
			TRACE((1, "ED_INFO_MAIL"));
			break;
		case ED_INFO_NOMAIL:    
			TRACE((1, "ED_INFO_NOMAIL"));
			break;
		case ED_INFO_DATA_BEGIN:  
			TRACE((1, "ED_INFO_DATA_BEGIN"));
			break;
		case ED_INFO_ECHO_REQUEST: 
			TRACE((1, "ED_INFO_ECHO_REQUEST"));
			break;
		case ED_OK_PPP:      
			TRACE((1, "ED_OK_"));
			break;
		case ED_OK_GPRS_SESSION_SET: 
			TRACE((1, "ED_OK_GPRS_SESSION_SET"));
			break;
		case ED_OK_ON_HOOK:          
			TRACE((1, "ED_OK_ON_HOOK"));
			break;
		case ED_OK_MAIL_SENT:       
			TRACE((1, "ED_OK_MAIL_SENT"));
			break;
		case ED_OK_POP3:             
			TRACE((1, "ED_OK_POP3"));
			break;
		case ED_OK_FILE_TRANSFERED:
			TRACE((1, "ED_OK_TRANSFERED"));
			break;
		case ED_OK_UDP_CLOSED:       
			TRACE((1, "ED_OK_UDP_CLOSED"));
			break;
		case ED_OK_ECHO_REPLY:  
			TRACE((1, "ED_OK_ECHO_REPLY"));
			break;
		default	:	ServerIndex++;
					ServerIndex = ServerIndex%10;
					SocketFail = TRUE;
					break;
	}
}

Sometimes after the “Ret = ed_SocketSetConfig(ED_ID_TCPSOCKET_1, (ed_SocketSetupParams_t *)&ServerParam);” I don´t get Ret=0 which means it isn´t ok, right? Is there any issue setting the SocketConfig everytime even if it´s the same already stored?

I´m getting the following response from the “Ret” variable: ED_ERR_SERVICE_ALREADY_RUNNING

It means that the TCP/IP is already running, right? But the socket hasn´t been stablished yet…! What should I do?

Sometimes after receiving a -34 event from ResponseCbk, it never get connected again.

Here´s the function I´m trying to use to place a Socket Connection:

void TimeToStartSocket(u8 TimerId)
{
	ascii Buff[50];
	s8 Ret;
	ed_SocketSetupParams_t ServerParam;

	adl_atSendResponse(ADL_AT_UNS, "\r\nTimeToStartSocket();\r\n");
	
//	if (SocketFail == TRUE)
	//{
//		SocketFail = FALSE;
		ServerParam.TcpPort		= ServerPort[ServerIndex];
		ServerParam.TcpTxDelay	= TIME_TO_SEND_DATA;
		wm_sprintf(ServerParam.TcpServ,ServerIP[ServerIndex]);

		Ret = ed_SocketSetConfig(ED_ID_TCPSOCKET_1, (ed_SocketSetupParams_t *)&ServerParam);
		wm_sprintf (Buff, "\r\nIP   : %s\r\n", ServerParam.TcpServ);
		adl_atSendResponse(ADL_AT_UNS, Buff);
		wm_sprintf (Buff, "\r\nPORT :%d\r\n", ServerParam.TcpPort);
		adl_atSendResponse(ADL_AT_UNS, Buff);
		wm_sprintf (Buff, "\r\nDELAY:%d\r\n", ServerParam.TcpTxDelay);
		adl_atSendResponse(ADL_AT_UNS, Buff);
		if (Ret != 0)
		{
			switch (Ret)
			{
			case ED_ERR_NOT_INIT:
				adl_atSendResponse(ADL_AT_RSP, "\r\ned_Init() missing.\r\n");
				break;
			case ED_ERR_INVALID_ARG:
				adl_atSendResponse(ADL_AT_RSP, "\r\nInvalid Input Parameter (NULL pointer).\r\n");
				break;
			case ED_ERR_PARAM_BAD_VALUE:
				adl_atSendResponse(ADL_AT_RSP, "\r\nOne of the parameterss has bad value.\r\n");
				break;
			case ED_ERR_PARAM_TOO_LONG:
				adl_atSendResponse(ADL_AT_RSP, "\r\nOne of the parameters string is too long.\r\n");
				break;
			case ED_ERR_PARAM_WRITE_E2P:
				adl_atSendResponse(ADL_AT_RSP, "\r\nEEPROM write failed.\r\n");
				break;
			case ED_ERR_SERVICE_ALREADY_RUNNING:
				adl_atSendResponse(ADL_AT_RSP, "\r\nThe input parameter cannot be set because this TCP socket is up & running.\r\n");
				break;
			case ED_ERR_INVALID_ID:
				adl_atSendResponse(ADL_AT_RSP, "\r\nThe id parameter is invalid.\r\n");
				break;
			}

		}
		if(SocketOk==TRUE)
		{
			adl_tmrUnSubscribe (TimeToStartSocketHandle,(adl_tmrHandler_t)TimeToStartSocket,ADL_TMR_TYPE_100MS);
			adl_atSendResopnse(ADL_AT_UNS, "\r\nTimeToStartSocket: OFF\r\n");
		}
		else
		{
			Ret = ed_SocketTCPStart(ED_ID_TCPSOCKET_1, CLIENT, (ed_ResponseCbk_f) SocketResponseCbk,
                   (ed_DataHandler_f) SocketDataHnd, (ed_DataRequest_f) SocketDataRequest);
			adl_atSendResponse(ADL_AT_UNS, "\r\nTried another SocketTCPStart\r\n");
		}

		adl_atSendResponse(ADL_AT_UNS,"\n\rSOCKET START\n\r");
	//}
}

Any tips/hints?

Best Regards,

Henrique


#2

Hello
We are in the same problem, so he idea is to stop a connection, and detach from GPRS (in case of GPRS Lost), and After this reattach on GPRS and Start connection.

Have u find the solution?