Bearerstart problem


#1

I’m trying to set up a GPRS connection so I can make HTTP requests. I’m using WIP 5.42, FW 7.46 and Dev Studio 2.1.1
The bearer isn’t started until now

Here is a snippet of my code:

void BearHandler(wip_bearer_t Br_Id, s8 Event, void  *context) {
	s8 close;
	switch(Event){
		case WIP_BEV_CONN_FAILED:
			TRACE((1,"Bear conn failed"));
            break;
		case WIP_BEV_IP_DISCONNECTED:
			TRACE((1,"IP communication terminated"));
			break;
		case WIP_BEV_IP_CONNECTED:
			TRACE((1,"Bear ip connected"));
			break;
		case WIP_BEV_STOPPED:
			TRACE((1,"Bear close, stopped"));
			close = wip_bearerClose (Br_Id);
			switch(close){
            	case WIP_BERR_BAD_STATE:
            		TRACE((1,"Bad state"));
            		break;
            	case WIP_BERR_BAD_HDL:
            		TRACE((1,"bad handle"));
            		break;
            }
			break;
        case WIP_BERR_GPRS_FAILED:
        	TRACE((1,"GPRS failed"));
        	break;
        case WIP_BERR_PIN_NOT_READY:
        	TRACE((1,"Pin error"));
        	break;
        default:
        	TRACE((1,"Default: error: %d", Event));
        	break;
	}
}

static void open_and_start_bearer(void) {
  wip_bearer_t Br_ID;
  TRACE((1, "wip_bearerOpen()"));

  if(wip_bearerOpen( &Br_ID, "GPRS", BearHandler, NULL) != 0) TRACE((1, "wip_bearerOpen() : Fail"));
  else{
	  	  TRACE((1, "wip_bearerSetOpts()"));
	  	  if(wip_bearerSetOpts( Br_ID, WIP_BOPT_GPRS_APN, GPRS_APN,
	  			  WIP_BOPT_LOGIN,       GPRS_USER,
	  			  WIP_BOPT_PASSWORD,    GPRS_PASSWORD,
	  			  WIP_BOPT_END) != 0) {
		  	  TRACE((1, "wip_bearerSetOpts : Fail"));
		  	  wip_bearerClose(Br_ID);
	  	  }
	  	  else{
		  	  if(wip_bearerStart(Br_ID) != 0){
		  		  TRACE((1, "wip_bearerStart : Fail"));
		  		  TRACE((1, "ERROR CODE: %d", wip_bearerStart(Br_ID)));
		  	  }
	  	  }
  	  }
}

static void wip_init( void) {
	u8 wRet;
	wip_logEvents = TRUE;

	wRet = wip_netInitOpts(WIP_NET_OPT_IP_FORWARD,FALSE,WIP_NET_OPT_DEBUG_PORT, WIP_NET_DEBUG_PORT_TRACE,WIP_NET_OPT_END);

	if(wRet != 0){
		TRACE (( 1, "wip_netInit error" ));
	}
	else{
		TRACE (( 1, "wip_netInit :)" ));
		adl_atSendResponse ( ADL_AT_UNS, "wip_eventInit :)\r\n");
		open_and_start_bearer();
	}
}

This is the feedback from the traces

