Post a new topicPost a reply Page 1 of 2   [ 13 posts ]
Go to page 1, 2  Next
Author Message
 Post subject: Unresponsive GPRS modem
PostPosted: Mon Feb 06, 2012 1:36 am 

Joined: Mon Jul 11, 2011 3:15 am
Posts: 78
Hey guys,

I'm writing to query about the functionality of the GPRS modem. The modems I had shipped are the Sagemcom MODULE HILO and they came with version HiC,A.009.00 of firmware flashed on to them.

They have now become the bottleneck of the system I've set up which involves opening a tcp socket connection, sending data over this socket, receiving, sending again and receiving again. It follows this sequence every minute in which it will repeat the sequence 1 to 2 times (depending on the states of other nodes in the system).

After some time, the modem will either start failing to receive anything over this socket, in which case, the socket is reconnected to (which seems to resolve any problems half of the time) or the modem will stop responding to any commands at all. When the modem stops responding, the mote will generally wait for the watchdog to kick in and have the system reboot. Even after having reboot, the modem will still not respond to command for some time.

I've also spent a fair few hours trying to upgrade the firmware (although software release notes don't seem to address the problem I'm having) as documented on these forums with no luck of receiving any response from the AT command sent

Is there anything anybody could suggest which could help resolve the issue I'm having with these unresponsive modems?


Top
 Profile  
 
 Post subject: Re: Unresponsive GPRS modem
PostPosted: Tue Feb 07, 2012 9:34 am 

Joined: Mon Sep 28, 2009 1:06 pm
Posts: 7516
Dear yoshi_jd,

Can you post the part of the code that manages GPRS?

One tip: When you open sockets it is necessary also to close it with

GPRS.closeSocket(GPRS.socket_ID);
GPRS.deleteSocket(GPRS.socket_ID);


Try adding this lines also to your code.

We will wait your comments.

Regards!


Top
 Profile  
 
 Post subject: Re: Unresponsive GPRS modem
PostPosted: Wed Feb 08, 2012 3:33 am 

Joined: Mon Jul 11, 2011 3:15 am
Posts: 78
Currently GPRS code is as follows -

definitions and global variables :

Code:
#define   AT_GPRS_APN          "vfinternet.au"
#define   AT_GPRS_LOGIN       "guest"
#define   AT_GPRS_PASSW       "guest"
#define DEST_IP               "203.34.52.61"
#define DEST_PORT            "80"
#define GPRS_CLIENT         0
#define BUF_SZ                  100
#define ID_SZ                  12            // size of the id string
#define NUM_SLAVES            5
#define GPRS_MSG_CONT      "HTTP/1.1 100 Continue"
#define   GPRS_MSG_OK         "HTTP/1.1 200 OK"
#define MAX_LINES            300

typedef struct
{
   char id[ID_SZ];
   uint16_t lines;
} sd_t;

uint8_t storedNodeCount=0;
sd_t storedNode[NUM_SLAVES];


initialisation run before main loop :

Code:
void GPRS_Init()
{
   uint8_t bSuccess = 0;

   USB.print( "GPRS init.." );

   // opens UART1 and powers the GPRS module ( performs begin() sequence )
   GPRS.ON();

   if(!GPRS.check())
   {
      PWR.reboot();
   }
   USB.print( "connected.." );

   bSuccess |= GPRS.configureGPRS();

   if( GPRS.flag != 0 )
   {
      USB.print( "error " );
      USB.print( GPRS.flag );
      USB.println( " communicating with module" );

      PWR.reboot();
   }
   Output_Update();

   delay(2000);

   bSuccess |= GPRS.createSocket( DEST_IP, DEST_PORT, GPRS_CLIENT );      // web service
   Output_Update();

   USB.println( bSuccess?"OK":"FAIL" );

   if( bSuccess == 0 )
   {
      PWR.reboot();
   }
}


run in main loop :

