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.
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);