Post a new topicPost a reply Page 1 of 2   [ 12 posts ]
Go to page 1, 2  Next
Author Message
 Post subject: GPRS, configuring & connecting...
PostPosted: Thu Mar 15, 2012 2:07 pm 

Joined: Fri Nov 25, 2011 2:28 pm
Posts: 62
Hello everyone,

I've been using the waspmote GPRS module for SMS & FTP for some time now and have
noticed a recurring issue that threatens the viability of the networks I intend to utilize & create.

I'm using vodafone Telemetry SIMs, and my issue is characterized by peroids of difficulty connecting to the network, often attempting to join forever, staying in the infinite loop:
Quote:
  while(!GPRS.check());
  USB.println("GPRS connected to the network");


<<Note: I have a non-infinite loop work around (calling GPRS.check 2 - 3 times, then timing out) that allows for difficulty in association, but only lessens the symptoms - not helping the root cause.>>

The periods of difficulty in question can last from hours to days, with the exact same module, mote SIM and sketch (and APN etc. in GPRSconstants.h) failing to associate for several hours, then apparently without change being able to associate and send messages perfectly.

When The issue occurs I upload default (i.e. example) code, only editing the phone number, and it is usually no more successful than my own GPRS code. I have tried different motes, GPRS modules, SIMs and API versions (.21 & .23) and the result is the same.

I would greatly appreciate any hints towards debugging / testing the modules.
I am investigating the ISP side, as I am aware they can have issues, either in provisioning
or disseminating essential parameters.

Thanks.


Top
 Profile  
 
 Post subject: Re: GPRS, configuring & connecting...
PostPosted: Mon Mar 19, 2012 10:07 am 

Joined: Mon Sep 28, 2009 1:06 pm
Posts: 7455
LiamatTitan,

First of all, We apologize for delay answering.

Regarding your issue, the network provider is also involved, so let's write down some tips to improve GPRS operation. However, let us say that GPRS coverage can be low and this can be one of the causes of the problem.

LiamatTitan wrote:
<<Note: I have a non-infinite loop work around (calling GPRS.check 2 - 3 times, then timing out)..
That is a good practice to avoid code hanging in this line.

Regarding your operator, you should modify WaspGPRSConstants.h with corresponding APN, etc. for your operator.

We suppose you have already tested SMS and making lost call examples successfully (with battery and GPRS antenna always connected).

Also you can use next lines after using GPRS, but do not forget to turn GPRS On when using it again.
GPRS.OFF();
Utils.setMuxGPS();


Moreover, if you are using TCP sockets it is recommended to close and delete sockets after using them by:
GPRS.closeSocket(GPRS.socket_ID);
GPRS.deleteSocket(GPRS.socket_ID);


Hope this tips can help you to improve GPRS behaviour.

Let us know your comments.

Regards.


Top
 Profile  
 
 Post subject: Re: GPRS, configuring & connecting...
PostPosted: Tue Mar 20, 2012 1:07 pm 

Joined: Fri Nov 25, 2011 2:28 pm
Posts: 62
Hello again,

Thanks for the advice, I've already made SMS & lost call tests successfully,
both with the example code and my own "sendSMS(char*)" functions.

Below is the sketch I'm using to combine ZB and GPRS, on a waspmote with a Coordinator ZB module, which when it recieves a packet sends the contents as an SMS (using a function I have previously tested).

I'm using the LED patterns to observe the flow of control - So far I have found the packets (ZB) are sent / recieved reliably, however when the sendSMS(char*) function is called the GPRS module times out and does not associate with the network.

I originally tested code similar to this (minus the SMS components) successfully, then added the aforementioned SMS function. This new code (Identical to that posted below) associated with the network and transmitted SMS successfully as soon as I uploaded it. When I tested slightly different versions of the code the now all too familiar timeouts returned, and switching back to the original sketch hasn't fixed this.

I have had successful GPRS associations and SMS transmissions with a sendSMS(char*) function call in the setup part of the sketch - however this is not the functionality I need to achieve.


