Hi,
I am using m2m studio 1.0.2 with a development board q2687G also I have the R74 firmware and 06.30 OS on the unit.
When my program goes into the first loop it post’s the data to the server correctly, then I destroy the connection and after a period repeat it again. But when I do it the second time, my program does not post the data or read anything.
Can anyone help me please…
Here is my Traces:
10/01/07,09:35:20:171 ADL 1 ADL_SIM_EVENT_INSERTED
10/01/07,09:35:20:703 ADL 1 ADL_SIM_EVENT_PIN_OK
10/01/07,09:35:27:593 ADL 1 ADL_SIM_EVENT_FULL_INIT
10/01/07,09:35:27:593 ADL 20 [ADL] tmr subs ; id 1 ; hdlr 0026E8E5 ; val 5 ; cycl 2
10/01/07,09:35:27:593 ADL 1 poll_creg
10/01/07,09:35:27:593 ADL 20 [ADL] tmr subs ; id 2 ; hdlr 00260725 ; val 500 ; cycl 2
10/01/07,09:35:29:656 ADL 1 poll_creg
10/01/07,09:35:29:656 ADL 1 (poll_creg_callback) Enter.
10/01/07,09:35:29:656 ADL 1 (poll_creg_callback) Registered on GPRS network.
10/01/07,09:35:29:656 ADL 27 Call subs 0027D079 : 0
10/01/07,09:35:29:656 ADL 31 Gprs subs 0027131D : 0
10/01/07,09:35:29:656 ADL 16 [ADL port] IsAvailable(80) : 1
10/01/07,09:35:29:656 ADL 31 Gprs setup 1 : 0
10/01/07,09:35:29:656 ADL 16 [ADL port] IsAvailable(80) : 1
10/01/07,09:35:32:187 ADL 1 BearerEventHandler: <WIP_BEV_IP_CONNECTED>
10/01/07,09:35:32:187 ADL 2 HTTP Client Service test application : Init
10/01/07,09:35:32:187 ADL 1 http session channel created
10/01/07,09:35:32:187 ADL 1 http data channel created
10/01/07,09:35:32:734 ADL 4 http_ClientTestDataHandler: WIP_CEV_OPEN
10/01/07,09:35:32:734 ADL 4 http_ClientTestDataHandler: WIP_CEV_WRITE
10/01/07,09:35:32:734 ADL 5 http_ClientTestDataHandler: data 403442268 written
10/01/07,09:35:32:734 ADL 4 http_ClientTestDataHandler: bytes 30 written
10/01/07,09:35:34:968 ADL 4 http_ClientTestDataHandler: WIP_CEV_READ
10/01/07,09:35:34:968 ADL 4 http_ClientTestDataHandler: read 0 bytes
10/01/07,09:35:34:968 ADL 4 http_ClientTestDataHandler: WIP_CEV_READ
10/01/07,09:35:34:968 ADL 4 http_ClientTestDataHandler: read 24 bytes
10/01/07,09:35:34:968 ADL 4 http_ClientTestDataHandler: WIP_CEV_PEER_CLOSE
10/01/07,09:35:34:968 ADL 4 http_ClientTestDataHandler: Status=200
10/01/07,09:35:34:968 ADL 4 http_ClientTestDataHandler: Reason=“OK”
10/01/07,09:35:34:968 ADL 4 http_ClientTestDataHandler: Response Length=54 bytes
10/01/07,09:35:37:406 ADL 16 [ADL port] IsAvailable(80) : 1
10/01/07,09:35:37:406 ADL 1 BearerEventHandler: <WIP_BEV_IP_DISCONNECTED >
10/01/07,09:35:37:406 ADL 27 Call unsubs 0027D079 : 0
10/01/07,09:35:37:406 ADL 31 GPRS unsubs 0027131D : 0
10/01/07,09:36:17:656 ADL 1 poll_creg
10/01/07,09:36:17:656 ADL 1 (poll_creg_callback) Enter.
10/01/07,09:36:17:656 ADL 1 (poll_creg_callback) Registered on GPRS network.
10/01/07,09:36:17:656 ADL 1 open and start bearer.
10/01/07,09:36:17:656 ADL 31 Gprs subs 0027131D : 0
10/01/07,09:36:17:656 ADL 16 [ADL port] IsAvailable(80) : 1
10/01/07,09:36:20:281 ADL 1 BearerEventHandler: <WIP_BEV_IP_CONNECTED>
10/01/07,09:36:20:281 ADL 2 HTTP Client Service test application : Init
10/01/07,09:36:20:281 ADL 1 http session channel created
10/01/07,09:36:20:281 ADL 1 http data channel created
10/01/07,09:36:20:562 ADL 4 http_ClientTestDataHandler: WIP_CEV_OPEN
10/01/07,09:36:20:562 ADL 4 http_ClientTestDataHandler: WIP_CEV_WRITE
10/01/07,09:36:20:562 ADL 5 http_ClientTestDataHandler: data 403442268 written
10/01/07,09:36:20:562 ADL 4 http_ClientTestDataHandler: bytes 30 written
And the Shell…
ADL_SIM_EVENT_INSERTED
+CREG: 2
ADL_SIM_EVENT_PIN_OK
ADL_SIM_EVENT_FULL_INIT
Start GPRS Procedure
poll_creg
+CREG: 1,“02C9”,“C352”
poll_creg
[GPRS]: open: -> DISCONNECTED
[GPRS]: start: -> CONNECTING
[GPRS]: GPRS EVENT SETUP OK (cid=1): GPRS activate
[GPRS]: GPRS EVENT: 27 (cid=1)
[GPRS]: GPRS EVENT ACTIVATE OK (cid=5)
[GPRS]: GPRS: -> CONNECTED
HTTP Client Service test application : Init
PARSE_URL STEP3[HTTP] req parsed URL: /post.php at myurl.co.za
[HTTP] new request GET myurl.co.za/post.php HTTP/1.0 @ 180c6644
[HTTP] connect to host: myurl.co.za:80
[WIP] new TCPCLIENT 0x180c5864
[req_event] WIP_CEV_OPEN
[req_event] WIP_CEV_WRITE
http_ClientTestDataHandler: Start
http_ClientTestDataHandler: WIP_CEV_WRITE
http_ClientTestDataHandler: WIP_CEV_WRITE
date_time=2009-09-12&temp=21.5
http_ClientTestDataHandler: 30 bytes written
[req_event] WIP_CEV_READ
[req_event] WIP_CEV_READ
AA Test data response AA[req_event] WIP_CEV_PEER_CLOSE
http_ClientTestDataHandler: Done
http_ClientTestDataHandler: Status=200
http_ClientTestDataHandler: Reason=“OK”
WIP CLOSE OK
[WIP] closing HTTP_DATA 0x180c6644
[HTTP] destroy request @ 180c6644
[WIP] closing HTTP_CONTROL 0x180c6404
Release subLevelOptions
[WIP] closing TCPCLIENT 0x180c5864
[GPRS]: -> PEER DISCONNECTING
[GPRS]: GPRS deactivate
[GPRS]: close: -> CLOSED
+CGREG: 0
poll_creg
[GPRS]: open: -> DISCONNECTED
[GPRS]: start: -> CONNECTING
[GPRS]: GPRS EVENT SETUP OK (cid=1): GPRS activate
[GPRS]: GPRS EVENT: 27 (cid=1)
[GPRS]: GPRS EVENT ACTIVATE OK (cid=5)
[GPRS]: GPRS: -> CONNECTED
HTTP Client Service test application : Init
PARSE_URL STEP3[HTTP] req parsed URL: /post.php at myurl.co.za
[HTTP] new request GET myurl.co.za/post.php HTTP/1.0 @ 180c6824
[HTTP] connect to host: myurl.co.za:80
[WIP] new TCPCLIENT 0x180c5864
[req_event] WIP_CEV_OPEN
[req_event] WIP_CEV_WRITE
http_ClientTestDataHandler: Start
http_ClientTestDataHandler: WIP_CEV_WRITE
http_ClientTestDataHandler: WIP_CEV_WRITE
date_time=2009-09-12&temp=21.5
http_ClientTestDataHandler: 30 bytes written
and here is the important parts of the code…
after sim ok:
wiprun_cmd();
// Initialize port debugging for WIP
r = wip_netInitOpts(
WIP_NET_OPT_DEBUG_PORT, WIP_NET_DEBUG_PORT_UART1, // WIP traces on UART1
//WIP_NET_OPT_DEBUG_PORT, WIP_NET_DEBUG_PORT_UART2,
//WIP_NET_OPT_DEBUG_PORT, WIP_NET_DEBUG_PORT_TRACE,
WIP_NET_OPT_END);
poll_creg(0);
adl_tmrSubscribe(TRUE, 500, ADL_TMR_TYPE_100MS, poll_creg);
void wipBearerEventHandler( wip_bearer_t b, s8 event, void *ctx) {
switch(event)
{
case WIP_BEV_IP_CONNECTED:
TRACE (( 1, "BearerEventHandler: <WIP_BEV_IP_CONNECTED>"));
appli_entry_point();
break;
case WIP_BEV_CONN_FAILED:
TRACE (( 1, "BearerEventHandler: <WIP_BEV_CONN_FAILED>"));
wip_bearerClose( bearerHandle );
break;
case WIP_BEV_STOPPED:
TRACE (( 1, "BearerEventHandler: <WIP_BEV_STOPPED>"));
wip_bearerClose(bearerHandle );
break;
case WIP_BEV_IP_DISCONNECTED:
TRACE (( 1, "BearerEventHandler: <WIP_BEV_IP_DISCONNECTED >"));
wip_bearerClose(bearerHandle );
break;
default:
TRACE (( 1, "BearerEventHandler: <WIP Other Events>: %d", event));
break;
}
}
void open_and_start_bearer( void) {
int r;
//wip_bearer_t bearerHandle;
TRACE (( 1, "open and start bearer." ));
r = wip_bearerOpen( &bearerHandle, "GPRS", ( wip_bearerHandler_f )wipBearerEventHandler, NULL);
ASSERT_OK( r);
// Set the GPRS bearer options
r = wip_bearerSetOpts( bearerHandle,
WIP_BOPT_GPRS_APN, GPRS_APN,
WIP_BOPT_LOGIN, GPRS_USER,
WIP_BOPT_PASSWORD, GPRS_PASSWORD,
WIP_BOPT_END);
ASSERT_OK( r);
// Start the GPRS bearer
r = wip_bearerStart( bearerHandle);
ASSERT( 0 == r || WIP_BERR_OK_INPROGRESS == r);
}
void poll_creg( u8 Id );
bool poll_creg_callback(adl_atResponse_t *Rsp) {
ascii *rsp;
ascii regStateString[3];
s32 regStateInt;
TRACE (( 1, "(poll_creg_callback) Enter." ));
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." ));
open_and_start_bearer();
} else {
/* Not ready yet, we'll check again later. Set a one-off timer. */
adl_tmrSubscribe( FALSE, CREG_POLLING_PERIOD, ADL_TMR_TYPE_100MS, poll_creg);
}
return FALSE;
}
void wiprun_cmd(void)
{
//subscride to the wip application
wip_ATCmdSubscribe ();
wip_netInit();
}
void poll_creg( u8 Id )
{
TRACE (( 1, "poll_creg" ));
adl_atSendResponse ( ADL_AT_UNS, "poll_creg\r\n" );
adl_atCmdCreate( "AT+CREG?", FALSE, poll_creg_callback, ADL_STR_CREG, NULL);
}
and…
void stop_gprs( void) {
adl_atCmdSend("AT+CGATT=0",gen_handlr,NULL);
}
static void http_ClientTestDataHandler( wip_event_t *ev, void *ctx)
{
ascii tmpbuf[256];
ascii Ptr_OnTrace[240];
s32 BytesWritten;
ascii info[50];
int len, tmplen;
//How many bytes of [tmpbuf] have already been sent.
static int offset = 0;
s32 status, sRet, sRet2;
http_ClientTestCtx_t *pHttpClientCtx =
(http_ClientTestCtx_t *) &http_ClientTestCtx;
switch(ev->kind)
{
case WIP_CEV_OPEN:
TRACE(( 4, "http_ClientTestDataHandler: WIP_CEV_OPEN\n" ));
adl_atSendResponse ( ADL_AT_UNS, "http_ClientTestDataHandler: Start\r\n" );
// ready for getting response data
pHttpClientCtx->dataLength = 0;
break;
case WIP_CEV_READ:
TRACE(( 4, "http_ClientTestDataHandler: WIP_CEV_READ\n" ));
// we must read all available data to trigger WIP_CEV_READ again
tmplen = 0;
while( (len = wip_read( ev->channel, tmpbuf, sizeof(tmpbuf)-1)) > 0) {
tmpbuf[len] = 0;
adl_atSendResponse ( ADL_AT_UNS, tmpbuf );
tmplen += len;
}
TRACE(( 4, "http_ClientTestDataHandler: read %d bytes\n", tmplen ));
// compute total length of response
pHttpClientCtx->dataLength += tmplen;
break;
case WIP_CEV_WRITE:
adl_atSendResponse ( ADL_AT_UNS, "http_ClientTestDataHandler: WIP_CEV_WRITE\n" );
TRACE(( 4, "http_ClientTestDataHandler: WIP_CEV_WRITE\n" ));
adl_atSendResponsePort ( ADL_AT_RSP, ADL_PORT_UART1, "\r\nhttp_ClientTestDataHandler: WIP_CEV_WRITE\r\n");
wip_state = wip_getState(ev->channel);
if (wip_state==WIP_CSTATE_READY || WIP_CSTATE_BUSY)
{
// we must write all available data to trigger WIP_CEV_WRITE again
BytesWritten = wip_write( ev->channel, writbuf, sizeof(writbuf)-offset);
TRACE(( 5, "http_ClientTestDataHandler: data %d written\n", writbuf ));
if(BytesWritten < 0)
{//error
//wip_debug( "HTTP write error %i\n", BytesWritten);
adl_atSendResponse ( ADL_AT_UNS, "\r\nwip_write error\r\n" );
return;
}
offset += BytesWritten; // Update the number of bytes sent.
pHttpClientCtx->dataLength += offset;
if( offset == sizeof( writbuf)) { //All of [buffer] has been sent
TRACE(( 4, "http_ClientTestDataHandler: bytes %d written\n", offset ));
adl_atSendResponsePort ( ADL_AT_RSP, ADL_PORT_UART1,writbuf);
wm_sprintf( info, "\r\nhttp_ClientTestDataHandler: %d bytes written\r\n", offset);
adl_atSendResponsePort ( ADL_AT_RSP, ADL_PORT_UART1, info);
}
//wip_shutdown(ev->channel,FALSE,TRUE);
//added to close channel
//wip_close( ev->channel);
//3s delay
// adl_ctxSleep(4000 / 18.5 );
//stop the bearer
// stop_bearer();
//adl_atCmdCreate( "at+cgatt=0", FALSE, NULL, "", NULL);
//3s delay
//adl_ctxSleep(3000 / 18.5 );
//voda_prepaid_retrieve();
}
else if (wip_state==WIP_CSTATE_TO_CLOSE)
{
adl_atSendResponsePort ( ADL_AT_RSP, ADL_PORT_UART1, "\r\nData channel is broken\r\n");
wip_close( ev->channel);
}
break;
case WIP_CEV_PEER_CLOSE:
TRACE(( 4, "http_ClientTestDataHandler: WIP_CEV_PEER_CLOSE\n" ));
adl_atSendResponse ( ADL_AT_UNS, "\r\nhttp_ClientTestDataHandler: Done\r\n" );
// end of data
// show response information
if( wip_getOpts( ev->channel,
WIP_COPT_HTTP_STATUS_CODE, &status,
WIP_COPT_HTTP_STATUS_REASON, tmpbuf, sizeof(tmpbuf),
WIP_COPT_END) == OK) {
ascii sbuf[16];
adl_atSendResponse ( ADL_AT_UNS, "http_ClientTestDataHandler: Status=" );
wm_sprintf( sbuf, "%d", status);
adl_atSendResponse ( ADL_AT_UNS, sbuf);
adl_atSendResponse ( ADL_AT_UNS, "\r\nhttp_ClientTestDataHandler: Reason=\"" );
adl_atSendResponse ( ADL_AT_UNS, tmpbuf);
adl_atSendResponse ( ADL_AT_UNS, "\"\r\n" );
TRACE(( 4, "http_ClientTestDataHandler: Status=%d\n", status));
wm_sprintf(Ptr_OnTrace, "http_ClientTestDataHandler: Reason=\"%s\"\n", tmpbuf);
TRACE((4,Ptr_OnTrace));
}
if( wip_getOpts( ev->channel,
WIP_COPT_HTTP_HEADER, "content-type", tmpbuf, sizeof(tmpbuf),
WIP_COPT_END) == OK) {
wm_sprintf(Ptr_OnTrace, "http_ClientTestDataHandler: Content Type=\"%s\"\n", tmpbuf);
TRACE((4,Ptr_OnTrace));
}
TRACE(( 4, "http_ClientTestDataHandler: Response Length=%d bytes\n",
pHttpClientCtx->dataLength ));
wip_shutdown(ev->channel,FALSE,TRUE);
//wip_shutdown(ev->channel,FALSE,TRUE);
/* close the channel */
sRet = wip_close( ev->channel);
sRet2 = wip_close(http_ClientTestCtx.CnxChannel);
if((sRet == 0) && (sRet2 == 0))
{
adl_atSendResponse (ADL_AT_UNS,"\r\nWIP CLOSE OK\r\n");
//stop the bearer
//adl_tmrSubscribe(FALSE, 25, ADL_TMR_TYPE_100MS, stop_bearer);
adl_tmrSubscribe(FALSE, 25, ADL_TMR_TYPE_100MS, stop_gprs);
//stop_bearer();
}
else
{
adl_atSendResponse ( ADL_AT_UNS,"\r\nWIP CLOSE ERROR\r\n");
}
//stop_bearer();
break;
case WIP_CEV_ERROR:
TRACE(( 4, "http_ClientTestDataHandler: WIP_CEV_ERROR %d\n",
ev->content.error.errnum));
adl_atSendResponse ( ADL_AT_UNS, "http_ClientTestDataHandler: ERROR\r\n" );
// connection to server broken
wip_close( ev->channel);
break;
case WIP_CEV_PING:
TRACE (( 1, "http_ClientTestDataHandler: WIP_CEV_PING"));
adl_atSendResponse ( ADL_AT_UNS, "http_ClientTestDataHandler: PING\r\n" );
break;
case WIP_CEV_DONE:
TRACE (( 1, "http_ClientTestDataHandler: WIP_CEV_DONE"));
adl_atSendResponse ( ADL_AT_UNS, "http_ClientTestDataHandler: DONE\r\n" );
break;
default:
TRACE(( 4, "http_ClientTestDataHandler: unexpected event: %d\n",
ev->kind));
break;
}
}
static s32 http_ClientTestCreate(void)
{
s32 ret = 0;
ascii datalenght[10];
fillwritbuf();
wm_itoa(sizeof(writbuf),datalenght);
// HTTP Session creation
// ---------------------------
http_ClientTestCtx.CnxChannel = wip_HTTPClientCreateOpts(
NULL, // no handler
NULL, // no context
// default headers
//WIP_COPT_HTTP_HEADER, "User-Agent", "WIPHTTP/1.0",
WIP_COPT_HTTP_VERSION, WIP_HTTP_VERSION_1_0,
WIP_COPT_END);
if (http_ClientTestCtx.CnxChannel == NULL)
{
TRACE(( 1, "cannot create http session channel\n" ));
adl_atSendResponse ( ADL_AT_UNS, "cannot create http session channel\r\n" );
ret = -1;
}
else
{
// HTTP POST command
// ---------------------------
TRACE(( 1, "http session channel created\n" ));
http_ClientTestCtx.DataChannel = wip_getFileOpts(
http_ClientTestCtx.CnxChannel, // session channel
HTTP_STR_URL, // requested URL
http_ClientTestDataHandler, // data handler
&http_ClientTestCtx, // context
WIP_COPT_HTTP_METHOD, WIP_HTTP_METHOD_POST,
// request headers
WIP_COPT_HTTP_HEADER, "Accept", "text/html",
WIP_COPT_HTTP_HEADER, "Content-Length", datalenght,
WIP_COPT_HTTP_HEADER, "Content-Type", "application/x-www-form-urlencoded",
WIP_COPT_HTTP_HEADER, "Host", "www.myurl.co.za",
WIP_COPT_END);
if (http_ClientTestCtx.DataChannel == NULL)
{
TRACE(( 1, "cannot create http data channel\n" ));
adl_atSendResponse ( ADL_AT_UNS, "cannot create http data channel\r\n" );
wip_close( http_ClientTestCtx.CnxChannel);
ret =-1;
}
else
{
TRACE(( 1, "http data channel created\n" ));
}
}
return(ret);
}
void appli_entry_point(void) {
TRACE (( 2, "HTTP Client Service test application : Init" ));
adl_atSendResponse ( ADL_AT_UNS, "\r\nHTTP Client Service test application : Init\r\n" );
http_ClientTestCreate();
}
some variables declared…
const ascii * HTTP_STR_URL = "http://www.myurl.co.za/post.php";
wip_bearer_t bearerHandle = NULL;
typedef struct
{
wip_channel_t CnxChannel; // session channel
wip_channel_t DataChannel; // data channel
u32 dataLength; // response data length
} http_ClientTestCtx_t;
http_ClientTestCtx_t http_ClientTestCtx;
wip_cstate_t wip_state;
ascii writbuf[30];
thanx a lot in advance…