Hi community!
The startup and connection sequence for the modem in the examples and from what I have found in the net are not quite satisfactory. What i am looking for is a sequence that tests sim and pin, then tries to connect and eventually gets into the loop despite problems. I think this could be interesting for many .
I make a first suggestion here and hope for improvements from you.
Notes:
WDTZero lib as Watchdog,
MKRNB lib with
NBClient net;
GPRS gprs;
NB nbAccess(true); //(true)
NBScanner scannerNetworks;
NB_SMS sms;
current behavior: Sim and pintest work in my modest tests, sometimes the modem hangs in the
if ((nbAccess.begin(PINNUMBER) == NB_READY) && (gprs.attachGPRS() == GPRS_READY))
statement, then the watchdog resets the board after one minute, sometimes it connects at the second try, sometimes it goes smooth, sometimes i need a cold beer. May someone has a contribution..
Often the modem hangs in limbo for no reason:
14:15:10.038 -> Modem, SIM und PIN OK!AT+CFUN=1
14:15:10.038 -> OK
14:15:10.075 -> AT+CPWROFF
14:15:10.075 -> OK
14:15:10.254 -> AT
14:15:10.254 -> OK
14:15:10.364 -> AT+CMEE=0
14:15:10.364 -> OK
14:15:10.542 -> AT+CFUN=0
14:15:12.259 -> OK
And then nothing happens.
Here's my code:
MyWatchDoggy.attachShutdown(myshutdown);
MyWatchDoggy.setup(WDT_SOFTCYCLE1M); // Software Watchdog set 1 min
MODEM.begin();
delay(500);
String response;
// SIM present?
MODEM.sendf("AT+CCID?");
MODEM.waitForResponse(10000, &response);
Serial.print("simtest response: ");
Serial.println(response);
if (response.startsWith("+CCID: ")) {
simtest = true;
Serial.print("SIM Present!");
}
else {
simtest = false;
Serial.print("SIM NOT present");
}
MODEM.send("AT+CPIN?");
MODEM.waitForResponse(10000, &response);
Serial.print("pintest response: ");
Serial.println(response);
if (response.endsWith("READY")) {
pintest = true;
Serial.print("PIN Test Passed");
} else if (response.endsWith("SIM PIN")) {
Serial.print("Wrong PIN");
Serial.print("PIN Test NOT passed");
} else if (response.endsWith("SIM PUK")) {
Serial.print("PUK wrong");
Serial.print("SIM needs PUK");
}
if ((simtest == false) || (pintest == false))
{
Serial.println("Modem or SIM not ready");
modemconnected = false;
delay(2000);
}
if ((simtest == true) && (pintest == true))
{
Serial.print("Modem, SIM and PIN OK!");
MyWatchDoggy.clear();
int gsm_conn_counter = 0;
// MODEM reset
// MODEM.send("AT+CFUN=16");
// MODEM.waitForResponse(10000);
//MODEM.send("AT+CFUN=1");
// MODEM.waitForResponse(10000);
do {
if ((nbAccess.begin(PINNUMBER) == NB_READY) && (gprs.attachGPRS() == GPRS_READY))
// (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)
{
modemconnected = true;
Serial.print("Mobile Uplink Ready!");
delay(1000);
break;
}
else
{
Serial.print("Mobile Uplink Not Ready!");
delay(2000);
Serial.print("Trying to uplink again..");
Serial.print("gsm_conn_counter");
gsm_conn_counter ++;
Serial.print(gsm_conn_counter);
if (gsm_conn_counter > 3)
{
Serial.print("Start without Network..");
delay(2000);
}
}
}
while (gsm_conn_counter <= 2);
}
void loop(){}
void myshutdown()
{
Serial.print("Restart now...");
// Proper Modem Shutdown ?
MODEM.sendf("AT+CFUN=16");
MODEM.waitForResponse(10000);
}