Code:
void GPRS_Process_Send2Server()
{
   static volatile uint16_t GPRS_Timer = 0;
   int8_t bSuccess = 0;
   char* buffer;
   char buf[350];
   static uint8_t GPRSState = 0;
   static uint8_t SDState = 0;
   uint8_t i, iRetVal;
   static uint8_t rxCounter = 0;
   static uint8_t flagRefresh = FALSE, flagFirstTime = TRUE, flagExit = FALSE;
   static uint16_t DELAY_Timer = 0;
   static uint16_t length = 0;
   char string[5];
   static uint8_t iNodeIndex = 0;

   switch( SDState )
   {
   case( 0 ):
      if( flagFirstTime )
      {
         USB.println( "count nodes " );
         getNodesToUpload( FALSE );
         flagFirstTime = FALSE;
         USB.println( storedNodeCount, DEC );
         if( storedNodeCount > 0 )
         {
            // initialise variables
            flagExit = FALSE;
            length = 0;
            // get a line count of data for each node
            memset( filename, 0x00, ID_SZ+12 );
            iNodeIndex = storedNodeCount - 1;
            for( i=0; i<storedNodeCount; i++ )
            {
               snprintf( filename, ID_SZ+12, "datalog%s.csv", storedNode[i].id );
               storedNode[i].lines = SD.numln( filename );
               if( ( (storedNode[i].lines - 1) == 0 ) || ( (storedNode[i].lines - 1) >= MAX_LINES ) )
               {
                  //USB.println( "error reading" );
                  //i--;
               }
            }
            GPRS_Timer = millis();
            SDState = 1;
            GPRSState = 0;
            DELAY_Timer = millis();
         }
         else
         {
            flagExit = TRUE;
         }
      }
      else if( flagRefresh )
      {
         getNodesToUpload( TRUE );
      }
      else
      {
         flagExit = TRUE;
      }
      break;

   case( 1 ):
      switch( GPRSState )
      {
      case( 0 ) :
         if( iNodeIndex >= 0 )
         {            
            if( Timer_PassedDelay( DELAY_Timer, 2000 ) )      // delay of 2 seconds
            {
               memset( filename, 0x00, ID_SZ+12 );
               length = 0;
               snprintf( filename, ID_SZ+12, "datalog%s.csv", storedNode[iNodeIndex].id );
               if( ( (storedNode[iNodeIndex].lines - 1) == 0 ) || ( (storedNode[iNodeIndex].lines - 1) >= MAX_LINES ) )
               {
                  //USB.println( "error reading" );
                  //i--;
               }
               else
               {
                  buffer = SD.catln( filename, storedNode[iNodeIndex].lines, 1 );
                  length = strlen( buffer );
               }
               
               if( length == 0 || length > BUF_SZ-1 )
               {
                  flagExit = TRUE;
               }
               else
               {
                  snprintf( string, 5, "%u", length );
                  snprintf( buf, 350, "%s%s%s%s%s%s%s%s",
                     "POST /WebReceiver.svc HTTP/1.1\r\n",
                     "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client Protocol 4.0.30319.239)\r\n",
                     "Content-Type: text/xml; charset=utf-8\r\n",
                     "SOAPAction: \"http://tempuri.org/IWebReceiver/UploadInformation\"\r\n",
                     "Host: web.name.com\r\n",
                     "Content-Length: ",
                     string,
                     "\r\nExpect: 100-continue\r\n\r\n" );            
                  if( !( GPRS.sendData( buf, GPRS.socket_ID ) ) )
                  {
                     //GPRS_Reconnect();
                     GPRS.OFF();
                     delay( 2000 );
                     GPRS.ON();
                     rxCounter = 0;
                     SDState = 0;               // start at SDState 1 to prevent resending data - starts at the line at which gprs was failing
                     GPRSState = 0;
                  }
                  else
                  {
                     GPRSState++;
                  }
                  DELAY_Timer = millis();
               }
            }
         }
         break;

      case( 1 ) :
         bSuccess=0;
         if( Timer_PassedDelay( DELAY_Timer, 2000) )      // delay of 2 seconds
         {
            memset(GPRS.data_URL, 0, 100);
            while( !bSuccess )
            {
               bSuccess = GPRS.readData( GPRS.socket_ID, "90" );   // delays occurring here
            }
            USB.print( "GPRS: RX1->" );
            USB.println( GPRS.data_URL );
            if( isEqual( GPRS.data_URL, GPRS_MSG_CONT, strlen(GPRS_MSG_CONT) ) )
            {
               GPRSState = 2;
            }
            else
            {
               // still waiting for the Continue message
               rxCounter++;
               GPRSState = 1;
            }
            DELAY_Timer = millis();
         }
         break;

      case( 2 ) :
            if( Timer_PassedDelay( DELAY_Timer, 3000) )      // delay of 3 seconds
            {
               memset( filename, 0x00, ID_SZ+12 );
               snprintf( filename, ID_SZ+12, "datalog%s.csv", storedNode[iNodeIndex].id );
               USB.println( filename );
               if( ( (storedNode[iNodeIndex].lines - 1) == 0 ) || ( (storedNode[iNodeIndex].lines - 1) >= MAX_LINES ) )
               {
                  //USB.println( "error reading" );
                  //i--;
               }
               else
               {
                  snprintf( filename, ID_SZ+12, "datalog%s.csv", storedNode[iNodeIndex].id );
                  buffer = SD.catln( filename, storedNode[iNodeIndex].lines, 1 );
                  // checks for error on line
                  if( strlen( buffer ) > BUF_SZ-1 )
                  {
                     //USB.println( "error on line" );
                     //i--;
                  }
                  else
                  {
                     snprintf( buf, BUF_SZ, "%s", buffer );
                     if( storedNodeCount==1 )
                     {
                        iRetVal = GPRS.sendData( buf, GPRS.socket_ID );
                     }
                     if( !iRetVal )
                     {
                        //GPRS_Reconnect();
                        GPRS.OFF();
                        delay( 2000 );
                        GPRS.ON();
                        rxCounter = 0;
                        SDState = 0;
                        GPRSState = 0;
                        break;
                     }
                  }
               }
               GPRSState++;
               rxCounter = 0;
               DELAY_Timer = millis();
            }
            break;

      case( 3 ) :
         bSuccess = 0;
         if( Timer_PassedDelay( DELAY_Timer, 2000) )      // delay of 2 seconds
         {
            memset(GPRS.data_URL, 0, 100);
            while( !bSuccess )
            {
               bSuccess = GPRS.readData( GPRS.socket_ID, "90" );
            }
            USB.print( "GPRS: RX2->" );
            USB.println( GPRS.data_URL );
            if( isEqual( GPRS.data_URL, GPRS_MSG_OK, strlen(GPRS_MSG_OK) ) )
            {
               GPRSState++;
            }
            else
            {
               // still waiting for ok message
               rxCounter++;
               GPRSState = 3;
            }
            DELAY_Timer = millis();
         }
         break;

      case( 4 ) :
         // decrement line count
         storedNode[iNodeIndex].lines--;
         if( (storedNode[iNodeIndex].lines-1) == 0 || (storedNode[iNodeIndex].lines-1) > MAX_LINES )
         {
            // no more lines to upload, delete the file
            snprintf( filename, ID_SZ+12, "datalog%s.csv", storedNode[iNodeIndex].id );
            SD.del( filename );
            // must raise flag to refresh node count
            iNodeIndex--;
         }
         SDState = 0;
         GPRSState = 0;
         XBee.print( "GPRS: Time taken " );
         XBee.println( (int)(millis() - GPRS_Timer) );
         rxCounter = 0;
         serialFlush(PORT_USED);
         DELAY_Timer = millis();
         break;
      }
      break;
   }

   if( flagExit )
   {
      flagFirstTime = TRUE;
      flagSend2Server = FALSE;
      flagExit = FALSE;
   }
   else if( rxCounter >= MAX_RX_CNT )
   {
      //GPRS_Reconnect();
      GPRS.OFF();
      delay( 2000 );
      GPRS.ON();
      rxCounter = 0;
      SDState = 0;               // start at SDState 1 to prevent resending data - starts at the line at which gprs was failing
      GPRSState = 0;
   }
}