2012/02/29;14:26:30:842;001;ADL;1;GPRS_Handler
2012/02/29;14:26:30:846;001;ADL;1;GPRS ME Attached
2012/02/29;14:26:32:007;001;ATI;1;<CR><LF>OK<CR><LF>
2012/02/29;14:26:32:009;001;ATI;1;0d 0a 4f 4b 0d 0a 
2012/02/29;14:26:32:012;001;ATI;1;AT+CGPADDR=1<CR>
2012/02/29;14:26:32:015;001;ATI;1;41 54 2b 43 47 50 41 44 44 52 3d 31 1a 
2012/02/29;14:26:32:018;001;ATI;1;<CR><LF>+CGPADDR: 1,"62.133.83.36"<CR><LF>
2012/02/29;14:26:32:021;001;ATI;1;0d 0a 2b 43 47 50 41 44 44 52 3a 20 31 2c 22 36 32 2e 31 33 33 2e 38 33 2e 33 36 22 0d 0a 
2012/02/29;14:26:32:028;001;ATI;1;<CR><LF>OK<CR><LF>
2012/02/29;14:26:32:030;001;ATI;1;0d 0a 4f 4b 0d 0a 
2012/02/29;14:26:32:035;001;ADL;1;GPRS_Handler
2012/02/29;14:26:32:038;001;ADL;1;GPRS Event activated
2012/02/29;14:26:32:044;001;ADL;20;[ADL] tmr subs ; id 1 ; hdlr 0026A86D ; val 5 ; cycl 2
2012/02/29;14:26:32:047;001;ADL;1;wip_netInit :)
2012/02/29;14:26:32:050;001;ADL;1;wip_bearerOpen()
2012/02/29;14:26:32:054;001;ADL;1;[GPRS]: open: -> DISCONNECTED
2012/02/29;14:26:32:060;001;ADL;1;wip_bearerSetOpts()
2012/02/29;14:26:32:064;001;ADL;31;[ADL] Gprs subs 0026C869 : 0
2012/02/29;14:26:32:068;001;ADL;16;[ADL port] IsAvailable(80) : 1
2012/02/29;14:26:32:073;001;ATI;1;AT+CGDCONT=1,"IP","m2mc.webtrial",,0,0<CR>
2012/02/29;14:26:32:080;001;ATI;1;41 54 2b 43 47 44 43 4f 4e 54 3d 31 2c 22 49 50 22 2c 22 6d 32 6d 63 2e 77 65 62 74 72 69 61 6c 22 2c 2c 30 2c 30 1a 
2012/02/29;14:26:32:087;001;ATI;1;<CR><LF>OK<CR><LF>
2012/02/29;14:26:32:089;001;ATI;1;0d 0a 4f 4b 0d 0a 
2012/02/29;14:26:32:095;001;ADL;31;[ADL] Gprs setup 1 : 0
2012/02/29;14:26:32:099;001;ADL;1;[GPRS]: start: -> CONNECTING
2012/02/29;14:26:32:103;001;ADL;1;wip_bearerStart : Fail
2012/02/29;14:26:32:108;001;ADL;1;ERROR CODE: -28
2012/02/29;14:26:32:115;001;ADL;1;[GPRS]: GPRS CTX (cid=1) found
2012/02/29;14:26:32:120;001;ADL;1;[GPRS]: GPRS EVENT ACTIVATE OK (cid=1)
2012/02/29;14:26:32:129;001;ADL;1;[GPRS]: cannot get GPRS information: GPRS deactivate
2012/02/29;14:26:32:134;001;ADL;16;[ADL port] IsAvailable(80) : 1
2012/02/29;14:26:32:138;001;ADL;1;GPRS_Handler
2012/02/29;14:26:32:142;001;ADL;1;GPRS Setup error 26
2012/02/29;14:26:32:146;001;ADL;16;[ADL port] IsAvailable(80) : 1
2012/02/29;14:26:32:148;001;ATI;1;AT+CGACT=1,1<CR>
2012/02/29;14:26:32:151;001;ATI;1;41 54 2b 43 47 41 43 54 3d 31 2c 31 1a 
2012/02/29;14:26:32:157;001;ATI;1;<CR><LF>OK<CR><LF>
2012/02/29;14:26:32:159;001;ATI;1;0d 0a 4f 4b 0d 0a 
2012/02/29;14:26:32:166;001;ADL;1;[GPRS]: GPRS CTX (cid=1) found
2012/02/29;14:26:32:172;001;ADL;1;[GPRS]: GPRS EVENT SETUP/ACTIVATE KO (cid=1): -> DISCONNECTED
2012/02/29;14:26:32:178;001;ADL;1;[WIP]  No more ctx, call adl_gprsUnsubscribe()
2012/02/29;14:26:32:182;001;ADL;31;[ADL] GPRS unsubs 0026C869 : 0
2012/02/29;14:26:32:186;001;ADL;1;Bear conn failed
2012/02/29;14:26:32:188;001;ATI;1;AT+CGPADDR=1<CR>
2012/02/29;14:26:32:191;001;ATI;1;41 54 2b 43 47 50 41 44 44 52 3d 31 1a 
2012/02/29;14:26:32:194;001;ATI;1;<CR><LF>+CGPADDR: 1,<CR><LF>
2012/02/29;14:26:32:196;001;ATI;1;0d 0a 2b 43 47 50 41 44 44 52 3a 20 31 2c 0d 0a 
2012/02/29;14:26:32:202;001;ATI;1;<CR><LF>OK<CR><LF>
2012/02/29;14:26:32:205;001;ATI;1;0d 0a 4f 4b 0d 0a 
2012/02/29;14:26:32:211;001;ADL;1;GPRS_Handler

Is it a problem with the settings for the connection?
I get error -28 which seems weird because the bearer never started.
Also after the connection failed it calls the GPRS handler again with ADL_GPRS_EVENT_ACTIVATE_OK.


#2

Hi,

