Browse Source

Fix gprsConnect, add getLocalIP(). Fix #9

v_master
Volodymyr Shymanskyy 7 years ago
parent
commit
4a86db0745
1 changed files with 18 additions and 6 deletions
  1. +18
    -6
      TinyGsmClientA6.h

+ 18
- 6
TinyGsmClientA6.h View File

@ -337,9 +337,17 @@ public:
bool gprsConnect(const char* apn, const char* user, const char* pwd) { bool gprsConnect(const char* apn, const char* user, const char* pwd) {
gprsDisconnect(); gprsDisconnect();
sendAT(GF("+CGATT=1"));
if (waitResponse(60000L) != 1)
return false;
// TODO: wait AT+CGATT?
sendAT(GF("+CGDCONT=1,\"IP\",\""), apn, '"'); sendAT(GF("+CGDCONT=1,\"IP\",\""), apn, '"');
waitResponse(); waitResponse();
if (!user) user = "";
if (!pwd) pwd = "";
sendAT(GF("+CSTT=\""), apn, GF("\",\""), user, GF("\",\""), pwd, GF("\"")); sendAT(GF("+CSTT=\""), apn, GF("\",\""), user, GF("\",\""), pwd, GF("\""));
if (waitResponse(60000L) != 1) { if (waitResponse(60000L) != 1) {
return false; return false;
@ -348,12 +356,6 @@ public:
sendAT(GF("+CGACT=1,1")); sendAT(GF("+CGACT=1,1"));
waitResponse(60000L); waitResponse(60000L);
sendAT(GF("+CGATT=1"));
if (waitResponse(60000L) != 1)
return false;
// TODO: wait AT+CGATT?
sendAT(GF("+CIPMUX=1")); sendAT(GF("+CIPMUX=1"));
if (waitResponse() != 1) { if (waitResponse() != 1) {
return false; return false;
@ -376,6 +378,16 @@ public:
return waitResponse(60000L) == 1; return waitResponse(60000L) == 1;
} }
String getLocalIP() {
sendAT(GF("+CIFSR"));
String res;
if (waitResponse(10000L, res) != 1) {
return "";
}
res.trim();
return res;
}
/* /*
* Phone Call functions * Phone Call functions
*/ */


Loading…
Cancel
Save