Hi Guys,
I’m having some trouble connecting to a GPRS bearer using the WIP v5.1 plug-in.
Device: Q2687
Firmware: R74_00gg
M2M Studio 1.0
Build Version 1.0.2.200903311200
I’ve disabled the PIN code request on the SIM card used and have also tested that GPRS is enable by the service provider (was able to browse the net if I use the SIM in a USB 3G modem).
When I try to Open the bearer error code -28 is returned. “WIP_BERR_BAD_STATE - The bearer is not stopped” according to documentation (Open AT® IP Connectivity Development Guide (WIPlib v5.10)).
I then try to stop the bearer using the wip_bearerStop function. Error code -24 “WIP_BERR_BAD_HDL - Invalid handle” is returned. This I expect because the handle “myBearer” hasn’t been used before (first run of the program after download / restart).
I based my program on the “Examples of Application - 15.1 Initializing a GPRS Bearer” in the above mentioned documentation.
/* -------- */
/* Includes */
/* -------- */
#include "adl_global.h"
#include "keyboard.h"
#include "adl_ctx.h"
#include "keypad_control"
#include "wip_bearer.h"
/* --------- */
/* Constants */
/* --------- */
/* --------- */
/* Variables */
/* --------- */
u8 key_TraceLevel = 17; // Keyboard Library
/***************************************************************************/
/* Mandatory variables */
/*-------------------------------------------------------------------------*/
/* wm_apmCustomStackSize */
/*-------------------------------------------------------------------------*/
/***************************************************************************/
const u16 wm_apmCustomStackSize = 1024*3;
/***************************************************************************/
/* bearer events handler */
void myHandler( wip_bearer_t br, s8 event, void *context)
{
TRACE (( 3, "In myHandler " ));
switch( event)
{
case WIP_BEV_IP_CONNECTED:
/*IP connectivity we can start IP application from here*/
TRACE (( 3, "WIP_BEV_IP_CONNECTED - IP connectivity we can start IP application from here" ));
break;
case WIP_BEV_IP_DISCONNECTED:
/*stop IP application*/
TRACE (( 3, "WIP_BEV_IP_DISCONNECTED - Stop IP Application" ));
break;
/* other events: */
default:
/*cannot start bearer: report error to higher levels*/
TRACE (( 3, "DEFAULT - cannot start bearer: report error to higher levels" ));
break;
}
}
/* bearer handle */
wip_bearer_t myBearer;
/* Initialise and start GPRS bearer */
bool myConnectToGPRS( void)
{
s8 bearerOpenReturn;
s8 bearerStopReturn;
s8 bearerCloseReturn;
bearerOpenReturn = wip_bearerOpen( &myBearer, "GPRS", myHandler, NULL);
TRACE (( 3, "bearerOpenReturn %d", bearerOpenReturn ));
/* if bearer is in bad state, close and retry */
if( bearerOpenReturn == -28)
{
bearerStopReturn = wip_bearerStop( myBearer);
/* cannot open bearer */
TRACE (( 3, "Bearer is not stopped. Stop Bearer 'myBearer'" ));
switch (bearerStopReturn)
{
case 0:
TRACE (( 3, "Bearer 'myBearer' stopped successfully" ));
break;
default:
TRACE (( 3, "bearerStopReturn %d", bearerStopReturn ));
break;
}
TRACE (( 3, "Bearer is not stopped. Close Bearer 'myBearer'" ));
bearerCloseReturn = wip_bearerClose( myBearer);
switch (bearerCloseReturn)
{
case 0:
TRACE (( 3, "Bearer 'myBearer' closed successfully" ));
break;
default:
TRACE (( 3, "bearerCloseReturn %d", bearerOpenReturn ));
break;
}
TRACE (( 3, "Wait 2seconds..." ));
adl_ctxSleep(5 * 1000 / 18.5 );
TRACE (( 3, "Retry Opening Bearer" ));
bearerOpenReturn = wip_bearerOpen( &myBearer, "GPRS", myHandler, NULL);
}
TRACE (( 3, "bearerOpenReturn %d", bearerOpenReturn ));
/* open bearer and install our event handler */
if( bearerOpenReturn != 0)
{
/* cannot open bearer */
TRACE (( 3, "Cannot Open Bearer" ));
return FALSE;
}
/* configure GPRS interface */
TRACE (( 3, "Configure GPRS Interface" ));
if( wip_bearerSetOpts ( myBearer,
WIP_BOPT_GPRS_APN, "internet",
WIP_BOPT_LOGIN, "",
WIP_BOPT_PASSWORD, "",
WIP_BOPT_END) != 0)
{
/* cannot configure bearer */
TRACE (( 3, "Cannot Configure Bearer" ));
wip_bearerClose( myBearer);
return FALSE;
}
/* start connection */
TRACE (( 3, "Start Connection" ));
if( wip_bearerStart( myBearer) != 0)
{
/* cannot start bearer */
TRACE (( 3, "Cannot Start Bearer" ));
wip_bearerClose( myBearer);
return FALSE;
}
/* connection status will be reported to the event handler */
return TRUE;
}
/***************************************************************************/
/* Function : adl_main */
/*-------------------------------------------------------------------------*/
/* Object : Customer ADL application initialisation */
/* */
/*-------------------------------------------------------------------------*/
/* Variable Name |IN |OUT|GLB| Utilisation */
/*--------------------+---+---+---+----------------------------------------*/
/* adlInitType | | | | Application starting mode */
/*--------------------+---+---+---+----------------------------------------*/
/***************************************************************************/
void adl_main ( adl_InitType_e InitType )
{
TRACE (( 1, "Waiting 10 sec. before start the application...." ));
adl_ctxSleep(10 * 1000 / 18.5 );
/* DTMF Keyboard test application */
TRACE (( 1, "DTMF Keyboard sample main" ));
TRACE (( 1, __DATE__ ));
TRACE (( 1, __TIME__ ));
/* Subscribe to Keyboard service */
TRACE (( 1, "Subscribe to Keyboard Service" ));
key_Subscribe ( dk_KeyboardHandler, 0, 0 );
/* Call function to subscribe to GPRS Bearer */
TRACE (( 1, "Call GPRS Subscribe Function" ));
myConnectToGPRS();
}
TRACE logs
09/08/02,03:41:05:421 ADL 1 Binary header at 00260000
09/08/02,03:41:05:500 ADL 1 Waiting 10 sec. before start the application....
09/08/02,03:41:14:890 ADL 1 DTMF Keyboard sample main
09/08/02,03:41:14:890 ADL 1 Aug 2 2009
09/08/02,03:41:14:890 ADL 1 15:36:21
09/08/02,03:41:14:890 ADL 1 Subscribe to Keyboard Service
09/08/02,03:41:14:906 ADL 1 Call GPRS Subscribe Function
09/08/02,03:41:14:906 ADL 3 bearerOpenReturn -28
09/08/02,03:41:14:906 ADL 3 Bearer is not stopped. Stop Bearer 'myBearer'
09/08/02,03:41:14:921 ADL 3 bearerStopReturn -24
09/08/02,03:41:14:921 ADL 3 Bearer is not stopped. Close Bearer 'myBearer'
09/08/02,03:41:14:921 ADL 3 bearerCloseReturn -28
09/08/02,03:41:14:937 ADL 3 Wait 2seconds...
09/08/02,03:41:19:843 ADL 3 Retry Opening Bearer
09/08/02,03:41:19:843 ADL 3 bearerOpenReturn -28
09/08/02,03:41:19:843 ADL 3 Cannot Open Bearer
Any suggestions would be appreciated!
Thanks in advance guys!
Stef