Hi BenFT01 ,
I could not successfully complete the GPRS part , Here I have included my gprs code part
After debugging , I have noticed the following two problem .
-
IP communication terminated(WIP_BEV_IP_DISCONNECTED) , while uploading the data suddenly IP will get terminated .
-
Gprs connection failure (WIP_BEV_CONN_FAILED), When I call the gprs start bearer after few second I receive this status message .
Note : This happens irregularly(i.e data will upload some 20/30 times and in the next time this happens) .
I have come to know that these two problems are quite common in real time , and we need to try to re establish the connection after 5 to 10 sec when we have these problems .
So I went with trying this(I have including this code also i.e Re_establish()) , But when I try to re connect, status shows that WIP_BERR_ALREADY open,
Though i’m closing the connection before re connecting , it shows bearer is already opened . and it will be continuously trying this .
Pls help me to debug the “connection re establishing” part
#include "adl_global.h"
#include "wip.h"
#include "wip_bearer.h"
/***************************************************************************/
/* Defines */
/***************************************************************************/
//#define GPRS_APN "AirTelGprs.com"
#define GPRS_APN "airtelgprs.com"
#define GPRS_USER "tcs"
#define GPRS_PASSWORD "tcs"
#define GPRS_PINCODE "0000"
#define CREG_POLLING_PERIOD 20 /* in 100ms steps */
#define ASSERT( pred) \
if( !(pred)) wip_debug( "ASSERTION FAILURE line %i: " #pred "\n", __LINE__)
#define ASSERT_OK( v) ASSERT( 0 == (v))
/***************************************************************************/
/* Functions */
/***************************************************************************/
/* Function to be called once the bearer is up and running. */
static void (* appli_entry_point)( void);
char* set_gprs(void);
adl_atPort_e uart2_port;
wip_bearer_t b; // Gprs
/***************************************************************************/
/* Initialization-related event handlers */
/***************************************************************************/
/***************************************************************************/
/* GPRS Re setablish */
/***************************************************************************/
void Re_establish(void)
{
start_stop_gprs(1); // try to connect again
}
/***************************************************************************/
/* Function : evh_bearer */
/*-------------------------------------------------------------------------*/
/* Object : bearer events handler: when the bearer connection is */
/* completed, start IP services */
/*-------------------------------------------------------------------------*/
/* Variable Name |IN |OUT|GLB| Utilisation */
/*--------------------+---+---+---+----------------------------------------*/
/* b | X | | | bearer identifier */
/* event | X | | | bearer event type */
/* ctx | | | | unused */
/*--------------------+---+---+---+----------------------------------------*/
/***************************************************************************/
static void evh_bearer( wip_bearer_t b, s8 event, void *ctx) {
switch(event)
{
case WIP_BEV_CONN_FAILED:
send_sms("\r\nGPRS connection failure\r\n");
adl_atSendResponsePort(ADL_AT_RSP, uart2_port,("\r\n::GPRS connection failure\r\n" ));
start_stop_gprs(0);/// stop the GPRS
//Setting timer to reestblish the GPRS connection
adl_tmrSubscribe( FALSE, 2000, ADL_TMR_TYPE_100MS,Re_establish); break;
case WIP_BEV_IP_DISCONNECTED:
TRACE((1,"IP communication terminated"));
adl_atSendResponsePort(ADL_AT_RSP, uart2_port,("\r\n::IP communication terminated\r\n" ));
start_stop_gprs(0);/// stop the GPRS
//Setting timer to reestblish the GPRS connection
adl_tmrSubscribe( FALSE, 2000, ADL_TMR_TYPE_100MS,Re_establish);
break;
case WIP_BEV_IP_CONNECTED:
adl_atSendResponsePort(ADL_AT_RSP, uart2_port,("\r\n::GPRS STARTED ON IP.\r\n" ));
appli_entry_point() ; //Calling the TCP part to send the data
break;
case WIP_BEV_STOPPED:
adl_atSendResponsePort(ADL_AT_RSP, uart2_port,("\r\n::WIP_BEV_STOPPED.\r\n" ));
s8 close= wip_bearerClose (b);
switch(close)
{
case WIP_BERR_BAD_STATE:
adl_atSendResponsePort(ADL_AT_RSP, uart2_port,("\r\n:: Bearer was not clsoing before stopped:\r\n" ));
break;
case WIP_BERR_BAD_HDL:
adl_atSendResponsePort(ADL_AT_RSP, uart2_port,("\r\n:: Bad handle:\r\n" ));
break;
}
break;
}
}
/****************************************************************************/
/* Function : open_and_start_bearer() */
/*--------------------------------------------------------------------------*/
/* Object : Open and start the GPRS bearer. Normally, the bearer will */
/* answer IN_PROGRESS, and the initialization will be finished */
/* by the callback evh_bearer(). */
/*--------------------------------------------------------------------------*/
/* Variable Name |IN |OUT|GLB| Utilisation */
/*--------------------+---+---+---+-----------------------------------------*/
/*--------------------+---+---+---+-----------------------------------------*/
/****************************************************************************/
static void open_and_start_bearer( void) {
adl_atSendResponse ( ADL_AT_UNS, "\r\n open and start bearer\r\n" );
adl_atSendResponsePort(ADL_AT_RSP, uart2_port,("\r\n::open and start bearer::\r\n" ));
int r;
r = wip_bearerOpen( &b, "GPRS", evh_bearer, NULL);
switch(r)
{
case WIP_BERR_NO_DEV:
adl_atSendResponse ( ADL_AT_UNS, "\r\n The device does not exist\r\n" );
break;
case WIP_BERR_ALREADY:
adl_atSendResponse ( ADL_AT_UNS, "\r\n The device is already opened\r\n" ); break;
case WIP_BERR_NO_IF:
adl_atSendResponse ( ADL_AT_UNS, "\r\n The network interface is not available\r\n" );
break;
case WIP_BERR_NO_HDL:
adl_atSendResponse ( ADL_AT_UNS, "\r\n No free handle\r\n" );
break;
}
ASSERT_OK( r);
r = wip_bearerSetOpts( b, WIP_BOPT_GPRS_APN, GPRS_APN,
WIP_BOPT_LOGIN, GPRS_USER,
WIP_BOPT_PASSWORD, GPRS_PASSWORD,
WIP_BOPT_END);
switch(r)
{
case WIP_BERR_BAD_HDL:
adl_atSendResponse ( ADL_AT_UNS, "\r\n bad handle\r\n" );
break;
case WIP_BERR_OPTION:
adl_atSendResponse ( ADL_AT_UNS, "\r\n The device is already opened\r\n" );
break;
case WIP_BERR_PARAM:
adl_atSendResponse ( ADL_AT_UNS, "\r\n Invalid option value\r\n" );
break;
}
ASSERT_OK( r);
r = wip_bearerStart( b);
switch(r)
{
case WIP_BERR_OK_INPROGRESS:
adl_atSendResponse ( ADL_AT_UNS, "\r\n WIP_BERR_OK_INPROGRESS\r\n" );
break;
case WIP_BERR_BAD_HDL:
adl_atSendResponse ( ADL_AT_UNS, "\r\n WIP_BERR_BAD_HDL\r\n" );
break;
case WIP_BERR_BAD_STATE:
adl_atSendResponse ( ADL_AT_UNS, "\r\n WIP_BERR_BAD_STATE\r\n" );
break;
case WIP_BERR_DEV:
adl_atSendResponse ( ADL_AT_UNS, "\r\n WIP_BERR_DEV\r\n" );
break;
}
ASSERT( 0 == r || WIP_BERR_OK_INPROGRESS == r);
}
static void poll_creg( u8 Id );
/****************************************************************************/
/* Function : poll_creg_callback() */
/*--------------------------------------------------------------------------*/
/* Object : A call to "AT+CREG?" has been done, to check the registration */
/* status, and the answer comes back to this handler. */
/* Either the registration is completed, and we can actually */
/* open and start the bearer, or it isn't, and we shall poll */
/* at "AT+CREG?" command again through a timer. */
/*--------------------------------------------------------------------------*/
/* Variable Name |IN |OUT|GLB| Utilisation */
/*--------------------+---+---+---+-----------------------------------------*/
/* Rsp | x | | | AT command response */
/*--------------------+---+---+---+-----------------------------------------*/
/****************************************************************************/
static bool poll_creg_callback(adl_atResponse_t *Rsp) {
ascii *rsp;
ascii regStateString[3];
s32 regStateInt;
TRACE (( 1, "(poll_creg_callback) Enter." ));
adl_atSendResponsePort(ADL_AT_RSP, uart2_port,("\r\n::(poll_creg_callback) Enter.\r\n" ));
rsp = (ascii *)adl_memGet(Rsp->StrLength);
wm_strRemoveCRLF(rsp, Rsp->StrData, Rsp->StrLength);
wm_strGetParameterString(regStateString, Rsp->StrData, 2);
regStateInt = wm_atoi(regStateString);
if ( 1 == regStateInt || 5 ==regStateInt) {
TRACE (( 1, "(poll_creg_callback) Registered on GPRS network." ));
adl_atSendResponsePort(ADL_AT_RSP, uart2_port,("\r\n::(poll_creg_callback) Registered on GPRS network.\r\n\r\n" ));
} else {
/* Not ready yet, we'll check again later. Set a one-off timer. */
adl_atSendResponsePort(ADL_AT_RSP, uart2_port,("\r\n:: in polling call back it will retsart the device\r\n\r\n" ));
adl_tmrSubscribe( FALSE, CREG_POLLING_PERIOD, ADL_TMR_TYPE_100MS,
poll_creg);
}
return FALSE;
}
/****************************************************************************/
/* Function : poll_creg */
/*--------------------------------------------------------------------------*/
/* Object : Monitor the network registration; the only way to do that is */
/* through an AT command, so we send that "AT+CREG?" command. */
/* Actual reaction will be performed by the callback */
/* poll_creg_callback(). */
/*--------------------------------------------------------------------------*/
/* Variable Name |IN |OUT|GLB| Utilisation */
/*--------------------+---+---+---+-----------------------------------------*/
/* Id | | | | Dummy parameter that makes the function */
/* | | | | callable by a timer's adl_tmrSubscribe()*/
/*--------------------+---+---+---+-----------------------------------------*/
/****************************************************************************/
static void poll_creg( u8 Id ) {
adl_atCmdCreate( "AT+CREG?", FALSE, poll_creg_callback, ADL_STR_CREG, NULL);
}
/***************************************************************************/
/* Function : evh_sim */
/*-------------------------------------------------------------------------*/
/* Object : sim events: */
/* when SIM initialisation is completed, check the registra- */
/* tion status; poll_creg()'s callback will actually */
/* open the bearer once registration is completed. */
/*-------------------------------------------------------------------------*/
/* Variable Name |IN |OUT|GLB| Utilisation */
/*--------------------+---+---+---+----------------------------------------*/
/* event | X | | |SIM event */
/*--------------------+---+---+---+----------------------------------------*/
/***************************************************************************/
static void evh_sim( u8 event) {
TRACE (( 1, "(evh_sim) Enter." ));
//adl_atSendResponse ( ADL_AT_UNS, "\r\n(evh_sim) Enter..\r\n" );
adl_atSendResponsePort(ADL_AT_RSP, uart2_port,( "\r\n(evh_sim) Enter..\r\n" ));
if( ADL_SIM_EVENT_FULL_INIT == event) {
poll_creg( 0); /* argument 0 is dummy, see poll_reg() "Object" comment */
}
}
/***************************************************************************/
/* Function : cfg_gprs */
/*-------------------------------------------------------------------------*/
/* Object : initialize GPRS connection, then launch entry_point() on */
/* success. */
/* */
/*-------------------------------------------------------------------------*/
/* Variable Name |IN |OUT|GLB| Utilisation */
/*--------------------+---+---+---+----------------------------------------*/
/* entry_point | X | | |Function run after successful connection*/
/*--------------------+---+---+---+----------------------------------------*/
/***************************************************************************/
void cfg_gprs ( void (* entry_point)(void)) {
TRACE (( 2, "(cfg_gprs) Enter." ));
adl_atSendResponsePort(ADL_AT_RSP, uart2_port,("\r\n::(cfg_gprs) Enter.::\r\n" ));
adl_simSubscribe( evh_sim, GPRS_PINCODE);
appli_entry_point = entry_point;
}
/* *********************************************
***********************************************
GPRS Stop
************************************************
************************************************/
/****************************************************
This function will be called once the data is aquired from external device
or when the data upload is completed / when the error in gprs connection if set=1 : then it is for starting the bearer else stop
*/
void start_stop_gprs(int set)
{
if (set==1)
{
adl_atSendResponsePort(ADL_AT_RSP, uart2_port,("\r\n:: Calling to open the Gprs bearer . ::\r\n" ));
open_and_start_bearer(); // this function is called once we receive data from external device
else
{
adl_atSendResponsePort(ADL_AT_RSP, uart2_port,("\r\n::Calling to close the Gprs bearer.::\r\n" ));
s8 stop = wip_bearerStop (b);
switch(stop)
{
case WIP_BERR_OK_INPROGRESS:
adl_atSendResponsePort(ADL_AT_RSP, uart2_port,("\r\n:: Disconnection in progress:\r\n" ));
break;
case WIP_BERR_BAD_HDL:
adl_atSendResponsePort(ADL_AT_RSP, uart2_port,("\r\n:: Bad handle:\r\n" ));
break;
}
}
}
thanks & regards
chethan