Tcpclient with fcm

Hi ,

I’m trying to send to a server address some data which is received on UART1.
Therefore i have used the FCM code to retrieve 10 bytes and then initiated a client connection to the peer address using a client to server code. It seems that the process is going well including open beerer , and connection to the peer address. However:

  1. It seems that the server side(second sierra’s modem) do not see the client request although on the client it looks like there was a connection.

  2. after the connection was failed and the meter function went back to read data , the debugger went down…
    See below my code and attached is the log and traces.

Any immidate assitance will be highly appreciated.

Thanks ,

static void evh_bearer( wip_bearer_t b, s8 event, void *ctx) {
  if( WIP_BEV_IP_CONNECTED == event)
  {
	  appli_entry_point();
  }
}


void appli_entry_point() {
  wip_channel_t socket;
  wip_debug( "[SAMPLE]: connecting to client %s:%i...\n", PEER_STRADDR, PEER_PORT);
  socket = wip_TCPClientCreate( PEER_STRADDR, PEER_PORT, evh, NULL);
  iscon = true;
  if( ! socket) { wip_debug( "[SAMPLE] Can't connect\n"); return; }
}



static void evh( wip_event_t *ev, void *ctx,ascii *snd_buffer) {
	int r;
	wip_bearer_t b;
  switch( ev->kind) {

  case WIP_CEV_OPEN: {
    wip_debug ("[SAMPLE] Connection established successfully\n");
    iscon = true;
    break;
  }
  case WIP_CEV_READ: {
    	.
	.
	.
    }
    break;
  }
  case WIP_CEV_WRITE: {
    int nwrite;
    wip_debug ("[SAMPLE] Can send more data\n");
    nwrite = wip_write( ev->channel, snd_buffer + snd_offset,
                        sizeof( snd_buffer) - snd_offset);
    if( nwrite < 0) { wip_debug( "[SAMPLE] write error %i\n", nwrite); return; }
    snd_offset += nwrite;
    if( snd_offset == sizeof( snd_buffer)) {
      
      wip_debug( "[SAMPLE] Everything has been sent, won't send more.\n");
      wip_bearerClose( b );
      //adl_atCmdCreate("AT+WIPCLOSE =2,1", NULL, NULL, NULL);
      //adl_fcmSwitchV24State(DataMeter_fcmHandle, ADL_FCM_V24_STATE_AT);
      meeterRead = true;
      AppInitMeter ( );

    } else {
      wip_debug( "[SAMPLE] Wrote %i bytes. "
                 "%i bytes left to send in snd_buffer\n",
                 nwrite, sizeof( snd_buffer) - snd_offset);
    }
    break;
  }
  case WIP_CEV_ERROR: {
    wip_debug( "[SAMPLE] Error %i on socket. Closing.\n",
               ev->content.error.errnum);
    wip_close( ev->channel);
    meeterRead = true;
    iscon = false;
    AppInitMeter (  );
    break;
  }
  case WIP_CEV_PEER_CLOSE: {
    wip_debug( "[SAMPLE] Connection closed by peer\n");
    wip_close( ev->channel);
    meeterRead = true;
    iscon = false;
    AppInitMeter (  );
    break;
  }
  }
 
}


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);
  iscon =TRUE;

  TRACE ((1, " wip_bearerSetOpts : %s %s %s", GPRS_APN, GPRS_USER,GPRS_PASSWORD));
  ASSERT_OK( r);
  r = wip_bearerStart( b);
  ASSERT( 0 == r || WIP_BERR_OK_INPROGRESS == r);
}


void appTimerhdlc(u8 TimerId)
{
	if (iscon == false )
	poll_creg();

}

////rssi handler 
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);//"+CSQ: 19,0" rsp[7],rsp[8]

    wm_strGetParameterString(regStateString, Rsp->StrData, 2);

    regStateInt = wm_atoi(regStateString);

    if (( *( rsp +6 ) == '1' )  ||  ( *( rsp +7 ) > '6 ')&&( *( rsp +6 ) == '2' )   )
    {
        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, appTimerhdlc);
    }
    return FALSE;
}


////checks the rssi 
void poll_creg( void ) {

	adl_atCmdCreate( "AT+CSQ", FALSE, poll_creg_callback, "*", NULL);
 
}