bool isEqual( char a[], char b[], uint8_t size )
{
   uint8_t i;
   for( i=0; i<size; i++ )
   {
      if( a[i] != b[i] )
      {
         return FALSE;
      }
   }
   return TRUE;
}

void getNodesToUpload( bool keepLines )
{
   char* buffer;
   uint8_t i, j=0;
   buffer = SD.ls(0,0,NAMES);
   char tempID[ID_SZ];
   uint8_t tempStoredNodeCount = storedNodeCount;
   sd_t tempStoredNode[storedNodeCount];
   if( keepLines )
   {
      memcpy( tempStoredNode, storedNode, sizeof(sd_t)*storedNodeCount );
      memset( storedNode, 0x00, sizeof(sd_t)*NUM_SLAVES );
   }
   storedNodeCount = 0;
   while( buffer[j] != '\0' )
   {
      if( buffer[j] == 'd' )
      {
         if( buffer[j+1] == 'a' )
         {
            if( buffer[j+2] == 't' )
            {
               if( buffer[j+3] == 'a' )
               {
                  if( buffer[j+4] == 'l' )
                  {
                     if( buffer[j+5] == 'o' )
                     {
                        if( buffer[j+6] == 'g' )
                        {
                           for( i=0; i<ID_SZ-1; i++ )
                           {
                              tempID[i] = buffer[j+7+i];
                           }
                           tempID[ID_SZ-1] = '\0';
                           memcpy( storedNode[storedNodeCount].id, tempID, ID_SZ );
                           if( keepLines )
                           {
                              for( i=0; i<tempStoredNodeCount; i++ )
                              {
                                 if( strcmp( storedNode[storedNodeCount].id, tempStoredNode[i].id ) == 0 )
                                 {
                                    storedNode[storedNodeCount].lines = tempStoredNode[i].lines;
                                 }
                              }
                           }
                           storedNodeCount++;
                        }
                     }
                  }
               }
            }
         }
      }
      j++;
   }
}

