Openning a socket


#1

Hello guys,

I am using Open AT 4.00.a02 and trying to open a UDP socket in GPRS network.
I am new to Open AT environment and I’m bit confused about few things.

First of all, I have been looking at other sections of the forum and found that there is an example called ‘Socket’ which might be helpful for my task but I don’t think I have that. (it is not even included in the documents). Is this example no longer exist?

If it’s so, can anyone give me any suggestion how to create an UDP socket?

Also, I guess there is no PPP stack in the adl environment. Am I right?

When I tried to connect network using AT commands, I get following result:


atz
OK
AT+CGDCONT=1,“IP”, “Internet”
OK
~ }#À!}!}!} }6}!}$}%Ãœ}"}&} } } } }’}"}(}"}#}$À#&´~
CONNECT 115200
~ }#À!}!}!} }6}!}$}%Ãœ}"}&} } } } }’}"}(}"}#}$À#&´~~ }#À!}!}!} }6}!}$}%Ãœ}"}&} } }
} }’}"}(}"}#}$À#&´~~ }#À!}!}!} }6}!}$}%Ãœ}"}&} } } } }’}"}(}"}#}$À#&´~~ }#À!}!}!
} }6}!}$}%Ãœ}"}&} } } } }’}"}(}"}#}$À#&´~~ }#À!}!}!} }6}!}$}%Ãœ}"}&} } } } }’}"}(}
“}#}$À#&´~~ }#À!}!}!} }6}!}$}%Ãœ}”}&} } } } }’}"}(}"}#}$À#&´~~ }#À!}!}!} }6}!}$}%
Ãœ}"}&} } } } }’}"}(}"}#}$À#&´~~ }#À!}!}!} }6}!}$}%Ãœ}"}&} } } } }’}"}(}"}#}$À#&´~
~ }#À!}!}!} }6}!}$}%Ãœ}"}&} } } } }’}"}(}"}#}$À#&´~
NO CARRIER



#2

You need a TCPIP stack (aka eDLib for openat)
You are using an old Beta version and there was no tcpip stack support for that openat version.
If you use OpenAT3.03 you will see the stack and the socket example are available.


#3

Hi Waltersenekal,

Thanks for your reply.

I am using Open AT 4.00.a02. Is this a beta version?

I can find the ‘gcc_eDLib_310b01.lib’ under ($OPEN_AT)\TgtGen\Add-ons\TCPIP whereas other adl libraries are located under ($OPEN_AT)
TgtGen\Library.

So only the ‘socket’ example is missing.

Now, I have a problem when I’m trying to link the eDLib libraries to my project. It gives me error during compilation.
Maybe the eDLib can’t be linked in the beta version?


#4

In the project folder there are a file with the extension *.scs open this file and add this line to the WMNew script additional options:
-otherlib /TCPIP
this will link the compiler to the ed_Lib Libraries

Find below an example on how to connect to GPRS ussing ed_Lib

#include "adl_global.h"
#include "ed_common.h"
#include "ed_dialup.h"
#include "ed_ftp.h"
#include "ed_gprs.h"
#include "ed_socket.h"
#include "ed_msgcodes.h"

/***************************************************************************/
/*  Mandatory variables                                                    */
/*-------------------------------------------------------------------------*/
/*  wm_apmCustomStack                                                      */
/*  wm_apmCustomStackSize                                                  */
/*-------------------------------------------------------------------------*/
/***************************************************************************/
u32 wm_apmCustomStack [ 4000 ];
const u16 wm_apmCustomStackSize = sizeof ( wm_apmCustomStack );

/***************************************************************************/
/*  Local variables                                                        */
/***************************************************************************/
ed_FTPSetupParams_t FTPParams;
ed_gprsSetupParams_t APNParams;
ed_FTPGetFileParams_t FTPGetFileParameters;
s32 Cell_Handle;
s32 S32Return;


/***************************************************************************/
/*  Local functions                                                        */
/***************************************************************************/

void adl_main ( adl_InitType_e InitType );
void My_App_Normal_Init (void);
void SimEventHandler(u8 Event);
void SetupHandler(u8 ID);
bool AttRspHandler(adl_atResponse_t *params);
void GPRSWait( u8 ID);
void GPRSTimer(u8 ID);
void dialupHandler( s32 responseCode , TeDHandle id);
void dotted_notation(unsigned long int hex_ip);