Quote:
#define MAX_TRIES 2

packetXBee* paq_sent; 
int8_t state=0; 
long previous=0;
char aux[200];
char recievedBody[100];
char* macHigh=" ";
char* macLow=" ";
int aux_1 = 0;
int aux_2 = 0;

uint8_t timeout = 0;

#define key_access "LIBELIUM"

uint8_t direccion[8]={0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF};
uint8_t macA[8]={0x00,0x13,0xA2,0x00,0x40,0x65,0x02,0xAA};
//0013A200406502AA

void setup(){

  // Store key access in EEPROM
  for(int i=0;i<8;i++){
    Utils.writeEEPROM(i+107,key_access[i]);
  }

  RTC.ON();
  
  ACC.ON();
  
  XBee.setMode(XBEE_ON);
  XBee.begin(9600);
  delay(1000);
  XBee.print("+++");
  delay(2000);
  XBee.println("ATBD5,AP2,WR,CN");
  delay(150);
  
  XBee.setMode(XBEE_OFF);
  XBee.close();
    
  Utils.setLED(LED0, LED_ON);
  Utils.setLED(LED1, LED_ON);
  delay(5000);
  Utils.setLED(LED0, LED_OFF);
  Utils.setLED(LED1, LED_OFF);
  for (int i=0;i<24;i++){
    Utils.blinkLEDs(125);
  }
  
  // Inits the XBee XSC library
  xbeeZB.init(ZIGBEE,FREQ2_4G,NORMAL);
 
  // Powers XBee
  xbeeZB.ON();
  
  // Get the XBee MAC address

  delay(500);
  
  int counter = 0;
  while(xbeeZB.getOwnMac()==1&&counter<4){
    xbeeZB.getOwnMac();
    counter++;
  }
  
  Utils.hex2str(xbeeZB.sourceMacHigh,macHigh,4);
  Utils.hex2str(xbeeZB.sourceMacLow,macLow,4);
  

}

void loop(){
     for(uint8_t i = 0;i<2;i++){
        Utils.blinkLEDs(100);
     }
     //previous=millis();
     //while( (millis()-previous) < 20000 )
     //{
       if( XBee.available() )
       {
           xbeeZB.treatData(); 
           if( !xbeeZB.error_RX )
           { 
             
              while(xbeeZB.pos>0)
              {
                  //xbeeZB.packet_finished[xbeeZB.pos-1]->data;
                  sprintf(aux,"B(%u)[[[%s]]]\n",PWR.getBatteryLevel(),xbeeZB.packet_finished[xbeeZB.pos-1]->data);
                  //sendSMS(aux);
                  paq_sent=(packetXBee*) calloc(1,sizeof(packetXBee)); 
                  paq_sent->mode=UNICAST; 
                  paq_sent->MY_known=0; 
                  paq_sent->packetID=0x52; 
                  paq_sent->opt=0; 
                  xbeeZB.hops=0; 
                  xbeeZB.setOriginParams(paq_sent,MAC_TYPE); 
                  //xbeeZB.setDestinationParams(paq_sent, direccion, aux, MAC_TYPE, DATA_ABSOLUTE);
                  xbeeZB.setDestinationParams(paq_sent, macA, aux, MAC_TYPE, DATA_ABSOLUTE);
                  xbeeZB.sendXBee(paq_sent); 
                  
                  free(paq_sent);
                  paq_sent = NULL;
                  
                  free(xbeeZB.packet_finished[xbeeZB.pos-1]); 
                  xbeeZB.packet_finished[xbeeZB.pos-1]=NULL; 
                  xbeeZB.pos--; 
                  
                  sendSMS(aux);
                  
              }      
           }
       }
    //}
  //delay(500);
}