/////meter data hendler : reed data until METER_INPUT_BUFFER_SIZE.Get back to read after conection failed 

static bool DataMeter_data_handler(u16 datalength, u8 *data) {
	

	bool bReturnM = TRUE; /* Return value is always true to release the credits*/
      /* just dump into a buffer for later processing by the core */

	if ( meeterRead == true)
		if ((rx_bytes_ser_in + datalength) < METER_INPUT_BUFFER_SIZE)
		{
			wm_memcpy(&rx_met_buffer[rx_bytes_ser_in], data, datalength);
			rx_bytes_ser_in += datalength;
			 TRACE ((1, "DATAmeter Data Handler: %d %d", datalength, rx_bytes_ser_in));
		}
		else
			{
				//bReturnM = FALSE;
				meeterRead = false;
				rx_bytes_ser_in = 0;

				adl_fcmSwitchV24State(DataMeter_fcmHandle, ADL_FCM_V24_STATE_AT);

				adl_tmrSubscribe( FALSE, 60, ADL_TMR_TYPE_100MS, appTimerhdlc);

				TRACE ((1, "DATAmeter Data Handler: %d %d", datalength, rx_bytes_ser_in));
			}


    return bReturnM;

}

////meter control hendler 
static bool DataMeter_ctrl_handler(u8 event)
{
	TRACE((1, "DataMETER_ctrl_handler: %d", event));
	switch(event)
	{
		case ADL_FCM_EVENT_FLOW_OPENNED:
			/* Switch to data state */
			adl_fcmSwitchV24State(DataMeter_fcmHandle, ADL_FCM_V24_STATE_DATA);

		break;
		case ADL_FCM_EVENT_V24_DATA_MODE:
			TRACE((1, "ADL_FCM_EVENT_V24_DATA_MODE"));
			//adl_tmrSubscribe ( FALSE, 10, ADL_TMR_TYPE_100MS, GPIOInit );

		break;
		case ADL_FCM_EVENT_FLOW_CLOSED:
			TRACE((1, "ADL_FCM_EVENT_V24_AT_MODE"));
			adl_fcmSwitchV24State(DataMeter_fcmHandle, ADL_FCM_V24_STATE_AT);

	    break;
		
	}
	return TRUE;
}




///starts reading the meter data 

void AppInitMeter( void )
{


        TRACE (( 1, "Set Serial to preper Meter " ));
 
         if (( meeterRead == true)||(WIP_CEV_PEER_CLOSE)||(WIP_CEV_ERROR)){
        /* Open the Data FCM flow on the DATAGPS */
         DataMeter_fcmHandle = adl_fcmSubscribe(APP_METER_UART,
                                (adl_fcmCtrlHdlr_f)DataMeter_ctrl_handler,
                                (adl_fcmDataHdlr_f)DataMeter_data_handler);
         }
}



void adl_main ( adl_InitType_e InitType )
{

	int r;
 	 TRACE (( 1, "Embedded Application : Main" ));

   	 r = wip_netInitOpts( WIP_NET_OPT_DEBUG_PORT, WIP_NET_DEBUG_PORT_UART1,
           	          WIP_NET_OPT_END);

   	 AppInitMeter();
}

client_fcm_log_4_1_13.txt (6.77 KB)

Are you trying to coddect over GPRS?

Unless you have a proper M2M service which specifically allows it, most “consumer” services don’t allow incoming IP connections…

Can you please elaborate ? the SIW one’s has the incomming IP connection session(on the server side there should arrive some +WIPDATA: 2,1,1 events ) Any other recomendations?

Do you suggest writing an open at application that just uses the WIPsoft commands?

When using the WIP At commands, it is also necesery to open a GPRS bearer and this is what is done by the first open_and_start_bearer function.

Since i couldn’t find the issue that i had with my opean at code i have implemented that with an external mcu however it would be probably cheaper to eliminate the need for external by overcoming the issues that i had with the OpenAt environment and succeeding with this project , can you please advice regarding the failure that i still have ?

