Go Down

Topic: Connecting to GSM/GPRS unstable, eventually hangs (Read 14182 times) previous topic - next topic

stoutfiles

Does everyone here have the 3 second connected light when running this code?

ghen

This will do the trick with connectivity problems.
No GSM library modification needed.

Also make sure your BAUD rate for serial is high enough. GSM library in debug mode generates tons of messages. And Serial buffer is only 64 bytes.


Code: [Select]


  GSM                    gsmAccess(true);          // 'true' -> debug enabled
  GPRS                   gprs;
  GSMClient              client;

  GSM3_NetworkStatus_t   gsmStatus;
  GSM3_NetworkStatus_t   gprsStatus;


  Serial.begin(28800);                           // NOTE: Low BAUD rate leads to buffer overflow
  Serial.println("Starting up ...");             //       when there are a lot of DEBUG messages.
  Serial.flush();



  Serial.println("Connecting to GSM network ...");
  Serial.flush();

  // IMPORTANT: do not reset (false) and do not wait for ready state (false)
  //            E.g. call it async. We will pull for the ready state on our own.
  gsmStatus = gsmAccess.begin(GSM_PIN_NO, false, false);

  int retrycount = 60;
  while (gsmStatus != GSM_READY && retrycount-- > 0) {
    delay(1000);                                // lower delay value could lead to unstable state
   
    theGSM3ShieldV1ModemCore.manageReceivedData();
    gsmStatus = gsmAccess.getStatus();
  }

  if (gsmStatus != GSM_READY) {
    Serial.println("[ERR]: GSM connection failed");
    Serial.flush();
    goto exit;
  }
 
  Serial.println(" [DONE]");




  Serial.println("Connecting to GPRS ...");
  Serial.flush();

  // IMPORTANT: do not wait for ready state (false)
  //            E.g. call it async. We will pull for the ready state on our own.
  gprsStatus = gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD, false);

  int retrycount = 60;
  while (gprsStatus != GPRS_READY && retrycount-- > 0) {
    delay(1000);                                // lower delay value could lead to unstable state
   
    theGSM3ShieldV1ModemCore.manageReceivedData();
    gprsStatus = gprs.getStatus();
  }

  if (gprsStatus != GPRS_READY) {
    Serial.println("[ERR]: GPRS connection failed");
    Serial.flush();
    goto exit;
  }
 
  Serial.println(" [DONE]");



 
  // TODO: do your stuff here
  ...



exit:
  Serial.println("Shutting down GSM modem ...");
  Serial.flush()
 
  gsmAccess.shutdown();
  delay(250);
 
  // NOTE: There is an error in the schematic of the GSM Shield on the A_TX.
  //       You can find more info here: http://forum.arduino.cc/index.php?topic=158811.0
  //       and the way to fix it is to add digitalWrite(3,LOW); after the gsm.shutdown().
  digitalWrite(PIN_GSM_TX, LOW);



#17
Mar 30, 2015, 10:11 am Last Edit: Mar 30, 2015, 10:12 am by Maarten123
hi, is there a reason why this only works when the debug mode is true?

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy