Http Put problem

I used the http_get sample to write a http post program. Please find my code below:

/*

  • M2MGPRS.c
  • Created on: 27-Apr-2009
  •  Author: Terence Njinembo
    

*/

#include “adl_global.h”
#include “commonhdr.h”
#include “wip.h”
#include “adl_sim.h”
#include “M2MGPRS.h”

/**************************************************************************/
/
Defines /
/
*************************************************************************/
#define GPRS_APN “LIVE.VODAFONE.COM
#define GPRS_USER “vodafone”
#define GPRS_PASSWORD “vodafone”
#define GPRS_PINCODE “0000”
#define DST_FILENAME “Weather_station_data” /
Name of the file to put */

#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))

extern GPStimedate GPStimedate_t;
extern GPSposition GPSposition_t;
extern GPIO26info GPIO26info_t;

// HTTP defined strings set
// ------------------------
const ascii * HTTP_STR_URL = “http://en.wikipedia.org/wiki/Portal:Science”;

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;

/********************************************************************/
/
Function : http_ClientTestDataHandler /
/
-------------------------------------------------------------------------
/
/
Object : Handler for the HTTP data channel /
/
/
/
Returned : none /
/
/
/
/
/
--------------------±–±--±–±---------------------------------------
/
/
Variable Name |IN |OUT|GLB| Use /
/
--------------------±–±--±–±---------------------------------------
/
/
| | | | /
/
**************************************************************************/
static void http_ClientTestDataHandler( wip_event_t *ev, void ctx)
{
ascii tmpbuf[60];
int BytesWritten;
ascii info[10];
/
How many bytes of [tmpbuf] have already been sent. */
static int offset = 0;
s16 m,n,p,w;

/*wm_sprintf(tmpbuf, "\r\nLong/Lat/Alt: %0.02f%c, %0.02f%c, %0.02f%c\n ",
//“Time: %02lu:%02lu:%02lu\n”
//“Date: %02lu/%02lu/%04lu\n”
// “Temperature: %0.01f %s\n”
//“Relative Hum: %0.01f%c\r\n”,
fabs(GPSposition_t.Longitude),
GPSposition_t.dir[1],
fabs(GPSposition_t.Latitude),
GPSposition_t.dir[0],
GPSposition_t.Altitude,‘m’);
GPStimedate_t.hour,
GPStimedate_t.minute,
GPStimedate_t.seconds,
GPStimedate_t.day,
GPStimedate_t.month,
GPStimedate_t.year,
GPIO26info_t.TenMinTemp,“deg.celsius”,
GPIO26info_t.TenMinHum,’%’);
*/

m = (s16) GPIO26info_t.TenMinTemp * 10; // Decimal precision: 1 digit
n = (GPIO26info_t.TenMinTemp * 10 ) - m; // Decimal precision: 1 digit

p = (s16) GPIO26info_t.TenMinHum * 10; // Decimal precision: 1 digit
w = (GPIO26info_t.TenMinHum * 10 ) - p; // Decimal precision: 1 digit

wm_sprintf(tmpbuf, “\r\nTemperature: %d.%01d %s\r\n”, (s16)GPIO26info_t.TenMinTemp, n, “deg.celsius”);

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” );
adl_atSendResponsePort ( ADL_AT_RSP, ADL_PORT_UART1, “\r\nhttp_ClientTestDataHandler: Start\r\n”);
break;

  /* There is some space available in TCP send buffer, which allows me
     * to write more data from [tmpbuf]; let's write as much data as
     * possible, up to the end of [tmpbuf]. [BytesWritten] is the number of bytes
     * I actually managed to put in the TCP buffer. */
case WIP_CEV_WRITE:
  TRACE(( 4, "http_ClientTestDataHandler: WIP_CEV_WRITE\n" ));
  adl_atSendResponsePort ( ADL_AT_RSP, ADL_PORT_UART1, "\r\nhttp_ClientTestDataHandler: WIP_CEV_WRITE\r\n");
  // we must read all available data to trigger WIP_CEV_READ again

  BytesWritten = wip_write( ev->channel, tmpbuf, sizeof(tmpbuf)-offset);
  if(BytesWritten < 0)
  {/* error */
	  return;
  }
  offset += BytesWritten; /* Update the number of bytes sent. */
  if( offset == sizeof( tmpbuf)) { /* All of [buffer] has been sent */
      TRACE(( 4, "http_ClientTestDataHandler: bytes %d written\n", offset ));
      wm_sprintf( info, "\r\nhttp_ClientTestDataHandler: %d bytes written\r\n", offset);
      adl_atSendResponsePort ( ADL_AT_RSP, ADL_PORT_UART1, info);
     }
  wip_close( ev->channel);
  break;

case WIP_CEV_PEER_CLOSE:
  TRACE(( 2, "http_ClientTestDataHandler: WIP_CEV_PEER_CLOSE\n" ));

  adl_atSendResponsePort ( ADL_AT_RSP, ADL_PORT_UART1, "\r\nhttp_ClientTestDataHandler: Done\r\n");

  // data channel must be closed
  wip_close( ev->channel);

  break;