/***************************************************************************/
/*  Function   : adl_main                                                  */
/*-------------------------------------------------------------------------*/
/*  Object     : Customer application initialization                       */
/*                                                                         */
/*-------------------------------------------------------------------------*/
/*  Variable Name     |IN |OUT|GLB|  Utilization                           */
/*--------------------+---+---+---+----------------------------------------*/
/*  InitType          |   |   |   |  Application start mode reason         */
/*--------------------+---+---+---+----------------------------------------*/
/***************************************************************************/
void adl_main ( adl_InitType_e InitType )
{
	s8 result;
	TRACE (( 2, "Application Start with Init Type:%s",InitType ));
	
	result = ed_Init();

	TRACE (( 2, "Ed Library Initialized - %d" , result));
    switch(InitType)
	{
		case ADL_INIT_POWER_ON:              // Normal power on
			TRACE (( 2, "ADL_INIT_POWER_ON (Normal Start)" ));
			adl_atSendResponse( ADL_AT_UNS, "\r\nSMSParam Application Starting Normally\r\n" );
			My_App_Normal_Init();
			break;
		case ADL_INIT_REBOOT_FROM_EXCEPTION: // Reboot after an embedded application exception
			TRACE (( 2, "ADL_INIT_REBOOT_FROM_EXCEPTION" ));
			break;
		case ADL_INIT_DOWNLOAD_SUCCESS:      // Reboot after a successfully downloaded process
			TRACE (( 2, "ADL_INIT_DOWNLOAD_SUCCESS" ));
			break;
		case ADL_INIT_DOWNLOAD_ERROR:       // Reboot after a unsuccessful downloaded process
			TRACE (( 2, "ADL_INIT_DOWNLOAD_ERROR" ));
			break;
	}
}

void My_App_Normal_Init()
{
	TRACE (( 2, "My_App_Normal_Init"));
	adl_atCmdCreate("AT+CGCLASS=\"B\"",FALSE,NULL,NULL);
	adl_simSubscribe(SimEventHandler,NULL);

	//adl_tmrSubscribe(FALSE, 10, ADL_TMR_TYPE_100MS, SetupHandler); /*Only for Dev comment out for real app*/
}

void SimEventHandler(u8 Event)
{
	TRACE (( 2, "SimEventHandler"));
	switch(Event)
	{
	case ADL_SIM_EVENT_REMOVED:
		break;
	case ADL_SIM_EVENT_INSERTED:
		break;
	case ADL_SIM_EVENT_FULL_INIT:
		TRACE ((2,"ADL_SIM_EVENT_FULL_INIT"));
		adl_tmrSubscribe(FALSE, 10, ADL_TMR_TYPE_100MS, SetupHandler); //To Start The App Only After 1 Second To Allow Init
		break;
	case ADL_SIM_EVENT_PIN_ERROR:
		break;
	case ADL_SIM_EVENT_PIN_OK:
		break;
	case ADL_SIM_EVENT_PIN_WAIT:
		break;
	case ADL_SIM_EVENT_PIN_NO_ATTEMPT:
		break;
	}
}

void SetupHandler(u8 ID)
{
	TRACE( ( 2, "Inside SetupHandler" ) );
	adl_atCmdCreate("AT+CGATT=1",FALSE,AttRspHandler,"*",NULL);
}

bool AttRspHandler(adl_atResponse_t *params)
{
	TRACE( ( 2, "Inside AttRspHandler" ) );
	//if an OK is received as response to AT+CGATT=1 command then set GPRS settings.
	if( !wm_strncmp( params->StrData, "\r\nOK", 4 ) )
	{
		//Ready
		TRACE( ( 2, "Received OK" ) );
			adl_tmrSubscribe(FALSE,2,ADL_TMR_TYPE_100MS,GPRSWait);//Give modem time to process CGATT=1	

	}
	//if an OK is not received then create AT+CGATT=1 again.
	else
	{
		adl_atCmdCreate( "AT+CGATT=1", FALSE, AttRspHandler, "*", NULL );
	}
	return FALSE;
}

