hi all, i’m trying to make a tcp client using wip over gprs, and it has some problems.
#include "adl_global.h"
#include "wip.h"
#define SERVER_PORT 80
#define SERVER_ADDRESS "google.com.vn"
const u16 wm_apmCustomStackSize = 1024* 3 ;
void myHandler(wip_bearer_t br, s8 event, void *context) {
TRACE((1,"bearer_receive %d",event));
switch (event) {
case WIP_BEV_CONN_FAILED:
TRACE((1,"connection fail"));
break;
case WIP_BEV_IP_CONNECTED:
// IP connectivity, start IP application here
TRACE((1,"connected,ok"));
break;
case WIP_BEV_IP_DISCONNECTED:
//stop IP application here
TRACE((1,"disconnected,ok"));
break;
default:
break;
}
}
wip_bearer_t myBearer;
bool connectToGPRS(void) {
s8 ercode;
if (ercode = wip_bearerOpen(&myBearer, "GPRS", myHandler, NULL)) {
TRACE((1,"cannot open gprs,code=%d",ercode));
return FALSE;
}
if (ercode = wip_bearerSetOpts(myBearer, WIP_BOPT_GPRS_APN, "v-internet",
WIP_BOPT_LOGIN, "", WIP_BOPT_PASSWORD, "", WIP_BOPT_END)) {
wip_bearerClose(myBearer);
TRACE((1,"setopt fail,errorcode=%d",ercode));
return FALSE;
}
if ((ercode = wip_bearerStart(myBearer)) != OK && (ercode
!=WIP_BERR_OK_INPROGRESS)) {
wip_bearerClose(myBearer);
TRACE((1,"cannot start bearer,errorcode=%d",ercode));
return FALSE;
}
wip_bearerGetOpts(myBearer, WIP_BOPT_ERROR, &ercode, WIP_BOPT_END);
TRACE((1,"lasterr=%d",ercode));
return TRUE;
}
void commonHandler(wip_event_t *e, enum state *ctx) {
static bool init = FALSE;
u8 buffer[256];
ascii buff[256];
s32 nread;
wip_channel_t c = e->channel;
TRACE((1,"recevice wip kind=%d",e->kind));
switch (e->kind) {
case WIP_CEV_READ:
nread = wip_read(c, buffer, sizeof(buffer) - 1);
buffer[nread] = '\0';
wm_sprintf(buff, "rev:%s", buffer);
TRACE((1,buff));
break;
case WIP_CEV_WRITE:
TRACE((1,"sending hello"));
wip_write(c, "GET / HTTP/1.1\r\n\r\n", wm_strlen(
"GET / HTTP/1.1\r\n\r\n"));
break;
case WIP_CEV_ERROR:
case WIP_CEV_PEER_CLOSE:
case WIP_CEV_PING:
break;
}
}
void startClient(u8 timeID) {
wip_channel_t client = wip_TCPClientCreate(SERVER_ADDRESS, SERVER_PORT,
commonHandler,NULL);
}
void simHandler(u8 event) {
switch (event) {
case ADL_SIM_EVENT_FULL_INIT:
TRACE((1,"sim event full init"));
s8 code = wip_netInit();
TRACE((1,"init: %d",code));
if (connectToGPRS()) {
//adl_tmrSubscribe(TRUE, 50, ADL_TMR_TYPE_100MS, startClient);
startClient();
}
break;
}
}
void adl_main(adl_InitType_e InitType) {
TRACE (( 1, "project13 gprs/tcpip : Main" ));
s32 ret = adl_simSubscribe(simHandler, NULL);
TRACE((1,"Subscribed %d",ret));
}
when app start, wip_bearerStart() function return WIP_BERR_OK_INPROGRESS, which i don’t know that is OK or not. At later, when wip_TCPClientCreate() is called, the bearerHandler received a connection fail event(i’ve used gprs with this sim on my hand phone and it work ok) log of the program:
09/10/12,04:34:41:32 CUS4 1 sim event full init
09/10/12,04:34:41:81 CUS4 1 [GPRS]: initialized.
09/10/12,04:34:41:82 CUS4 1 [GSM]: initialized.
09/10/12,04:34:41:83 CUS4 1 [UART1]: initialized.
09/10/12,04:34:41:84 CUS4 1 [UART2]: initialized.
09/10/12,04:34:41:85 CUS4 1 []: initialized.
09/10/12,04:34:41:86 CUS4 1 init: 0
09/10/12,04:34:41:88 CUS4 1 [GPRS]: open: -> DISCONNECTED
09/10/12,04:34:41:163 CUS4 1 [GPRS]: start: -> CONNECTING
09/10/12,04:34:41:163 CUS4 1 lasterr=0
09/10/12,04:34:41:202 CUS4 1 [GPRS]: GPRS EVENT SETUP OK (cid=1): GPRS activate
09/10/12,04:34:41:536 CUS4 1 recevice wip kind=1
09/10/12,04:34:46:131 CUS4 1 [GPRS]: GPRS EVENT: 27 (cid=1)
09/10/12,04:34:47:767 CUS4 1 [GPRS]: GPRS EVENT SETUP/ACTIVATE KO (cid=1): -> DISCONNECTED
09/10/12,04:34:47:768 CUS4 1 bearer_receive 1
09/10/12,04:34:47:769 CUS4 1 connection fail
please help me!