case WIP_CEV_ERROR:
  TRACE(( 2, "http_ClientTestDataHandler: WIP_CEV_ERROR %d\n",
          ev->content.error.errnum));
  //adl_atSendResponse ( ADL_AT_UNS, "http_ClientTestDataHandler: ERROR\r\n" );
  adl_atSendResponsePort ( ADL_AT_RSP, ADL_PORT_UART1, "\r\nhttp_ClientTestDataHandler: ERROR\r\n");
  // connection to server broken
  wip_close( ev->channel);

  break;

default:
  TRACE(( 2, "http_ClientTestDataHandler: unexpected event: %d\n",
          ev->kind));
  adl_atSendResponsePort ( ADL_AT_RSP, ADL_PORT_UART1, "\r\nunexpected event\r\n");
  break;

}
}

void GPRSTimerhdl(u8 TimerIdFive)
{
// HTTP PUT command
// ---------------------------
http_ClientTestCtx.DataChannel = wip_putFileOpts(

	                                         http_ClientTestCtx.CnxChannel,  // session channel
	                                         HTTP_STR_URL,                   // URL to receive the data
	                                         http_ClientTestDataHandler,     // data handler
	                                         &http_ClientTestCtx,            // context
	                                        // WIP_COPT_HTTP_METHOD,  WIP_HTTP_METHOD_POST,
	                                         WIP_COPT_END);

	    if (http_ClientTestCtx.DataChannel == NULL)
	    {
	      TRACE(( 2, "cannot create http data channel\n" ));
	      //adl_atSendResponse ( ADL_AT_UNS, "cannot create http data channel\r\n" );
adl_atSendResponsePort ( ADL_AT_RSP, ADL_PORT_UART1, "\r\ncannot create http data  channel\r\n");
	      wip_close( http_ClientTestCtx.CnxChannel);
	     // ret =-1;
	    }
	    else
	   adl_atSendResponsePort ( ADL_AT_RSP, ADL_PORT_UART1, "\r\nHTTP data channel created\r\n");

}

static s32 http_Client(void)
{
s32 ret = 0;

// 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_END);

  if (http_ClientTestCtx.CnxChannel == NULL)
  {
     TRACE(( 2, "cannot create http session channel\n" ));
     //adl_atSendResponse ( ADL_AT_UNS, "cannot create http session channel\r\n" );
     adl_atSendResponsePort ( ADL_AT_RSP, ADL_PORT_UART1, "\r\ncannot create http session channel\r\n");
     ret = -1;
  }
  else {
	  adl_atSendResponsePort ( ADL_AT_RSP, ADL_PORT_UART1, "\r\nhttp session channel created\r\n");
     
  }

 return(ret);

}

/*******************************************************************/
/
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) {
if( WIP_BEV_IP_CONNECTED == event)
TRACE(( 4, “http_ClientTestDataHandler: WIP_BEV_IP_CONNECTED \n” ));
http_Client();
}

//
/
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) {
int r;
wip_bearer_t b;

r = wip_bearerOpen( &b, “GPRS”, evh_bearer, NULL);
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);
ASSERT_OK( r);
r = wip_bearerStart( b);
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 (( 2, "(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 (( 2, "(poll_creg_callback) Registered on GPRS network." ));
    adl_atSendResponsePort ( ADL_AT_RSP, ADL_PORT_UART1, "\r\nRegistered on GPRS network\r\n");
    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);
  adl_atSendResponsePort ( ADL_AT_RSP, ADL_PORT_UART1, "\r\nNot Registered on GPRS network\r\n");
}
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 IdFive ) {
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) {
s32 sim_state;
ascii simbuf[16];

TRACE (( 2, “(evh_sim) Enter.” ));

if( event == ADL_SIM_EVENT_FULL_INIT) {
adl_atSendResponsePort ( ADL_AT_RSP, ADL_PORT_UART1, “\r\nSIM subscribed\r\n”);
poll_creg( 0); /* argument 0 is dummy, see poll_reg() “Object” comment */
sim_state = adl_simGetState ();
wm_sprintf( simbuf, “%d”, sim_state);
adl_atSendResponsePort ( ADL_AT_RSP, ADL_PORT_UART1, simbuf);
}
else{
adl_atSendResponsePort ( ADL_AT_RSP, ADL_PORT_UART1, “\r\nSIM not subscribed\r\n”);
sim_state = adl_simGetState ();
wm_sprintf( simbuf, “%d”, sim_state);
adl_atSendResponsePort ( ADL_AT_RSP, ADL_PORT_UART1, simbuf);
}
}

s32 GPRSinit(void)
{
s32 init_state;

/* Initialise the TCP/IP stack */
init_state= wip_netInitOpts(
                WIP_NET_OPT_DEBUG_PORT, WIP_NET_DEBUG_PORT_UART1, /* WIP traces on UART1 */
    	        WIP_NET_OPT_END);

adl_simSubscribe( evh_sim, GPRS_PINCODE);

return init_state;

}

The code works well but the Fastrack Supreme restarts immediately after the data has been written to URL. after the creation of an http session channel i create the data channel every 25seconds so that the data (temperature) will be sent every 25seconds to the URL. why does the Fastrack Supreme restart after sending the data ? How can i solve this problem ?