I eliminated the FCM mechanism and staid with the basic code where I am trying to send a string of bytes to a remote server once a minute , I use a timer subscribe function of 60x100msec that will reinitiate the poll_creg() procedure (check the RSSI to reinitiate the open_and_start_bearer(); procedure to open the socket to the server ) . I use breakpoints and placed a breakpoint just at the timer handler where it should reinitiate the procedure and it seems like the debbuger never gets back to this point since it is crushing once it gets to this point.
I was using timer unsubscribe function to release timer operation and this action didn’t helped a lot.
Would appreacate if you can look at the mechanisem that I use after case wip_cev_write ends seems like the issue begins when Applientermeter() starts

#if __OAT_API_VERSION__ >= 400
const u16 wm_apmCustomStackSize = 4096;
#else
u32 wm_apmCustomStack[1024];
const u16 wm_apmCustomStackSize = sizeof(wm_apmCustomStack);
#endif


// Sim Handler
void SimHandler( u8 event  )
{
    TRACE (( 1, "Inside SimHandler" ));
    switch(event)
    {
        /* Initialization complete, subscribe for -  */
        case  ADL_SIM_EVENT_FULL_INIT:
        {
           /* Subscribe to SMS service */
           TRACE (( 1, "Registered" ));

           AppInitMeter();
        }  // start GPS Circuit and check location
        break;
    }
}
static void evh_bearer( wip_bearer_t b, s8 event, void *ctx) {
  //if( WIP_BEV_IP_CONNECTED == event)
//  {
	  appli_entry_point();
//  }
}
void app_wip_Timerhd(u8 Id,void * Context)
{
	//adl_tmrUnSubscribe( tt2, app_wip_Timerhd ,ADL_TMR_TYPE_100MS );
	//if (iscon == false )


	appli_entry_point();

}
void appTimerhd_er(u8 Id,void * Context)
{


	//adl_tmrUnSubscribe( tt, appTimerhd_er ,ADL_TMR_TYPE_100MS );//t2
	poll_creg();
}
void appTimerhdlc(u8 Id,void * Context)
{
//		if (flag1)
//			flag1=0;
//		if (flag2)
//			flag2=0;
	//adl_tmrUnSubscribe( tt, appTimerhdlc ,ADL_TMR_TYPE_100MS );//t1

	if (iscon == false )
	poll_creg();

}