Are you issuing AT commands i.e. AT+CGDCONT, AT+CGACT in addition to the application? Because I can see from the traces that an IP is obtained and after which the application is trying to do a bearer start and hence failing with an error -28 (due to another GPRS bearer being active).


#3

I’m not using any AT commands besides what is written in the code I posted.
I get an IP indeed, but the bearer won’t start somehow.
I tried to reset all the settings to see if there were some old settings which were interfering with the current bearer. But it doesn’t seems to work I tried AT+WOPEN=3 and AT&F0. Still getting -28.
Is it possible old settings are interfering with the current process? How can I erase them?


#4

Hiya,

Your downloaded code should have erased any existing applications in your modem.

To be really sure, do the following:
AT+WOPEN=0 (stop any running application and reboot)
AT+WOPEN=3 (erase configuration flash)
AT+WOPEN=4 (erase A&D flash and any applications)
AT+CFUN=1 (reboot).

At this point the modem should have no application available - and AT+WOPEN=1 should return an error.

ciao, Dave


#5

Thanks, I tried that again with no result.
If I send AT+CGDCONT? after the reset procedure I get the parameters I used before (+CGDCONT: 1,“IP”,“m2mc.webtrial”,0,0).
I tried to use the AT command setup but there seem to be no open bearers. Still getting the error, so I guess something is wrong with my code…


#6

Changed my code a bit:

static void open_and_start_bearer( void) {
  int r;
  wip_bearer_t b;

  r = wip_bearerOpen( &b, "GPRS", BearHandler, NULL); //adl_gprsCmdAct error??
  if(r != 0) {
    		  	  TRACE((1, "wip_bearerOpen : Fail"));
    	  	  }

  r = wip_bearerSetOpts( b, WIP_BOPT_GPRS_APN, GPRS_APN,
          WIP_BOPT_LOGIN,       GPRS_USER,
          WIP_BOPT_PASSWORD,    GPRS_PASSWORD,
          WIP_BOPT_END);
  if(r != 0) {
    		  	  TRACE((1, "wip_bearerSetOpts : Fail"));
    		  	  wip_bearerClose(b);
    	  	  }
  r = wip_bearerStart( b);
  if(r != 0) {
    		  	TRACE((1, "wip_bearerStart : Fail"));
    		  	TRACE((1, "ERROR CODE: %d", r));
    	  	  }
}

Now I get error -27 like I got before. If I get this error the GPRS handler is called with Setup KO?

2012/03/02;11:59:13:441;001;ADL;31;[ADL] Gprs setup 1 : 0
2012/03/02;11:59:13:445;001;ADL;1;wip_bearerStart : Fail
2012/03/02;11:59:13:448;001;ADL;1;ERROR CODE: -27
2012/03/02;11:59:13:452;001;ADL;16;[ADL port] IsAvailable(80) : 1
2012/03/02;11:59:13:454;001;ADL;1;GPRS_Handler
2012/03/02;11:59:13:458;001;ADL;1;GPRS Setup KO, error 26
2012/03/02;11:59:13:462;001;ADL;16;[ADL port] IsAvailable(80) : 1
2012/03/02;11:59:13:464;001;ATI;1;AT+CGACT=1,1<CR>
2012/03/02;11:59:13:467;001;ATI;1;41 54 2b 43 47 41 43 54 3d 31 2c 31 1a 
2012/03/02;11:59:13:473;001;ATI;1;<CR><LF>OK<CR><LF>
2012/03/02;11:59:13:475;001;ATI;1;0d 0a 4f 4b 0d 0a 
2012/03/02;11:59:13:481;001;ADL;31;[ADL] GPRS unsubs 0026C505 : 0
2012/03/02;11:59:13:484;001;ADL;1;Bear conn failed
2012/03/02;11:59:13:486;001;ATI;1;AT+CGPADDR=1<CR>
2012/03/02;11:59:13:488;001;ATI;1;41 54 2b 43 47 50 41 44 44 52 3d 31 1a 
2012/03/02;11:59:13:491;001;ATI;1;<CR><LF>+CGPADDR: 1,<CR><LF>
2012/03/02;11:59:13:494;001;ATI;1;0d 0a 2b 43 47 50 41 44 44 52 3a 20 31 2c 0d 0a 
2012/03/02;11:59:13:500;001;ATI;1;<CR><LF>OK<CR><LF>

The bearer connection fails after a while, then the GPRS handler is called again with EVENT_ACTIVATE_OK. Is it my bearer options which are not ok? Should I put the IP adress in the opts?


#7

It seems I have corrected the problem, I was first setting up a GPRS connection and then I was trying to start the bearer. While the wip will connect itself to GPRS.