Add isNetworkConnected(), isGprsConnected(). Fix #82
This commit is contained in:
@@ -171,7 +171,7 @@ public:
|
|||||||
String remoteIP() TINY_GSM_ATTR_NOT_IMPLEMENTED;
|
String remoteIP() TINY_GSM_ATTR_NOT_IMPLEMENTED;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TinyGsmSim800* at;
|
TinyGsmSim800* at;
|
||||||
uint8_t mux;
|
uint8_t mux;
|
||||||
uint16_t sock_available;
|
uint16_t sock_available;
|
||||||
uint32_t prev_check;
|
uint32_t prev_check;
|
||||||
@@ -411,13 +411,17 @@ public:
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isNetworkConnected() {
|
||||||
|
RegStatus s = getRegistrationStatus();
|
||||||
|
return (s == REG_OK_HOME || s == REG_OK_ROAMING);
|
||||||
|
}
|
||||||
|
|
||||||
bool waitForNetwork(unsigned long timeout = 60000L) {
|
bool waitForNetwork(unsigned long timeout = 60000L) {
|
||||||
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
||||||
RegStatus s = getRegistrationStatus();
|
if (isNetworkConnected()) {
|
||||||
if (s == REG_OK_HOME || s == REG_OK_ROAMING) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
delay(1000);
|
delay(500);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -503,7 +507,24 @@ public:
|
|||||||
|
|
||||||
bool gprsDisconnect() {
|
bool gprsDisconnect() {
|
||||||
sendAT(GF("+CIPSHUT"));
|
sendAT(GF("+CIPSHUT"));
|
||||||
return waitResponse(60000L) == 1;
|
if (waitResponse(60000L) != 1)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
sendAT(GF("+CGATT=0"));
|
||||||
|
if (waitResponse(60000L) != 1)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isGprsConnected() {
|
||||||
|
sendAT(GF("+CGATT?"));
|
||||||
|
if (waitResponse(GF(GSM_NL "+CGATT:")) != 1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
int res = stream.readStringUntil('\n').toInt();
|
||||||
|
waitResponse();
|
||||||
|
return res == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getLocalIP() {
|
String getLocalIP() {
|
||||||
|
Reference in New Issue
Block a user