void GPRSWait( u8 ID)
{
	s8 returnCode;
	TRACE( ( 2, "Inside GPRSWait" ) );
	APNParams.Cid=1;
	APNParams.Mode=1;
	wm_strcpy( APNParams.ApnUn,"");
	wm_strcpy( APNParams.ApnPw,"");
	wm_strcpy( APNParams.ApnServ,"internet");
	returnCode = ed_GprsSetConfig( &APNParams );
	if (returnCode == 0)
	{
		adl_tmrSubscribe(FALSE, 10, ADL_TMR_TYPE_100MS,GPRSTimer);

	}
	else
	{
		TRACE((2,"ed_GprsSetConfig failed returnCode = %d",returnCode));
	}

}

void GPRSTimer(u8 ID)
{
	s8 returnCode;
	TRACE( ( 2, "Inside timerHandler" ) );
	returnCode = ed_DialupConnectionStart(dialupHandler );

	if(returnCode == 0)
	{
		TRACE((2,"ed_DialupConnectionStart success returnCode = %d",returnCode));

		adl_atSendResponse(ADL_AT_RSP,"\r\nTrying to retrieve ip information.Please wait until local ip is received...\r\n");

	}
	else
	{
		adl_atSendResponse( ADL_AT_RSP, "\r\ned_DialupConnectionStart failed\r\n" );
		TRACE((2,"ed_DialupConnectionStart failed returnCode = %d",returnCode));
	}
}
void dialupHandler( s32 responseCode , TeDHandle id)
{
//	s8 RetS8;
//	ascii Temp[255];
	ed_dialupIPInfos_t ip_info;
	TRACE( ( 2, "Inside dialupHandler" ) );

	switch ( responseCode )
	{
	case ED_OK_GPRS_SESSION_SET://GPRS session is set.

		TRACE( ( 2, "Inside ED_OK_GPRS_SESSION_SET" ) );
		ed_DialupGetIpInformations(&ip_info); //retrieve ip informations (retrieved as u32).
		adl_atSendResponse(ADL_AT_RSP,"\r\nLocal ip is \r\n");
		dotted_notation(ip_info.LocalIP);//Print the ip information in dotted format
		adl_atSendResponse(ADL_AT_RSP,"\r\n");
		break;

	case ED_INFO_CONNECT:

		TRACE( ( 2, "Inside ED_INFO_CONNECT" ) );

		break;

	case ED_OK_PPP:

		TRACE( ( 2, "Inside ED_OK_PPP" ) );
		ed_DialupGetIpInformations(&ip_info);
		adl_atSendResponse(ADL_AT_RSP,"\r\nLocal ip is\r\n");
		dotted_notation(ip_info.LocalIP);

		break;

	case ED_OK_ON_HOOK:

		TRACE( ( 2, "Dial up connection closed" ) );
		adl_atSendResponse( ADL_AT_RSP, "\r\nDial up connection closed" );
		break;

	case ED_ERR_GPRS_ABORTED:
		TRACE((2,"ED_ERR_GPRS_ABORTED"));
		adl_atSendResponse(ADL_AT_RSP,"\r\nInternal GPRS error.Please check your APN parameters");
		break;

	default:
		TRACE((2,"default or error received in gprsHandler: responseCode - %d", responseCode));
		adl_atSendResponse( ADL_AT_RSP, "\r\nerror received in dial up connection start" );
		break;
	}
}

void dotted_notation(unsigned long int hex_ip)
{
	ascii array[30];
	TRACE( ( 2, "Inside dotted_Notation %d",hex_ip ) );
	if (hex_ip > 16777215)//to detect the least significant byte (not to put dot behind)
	{
		dotted_notation(hex_ip>>8 );
		sprintf(array,"%d",hex_ip & 0xFF);
		adl_atSendResponse(ADL_AT_RSP,array);
	} 
	else
	{
	
		if (hex_ip==0x00000000)
			return;
		else
		{
			dotted_notation(hex_ip>>8 );
			sprintf(array,"%d.",hex_ip & 0xFF);
			adl_atSendResponse(ADL_AT_RSP,array);
		}
	}
}

#5

Thanks you very much waltersenekal.

I really apprecitate your help.