uint8_t Timer_PassedDelay( uint16_t startTime, uint16_t msDelay )
{
   uint16_t stoptime = startTime+msDelay;
   uint16_t curtime = millis();
   if(stoptime >= startTime)
   {
      if((curtime >= stoptime) || (curtime < startTime))
         return TRUE;
      else
         return FALSE;
   } else {
      if((curtime > stoptime) && (curtime < startTime))
         return TRUE;
      else
         return FALSE;
   }
}


I think I've included everything of importance. Let me know if there are any queries. I'll see if your suggestion of closing and deleting sockets helps.


Top
 Profile  
 
 Post subject: Re: Unresponsive GPRS modem
PostPosted: Wed Feb 08, 2012 4:12 am 

Joined: Mon Jul 11, 2011 3:15 am
Posts: 78
You may notice some lines throughout the included code being commented out, in particular GPRS_Reconnect();

This involved:

Code:
void GPRS_Reconnect()
{
   uint8_t bSuccess = 0;
   uint8_t reconnCount = 0;
   uint8_t closeCount = 0;
   uint8_t deleteCount = 0;

   while( bSuccess == 0 )
   {
      USB.println( "GPRS: closing socket" );
      delay( 2000 );
      if( GPRS.closeSocket( GPRS.socket_ID ) )
      {
         USB.println( "GPRS: deleting socket" );
         delay( 2000 );
         if( GPRS.deleteSocket( GPRS.socket_ID ) )
         {
            USB.print( "GPRS: reconnecting.." );
            delay( 2000 );
            bSuccess = GPRS.createSocket( DEST_IP, DEST_PORT, GPRS_CLIENT );      // web service
            USB.println( bSuccess?"OK":"FAIL" );
            reconnCount++;
         }
         else
         {
            deleteCount++;
         }
      }
      else
      {
         closeCount++;
      }

      if( closeCount > 9 || deleteCount > 4 || reconnCount > 4 )
      {
         PWR.reboot();
      }
   }
}


