Not able to recreate TCP Socket Connection

I am using Sierra Wireless Fastrack XTend programmable Gateway (FXT009) to send data to web periodically.

I am facing an issue where i am not able to reconnect the TCP Connection whenever the socket connection closes down. I have observed that sometimes the connection closes down automatically after it is opened. Once it is closed, I am not able to reopen it successfully as the WIP Event Handler function is not getting invoked.

Here is the snippet of code that I am using

Firstly I am setting up the TCP Connection under Main() as below. I want to write some data later when the need arises based on some field operations.

bool ChannelStatus = FALSE; // To see status of the socket connection
void main_task(void)
{
   ...

   // TCP Initialisation Action Starts by initialising the NET stack
   ret = wip_netInit();
   if (OK == ret)
   {
      TRACE((GW_TCPTASK_TRACEID, "wip_netInit() Successful!"));
      CfgGprs(AppliEntryPoint);
   }
}

The above initialization part is as taken from one of the samples from Developer Studio

Under AppliEntryPoint function as below,

void AppliEntryPoint(void)
{
   socket = wip_TCPClientCreate(TCP_PEER_STRADDR, TCP_PEER_PORT, cbevh, NULL);
   if(socket != NULL)
   {
      SocketRetries = 0;
      TRACE((NORMAL_TRACE_LEVEL, "[AppliEntryPoint] Socket Connection Successful!"));
   }
}

I get all the right messages as below.
TRACE((NORMAL_TRACE_LEVEL, “[AppliEntryPoint] Socket Connection Successful!”));

The wip_eventHandler_f function is also successfully invoked as seen in the code snippet below

static void cbevh (wip_event_t *ev, void *ctx)
{
   // Go to different routines based on WIP Events
   switch(ev->kind)
   {
      case WIP_CEV_OPEN:
      {
         TRACE((NORMAL_TRACE_LEVEL, "[WIP Event Handler] Connection established successfully"));
         ChannelStatus = TRUE;
         break;
      }

      case WIP_CEV_WRITE:
      {
         ...
         break;
      }
      
      case WIP_CEV_READ:
      {
         ...
         break;
      }
      
      case WIP_CEV_ERROR:
      {
         TRACE((ERROR_TRACE_LEVEL, "[WIP Event Handler] Error %i on socket! So Closing...", ev-content.error.errnum));
         wip_close(ev->channel);
         ChannelStatus = FALSE;
         break;
      }

      case WIP_CEV_PEER_CLOSE:
      {
         TRACE ((NORMAL_TRACE_LEVEL, "[WIP Event Handler] Connection will be closed by peer now..."));
         wip_close(ev->channel);
         ChannelStatus = FALSE;
         break;
      }
}

TRACE((NORMAL_TRACE_LEVEL, “[WIP Event Handler] Connection established successfully”));

Now I can write the data successfully and Read the Response as well. The Socket Connection then closes.

The real issue is when I have to send the data again. I am not able to reopen it successfully as the WIP Event Handler function is not getting invoked at all.

I am using the function as below to recreate the connection when the need to send data to web again:

void SendWebPacket(void)
{
   ...
   if(ChannelStatus != TRUE)
   {
      AppliEntryPoint();
   }
   else
   {
      TRACE((NORMAL_TRACE_LEVEL, "TCP Connection already exists..."));
      write = wip_write(socket, TCPGatewayByteStream, sizeof(TCPGatewayByteStream));
   }
}

I am able to get into AppliEntryPoint function, I get all the right messages as below.
TRACE((NORMAL_TRACE_LEVEL, “[AppliEntryPoint] Socket Connection Successful!”));

But the wip_eventHandler_f function is not invoked.

Any help on this is appreciated.

Thanks
Sathya

I believe I have fixed the issue.

I was doing a simple post back activity where I would just post the data I get on the serial port to Web. The call to ‘AppliEntryPoint’ function did not work as it was being called from the Low Lever Interrupt Handler function.

Putting it outside of the function made it work.

Thanks,
Sathya