//bool Config_CMON_Handler4 ( adl_atResponse_t *paras )
//{
//    TRACE (( 1, "close keypad" ));
//    AppInitMeter();
//   return FALSE;
//}
static void open_and_start_bearer( void) {
  int r;
  wip_bearer_t b;
	//if (iscon == false ){
	  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);
	//}
  iscon = TRUE;

  TRACE ((1, " wip_bearerSetOpts : %s %s %s", GPRS_APN, GPRS_USER,GPRS_PASSWORD));
  //ASSERT_OK( r);
  r = wip_bearerStart( b);
  //ASSERT( 0 == r || WIP_BERR_OK_INPROGRESS == r);
}
static void evh( wip_event_t *ev, void *ctx) {
	//int r;
	//wip_bearer_t b;

  switch( ev->kind){

  case WIP_CEV_OPEN: {
    wip_debug ("[SAMPLE] Connection established successfully\n");
    //iscon = true;
    break;
  }
  case WIP_CEV_READ: {
    int nread;
    wip_debug ("[SAMPLE] Some data arrived\n");
    nread = wip_read( ev->channel, rcv_buffer + rcv_offset,
                      sizeof( rcv_buffer) - rcv_offset);
    if( nread < 0) { wip_debug( "[SAMPLE] read error %i\n", nread); return; }
    rcv_offset += nread;
    if( rcv_offset == sizeof( rcv_buffer)) {
      wip_debug( "[SAMPLE] Reception capacity exceeded, won't read more\n");
    } else {
      wip_debug( "[SAMPLE] Wrote %i bytes of data from network to rcv_buffer. "
                 "%i bytes remain available in rcv_buffer\n",
                 nread, sizeof( rcv_buffer) - rcv_offset);
    }

    break;
  }
  case WIP_CEV_WRITE: {
    int nwrite;
    wip_debug ("[SAMPLE] Can send more data\n");
    nwrite = wip_write( ev->channel, snd_buffer + snd_offset,
                        sizeof( snd_buffer) - snd_offset);
    if( nwrite < 0) { wip_debug( "[SAMPLE] write error %i\n", nwrite); return; }
    snd_offset += nwrite;
    if( snd_offset == sizeof( snd_buffer)) {
      wip_debug( "[SAMPLE] Everything has been sent, won't send more.\n");

      nwrite = wip_write( ev->channel, snd_buffer + snd_offset,
                              sizeof( snd_buffer) - snd_offset);
      wip_close( ev->channel);//wip_bearerClose( b );

      //adl_fcmSwitchV24State(DataMeter_fcmHandle, ADL_FCM_V24_STATE_AT);
      iscon = true;
      flag1=1;
     AppInitMeter();

      //tt2 = adl_tmrSubscribe( FALSE, 60, ADL_TMR_TYPE_100MS, appTimerhd_er);//t2
    } else {
      wip_debug( "[SAMPLE] Wrote %i bytes. "
                 "%i bytes left to send in snd_buffer\n",
                 nwrite, sizeof( snd_buffer) - snd_offset);
    }
    break;
  }
  case WIP_CEV_ERROR: {
    wip_debug( "[SAMPLE] Error %i on socket. Closing.\n",
               ev->content.error.errnum);
    wip_close( ev->channel);

    //wip_bearerClose( b );
    //CallMyHeavyTreatpments();
    //adl_atCmdCreate("AT+CFUN=1", false, Config_CMON_Handler4, "*",NULL);
   // meeterRead = true;
    iscon = false;
    flag2=0;
	 //tt2 = adl_tmrSubscribe( FALSE, 60, ADL_TMR_TYPE_100MS, appTimerhd_er);//t2
    AppInitMeter();
    break;
  }
  case WIP_CEV_PEER_CLOSE: {
    wip_debug( "[SAMPLE] Connection closed by peer\n");
    wip_close( ev->channel);

    //wip_bearerClose( b );
  //  adl_atCmdCreate("AT+CFUN=1", false, Config_CMON_Handler4, "*",NULL);
   // meeterRead = true;
   // iscon = false;
  // tt = adl_tmrSubscribe( FALSE, 60, ADL_TMR_TYPE_100MS, appTimerhd_er);
    AppInitMeter();
    break;
  }
  }
  //meeterRead = TRUE;
}

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);//"+CSQ: 19,0" rsp[7],rsp[8]

    wm_strGetParameterString(regStateString, Rsp->StrData, 2);
    regStateInt = wm_atoi(regStateString);

    if ((( *( rsp +6 ) == '1' )  && ( *( rsp +7 ) > '6')) || ( *( rsp +6 ) == '2' ))
    {
        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, 60, ADL_TMR_TYPE_100MS, appTimerhdlc);
    }
    return FALSE;
}


void poll_creg( void ) {

	adl_atCmdCreate( "AT+CSQ", FALSE, poll_creg_callback, "*", NULL);

}

void appli_entry_point() {
  wip_channel_t socket;
  wip_debug( "[SAMPLE]: connecting to client %s:%i...\n", PEER_STRADDR, PEER_PORT);
  socket = wip_TCPClientCreate( PEER_STRADDR, PEER_PORT, evh, NULL);
  iscon = true;
  if( ! socket) { wip_debug( "[SAMPLE] Can't connect\n"); return; }
}





void AppInitMeter( void )
{
	TRACE (( 1, "Set Serial to preper Meter " ));
	 adl_tmrSubscribe( false, 60, ADL_TMR_TYPE_100MS, appTimerhdlc);//t1
}



void adl_main ( adl_InitType_e InitType )
{
  int r;


  //adl_tmrSubscribe( true, 60, ADL_TMR_TYPE_100MS, app_wip_Timerhd);

  TRACE (( 1, "Embedded Application : Main" ));

  /* Initialize the stack */
  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);

  adl_simSubscribe(SimHandler, NULL);


//#endif
}

any posibale answers???

Why does a so called “open” forum charges any cost for resolving a minor problem???

Firstly, no one charges for answering questions. This is a free forum, so getting an answer is not guaranteed. If you have an urgent problem, you should contact your distributor.

Secondly, in the code you provided, you are polling the RSSI value, not the CREG value

adl_atCmdCreate( "AT+CSQ", FALSE, poll_creg_callback, "*", NULL);

The CSQ value will always return a number regardless of whether or not you are connected to the network. You should be sending AT+CREG? and looking for the network registration indication not the received signal strength value. Your connection is probably failing because you are trying to connect to GPRS without a valid GSM network registration.