However, the inclusion of this function did not seem to make any improvements.


Top
 Profile  
 
 Post subject: Re: Unresponsive GPRS modem
PostPosted: Wed Feb 08, 2012 9:44 am 

Joined: Mon Sep 28, 2009 1:06 pm
Posts: 7516
yoshi_jd,

Due to your code is large, we will analyse it but it will take some time.

Apart of this, please read about one feature of IDE:

One feature of the Wasp IDE is to copy sketch code with colours, posting it in a more clean way. Just instead of normal copy, try using edit/Copy for Forum.. It will show your code cleaner for us and for other readers. We recommend it particularly for large codes.

We will be back to you ASAP.

Regards.


Top
 Profile  
 
 Post subject: Re: Unresponsive GPRS modem
PostPosted: Wed Feb 08, 2012 3:37 pm 

Joined: Mon Jul 11, 2011 3:15 am
Posts: 78
I wasn't aware of this, thank you. :)


Top
 Profile  
 
 Post subject: Re: Unresponsive GPRS modem
PostPosted: Thu Feb 09, 2012 3:46 pm 

Joined: Mon Sep 28, 2009 1:06 pm
Posts: 7516
yoshi_jd,

Due to your code is to large to know exactly where could be the problem, we are giving you some tips. try them and let us know ok?

Let's see.

We do not know the general purposes of your code but, what if instead of configuring GPRS at the beginning, you just do first all your stuff, and when it is done, the turn on GPRS, send data and turn off again.

Appart of that, with the instruction Utils.setMuxGPS(); you manage analogue power switches and also ensures removing power of gprs. Test it, maybe it helps.

Another tip, the amount of opened sockets is limited (near 200, i do not remember right now), try to print socket_ID to see if this number is increasing. how where closesocket and deletesocket functions? no effect?

Last tip, please try to find where exactly your code is stuck to make easier locate what is going on.

Regards.


Top
 Profile  
 
 Post subject: Re: Unresponsive GPRS modem
PostPosted: Fri Feb 10, 2012 2:57 am 

Joined: Mon Jul 11, 2011 3:15 am
Posts: 78
I haven't had any improvements with the close and deleting of sockets though I'll definitely keep it in mind.

I'll try your other suggestions throughout the next couple of days and see how things progress - I'll keep you posted.


Top
 Profile  
 
 Post subject: Re: Unresponsive GPRS modem
PostPosted: Fri Feb 10, 2012 4:21 am 

Joined: Mon Jul 11, 2011 3:15 am
Posts: 78
By Utils.setMuxGPS(); are you actually referring to Utils.setMuxGPRS();? I assume you are.

Even still, I've placed GPRS.OFF(); at the beginning of each GPRS_Init(); that is called and this ends up calling Utils.setMuxGPRS();


Top
 Profile  
 
 Post subject: Re: Unresponsive GPRS modem
PostPosted: Fri Feb 10, 2012 10:44 am 

Joined: Mon Sep 28, 2009 1:06 pm
Posts: 7516
yoshi_jd,

Quote:
are you actually referring to Utils.setMuxGPRS();?


Actually no. I told you to use that to ensure GPRS is disable by hardware. So if you use Utils.setMuxGPS(); you are removing power from GPRS by choosing other multiplexor output.

Check this function in Wasputils.cpp


Tell us how is your code working.

Regards


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 2   [ 13 posts ]
Go to page 1, 2  Next


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Libelium theme based on 610nm Style by Daniel St. Jules of http://www.gamexe.net


© Libelium Comunicaciones Distribuidas S.L. | Terms of use