void sendSMS(char*){ //subfn to send SMS with message body as argument
  GPRS.begin();
  GPRS.setMode(GPRS_ON);

  //waiting while GPRS connects to the network
   while((timeout<MAX_TRIES)&&(!GPRS.check())){ //while in time and not connected...
    USB.print("timeout = ");
    USB.println(timeout,DEC);
    timeout++;
  }
  timeout = 0;
  
  if(GPRS.check()){

  //configure SMS and Incoming calls
    GPRS.setInfoIncomingCall();
    GPRS.setInfoIncomingSMS();
    GPRS.setTextModeSMS();

  // Sending test SMS
    GPRS.sendSMS(aux,"087*******"); //phone no.
    GPRS.setMode(GPRS_HIBERNATE);
  }
  else{
    GPRS.setMode(GPRS_HIBERNATE);
    for(uint8_t i = 0;i<10;i++){
        Utils.blinkLEDs(1000);
    }
  }
}





As always your help and advice in resolving this issue would be very welcome.
Thanks.

PS. I am using the same SIM, APN & GPRS module + antenna for the combined GPRS & ZB and the GPRS standalone tests.


Top
 Profile  
 
 Post subject: Re: GPRS, configuring & connecting...
PostPosted: Tue Mar 20, 2012 2:43 pm 

Joined: Mon Sep 28, 2009 1:06 pm
Posts: 7455
LiamatTitan,

Thanks for explain so clear your application. Now we can understand what you are trying to achieve.

let's focus into code:

Why are you using GPRS.begin() and GPRS.setmode() instead of GPRS.ON()? are you using an old API version? Take a look inside GPRS.ON() on API 0.23, it also do some necessary stuff to avoid RTC conflicts.

Moreover, take into account maximum length for an SMS is 90 bytes (90 characters), maybe you are trying to send a bigger SMS. Take a look into page 7 of GPRS programming guide.

Also read pag 9 if you are planning to use Hibernate modes.

Last thing, did you try to turn off Xbee before sending an SMS? GPRS requires high current spikes and it is better if GPRS does not share battery with other modules at same time.

Let us know your comments.

Regards.


Top
 Profile  
 
 Post subject: Re: GPRS, configuring & connecting...
PostPosted: Tue Mar 20, 2012 4:33 pm 

Joined: Fri Nov 25, 2011 2:28 pm
Posts: 62
Hey, thanks for the swift reply,

I've been using api v0.23 for some time now, but I suspect the sendSMS function was initially composed for v0.21.

I've checked the SMS message body length, and for these tests it's 20 or less chars.

I've edited the code for the ZB power modes to ensure it isn't on when the GPRS module is trying to associate with the network.


Quote:
#define MAX_TRIES 2

packetXBee* paq_sent; 
int8_t state=0; 
long previous=0;
char aux[200];
char recievedBody[100];
char* macHigh=" ";
char* macLow=" ";
int aux_1 = 0;
int aux_2 = 0;

uint8_t timeout = 0;

#define key_access "LIBELIUM"

uint8_t direccion[8]={0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF};
uint8_t macA[8]={0x00,0x13,0xA2,0x00,0x40,0x65,0x02,0xAA};
//0013A200406502AA

void setup(){

  // Store key access in EEPROM
  for(int i=0;i<8;i++){
    Utils.writeEEPROM(i+107,key_access[i]);
  }

  RTC.ON();
  
  ACC.ON();
  
  XBee.setMode(XBEE_ON);
  XBee.begin(9600);
  delay(1000);
  XBee.print("+++");
  delay(2000);
  XBee.println("ATBD5,AP2,WR,CN");
  delay(150);
  
  XBee.setMode(XBEE_OFF);
  XBee.close();
    
  Utils.setLED(LED0, LED_ON);
  Utils.setLED(LED1, LED_ON);
  delay(5000);
  Utils.setLED(LED0, LED_OFF);
  Utils.setLED(LED1, LED_OFF);
  for (int i=0;i<24;i++){
    Utils.blinkLEDs(125);
  }
  
  //sendSMS(aux); //connect ok
  
  // Inits the XBee XSC library
  xbeeZB.init(ZIGBEE,FREQ2_4G,NORMAL);
 
  // Powers XBee
  xbeeZB.ON();
  
  // Get the XBee MAC address
  
  delay(500);
  
  //sendSMS(aux); //connect ok
  
  int counter = 0;
  while(xbeeZB.getOwnMac()==1&&counter<4){
    xbeeZB.getOwnMac();
    counter++;
  }
  
  Utils.hex2str(xbeeZB.sourceMacHigh,macHigh,4);
  Utils.hex2str(xbeeZB.sourceMacLow,macLow,4);
 
  //sendSMS(aux); //connect ok
}

