Simple detection for LE910-NA1 modules
Fork of MTS-Cellular by
Diff: Cellular/EasyIP.cpp
- Revision:
- 51:ffc556ba33f7
- Parent:
- 49:1fc51c53cebf
- Child:
- 52:2cb58398a4f9
--- a/Cellular/EasyIP.cpp Tue Aug 05 15:02:00 2014 +0000 +++ b/Cellular/EasyIP.cpp Tue Aug 05 18:35:22 2014 +0000 @@ -72,12 +72,12 @@ if(isConnected()) { return true; } + //Create an mbed timer object Timer tmr; //Check Registration: AT+CREG? == 0,1 //(Does the AT command inside Cellular class) tmr.start(); - do { Registration registration = getRegistration(); if(registration != REGISTERED) { @@ -87,13 +87,14 @@ break; } } while(tmr.read() < 30); + //Check RSSI: AT+CSQ //Does the command inside Cellular tmr.reset(); do { int rssi = getSignalStrength(); logDebug("Signal strength: %d", rssi); - if((rssi == 99) || (rssi == -1)) { + if(rssi == 99 || rssi == -1) { logTrace("No Signal ... waiting"); wait(1); } else { @@ -156,6 +157,10 @@ logDebug("Successfully closed PPP Connection"); } + /* Radio was entering unknown state if ping command was sent after calling + * disconnect, due to context being closed between radio sending ping and + * waiting for ping response (which will never occur with connection closed) + */ tmr.start(); while(tmr.read() < 30) { result = sendCommand("AT#SGACT?", 1000); @@ -169,6 +174,7 @@ } } + //If still unable to close PPP connection, wait for 30 seconds to drop connection if(pppConnected) { wait(30); pppConnected = false; @@ -181,7 +187,7 @@ { std::string stateString; std::vector<std::string> pieces; - //state flags for various connection checks + //state flags for various connection components bool signal = false, regist = false, active = false; //1) Check if APN was set if we're on an HSPA radio @@ -200,7 +206,7 @@ //3) Query the radio - //Check antenna signal + //3.a) Check antenna signal std::string reply = sendCommand("AT+CSQ", 500); if(reply.empty() || (reply.find("ERROR") != std::string::npos)) { signal = false; @@ -218,7 +224,7 @@ } } - //Check cell tower registration + //3.b) Check cell tower registration reply = sendCommand("AT+CREG?", 500); if(reply.empty() || (reply.find("ERROR") != std::string::npos)) { regist = false; @@ -236,7 +242,7 @@ } } - //Check active context (SGACT = 1,1) + //3.c) Check active context (SGACT = 1,1) reply = sendCommand("AT#SGACT?", 500); if(reply.empty() || (reply.find("ERROR") != std::string::npos)) { active = false;