void loop(){
     for(uint8_t i = 0;i<2;i++){
        Utils.blinkLEDs(100);
     }
     //sendSMS(aux); //connect timeout
     //previous=millis();
     //while( (millis()-previous) < 20000 )
     //{
       if( XBee.available() )
       {
           //sendSMS(aux); //connect timeout
           xbeeZB.treatData(); 
           if( !xbeeZB.error_RX )
           { 
             
              while(xbeeZB.pos>0)
              {
                  //xbeeZB.packet_finished[xbeeZB.pos-1]->data;
                  sprintf(aux,"B(%u)[[[%s]]]\n",PWR.getBatteryLevel(),xbeeZB.packet_finished[xbeeZB.pos-1]->data);
                  //sendSMS(aux);
                  paq_sent=(packetXBee*) calloc(1,sizeof(packetXBee)); 
                  paq_sent->mode=UNICAST; 
                  paq_sent->MY_known=0; 
                  paq_sent->packetID=0x52; 
                  paq_sent->opt=0; 
                  xbeeZB.hops=0; 
                  xbeeZB.setOriginParams(paq_sent,MAC_TYPE); 
                  //xbeeZB.setDestinationParams(paq_sent, direccion, aux, MAC_TYPE, DATA_ABSOLUTE);
                  xbeeZB.setDestinationParams(paq_sent, macA, aux, MAC_TYPE, DATA_ABSOLUTE);
                  xbeeZB.sendXBee(paq_sent); 
                  
                  free(paq_sent);
                  paq_sent = NULL;
                  
                  free(xbeeZB.packet_finished[xbeeZB.pos-1]); 
                  xbeeZB.packet_finished[xbeeZB.pos-1]=NULL; 
                  xbeeZB.pos--; 
                  
                  xbeeZB.OFF();
                  
                  sendSMS(aux);
                  
                  xbeeZB.ON(); 
              }      
           }
       }
    //}
  //delay(500);
}

void sendSMS(char*){ //subfn to send SMS with message body as argument
  //GPRS.begin();
  //GPRS.setMode(GPRS_ON);
  GPRS.ON();

  //waiting while GPRS connects to the network
   while((timeout<MAX_TRIES)&&(!GPRS.check())){ //while in time and not connected...
    USB.print("timeout = ");
    USB.println(timeout,DEC);
    timeout++;
  }
  timeout = 0;
  
  if(GPRS.check()){

  //configure SMS and Incoming calls
    GPRS.setInfoIncomingCall();
    GPRS.setInfoIncomingSMS();
    GPRS.setTextModeSMS();

  // Sending test SMS
    GPRS.sendSMS(aux,"087*******"); //phone no.
    
    GPRS.setMode(GPRS_HIBERNATE);
  }
  else{
    GPRS.setMode(GPRS_HIBERNATE);
    for(uint8_t i = 0;i<10;i++){
        Utils.blinkLEDs(1000);
    }
  }
}




It's still timing out trying to associate with the network when I call sendSMS(char*);

I've tested the code again and sendSMS(char*) will successfully associate with the network and send an SMS if it is called in the setup, however If I call it at the beginning of the loop it will not work reliably. (Has worked on 2/10 attempts).

Thanks again.


Top
 Profile  
 
 Post subject: Re: GPRS, configuring & connecting...
PostPosted: Tue Mar 20, 2012 8:02 pm 

Joined: Fri Nov 25, 2011 2:28 pm
Posts: 62
To clarify me previous post:
Quote:
It's still timing out trying to associate with the network when I call sendSMS(char*);

I've tested the code again and sendSMS(char*) will successfully associate with the network and send an SMS if it is called in the setup, however If I call it at the beginning of the loop it will not work reliably. (Has worked on 2/10 attempts).


It times out when I call the sendSMS(char*) function after recieving a packet (line 118)

However it will successfully associate with the network and send an SMS if called before the loop phase (see comments @ lines 52 & 75).

It will connect occasionally before the loop stage (comment on line 82) however It will only with a low success rate (around 5:1).

Thanks, hope this makes it a bit easier to decipher.


Top
 Profile  
 
 Post subject: Re: GPRS, configuring & connecting...
PostPosted: Tue Mar 27, 2012 11:29 am 

Joined: Mon Sep 28, 2009 1:06 pm
Posts: 7455
Hi LiamatTitan,

It could be a problem in the connection to the network, after powering on the GPRS you execute a loop where you check it two consecutive times, but it could (and probably will) take longer than you are waiting for. Try adding some more retries and some more time between them, for example setting MAX_TRIES to 20 and adding a small waiting period in the loop, like a 200ms delay.

Code:
  #define MAX_TRIES 20

  ...

   while((timeout<MAX_TRIES)&&(!GPRS.check())){ //while in time and not connected...
    USB.print("timeout = ");
    USB.println(timeout,DEC);
    timeout++;
    delay(200);
  }


Please try and let us know if you got it.

Regards.


Top
 Profile  
 
 Post subject: Re: GPRS, configuring & connecting...
PostPosted: Tue Mar 27, 2012 7:02 pm 

Joined: Fri Nov 25, 2011 2:28 pm
Posts: 62
Thanks for that,

I've made the change to the GPRS connection code (adding the delay(200);)

So far so good: 5/5 SMS sent successfully, GPRS connecting in <20 seconds!

ok, second mote and GPRS module & SIM (same code, APN etc.) 3/3 SMS sent ok.

2rd mote, 1st GPRS module and 2nd SIM: 3/3 connects & SMS sends OK.

Hopefully this efficent operation will be consistant.

I'll be testing & retesting during the next week (indoors & out) to verify this possible resolution.

Thank you for your help.


Top
 Profile  
 
 Post subject: Re: GPRS, configuring & connecting...
PostPosted: Wed Mar 28, 2012 7:01 pm 

Joined: Fri Nov 25, 2011 2:28 pm
Posts: 62
Hi again, a quick update:

I've been testing GPRS today, had some successes & failures, still appears to have same issue - difficulty associating with the network.

I'll need to go deeper I fear, eg. AT commands, to try to identify a point of failure in the negotiation between the module and the local GSM network.

Thanks!


Top
 Profile  
 
 Post subject: Re: GPRS, configuring & connecting...
PostPosted: Fri Mar 30, 2012 4:02 pm 

Joined: Fri Nov 25, 2011 2:28 pm
Posts: 62
Hello again,

I've been expanding the test 'net'.

I've had no GPRS successes with Vodafone in the last 24hrs.
I tried an o2 SIM, configured the APN & credentials and it connected first time.
I sent , then reconnected 5 - 6 SMS messages in about 2 minutes... then I switched off the mote, powered it back on, and it connected and sent OK, as expected.

20 minutes later it would not connect. I uploaded the exact same sketch to the same physical system and the mote will not associate with the network, same behaviour as the vodafone SIMs.

I've been reading some sagemcom docs, esp. about AT commands http://www.alphamicro.net/media/191723/hilo_3g_ed_02_-_at_command_set_for_sagemcom_hilo3g_module.pdf but in order to communicate with the module this way I'll need to 'adapt' using the private AT command methods in WaspGPRS.cpp - meaning I'll need to recompile it and deal with dependancies.

I'd rather not have to do this - I can't guarantee I'll get more info from the association process (beyond GPRS.check() 's returning the connected state).

I'd appreciate advice on this goal - how to establish the GPRS module is working correctly with the SIM and mote - or isn't.

Thank you,
Liam.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 2   [ 12 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:


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