|
@ -126,7 +126,7 @@ public: |
|
|
TINY_GSM_YIELD(); |
|
|
TINY_GSM_YIELD(); |
|
|
at->maintain(); |
|
|
at->maintain(); |
|
|
size_t cnt = 0; |
|
|
size_t cnt = 0; |
|
|
while (cnt < size) { |
|
|
|
|
|
|
|
|
while (cnt < size && sock_connected) { |
|
|
size_t chunk = TinyGsmMin(size-cnt, rx.size()); |
|
|
size_t chunk = TinyGsmMin(size-cnt, rx.size()); |
|
|
if (chunk > 0) { |
|
|
if (chunk > 0) { |
|
|
rx.get(buf, chunk); |
|
|
rx.get(buf, chunk); |
|
@ -443,71 +443,82 @@ 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("+SAPBR=3,1,\"Contype\",\"GPRS\"")); |
|
|
|
|
|
|
|
|
// Set the Bearer for the IP |
|
|
|
|
|
sendAT(GF("+SAPBR=3,1,\"Contype\",\"GPRS\"")); // Set the connection type to GPRS |
|
|
waitResponse(); |
|
|
waitResponse(); |
|
|
|
|
|
|
|
|
sendAT(GF("+SAPBR=3,1,\"APN\",\""), apn, '"'); |
|
|
|
|
|
|
|
|
sendAT(GF("+SAPBR=3,1,\"APN\",\""), apn, '"'); // Set the APN |
|
|
waitResponse(); |
|
|
waitResponse(); |
|
|
|
|
|
|
|
|
if (user && strlen(user) > 0) { |
|
|
if (user && strlen(user) > 0) { |
|
|
sendAT(GF("+SAPBR=3,1,\"USER\",\""), user, '"'); |
|
|
|
|
|
|
|
|
sendAT(GF("+SAPBR=3,1,\"USER\",\""), user, '"'); // Set the user name |
|
|
waitResponse(); |
|
|
waitResponse(); |
|
|
} |
|
|
} |
|
|
if (pwd && strlen(pwd) > 0) { |
|
|
if (pwd && strlen(pwd) > 0) { |
|
|
sendAT(GF("+SAPBR=3,1,\"PWD\",\""), pwd, '"'); |
|
|
|
|
|
|
|
|
sendAT(GF("+SAPBR=3,1,\"PWD\",\""), pwd, '"'); // Set the password |
|
|
waitResponse(); |
|
|
waitResponse(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Define the PDP context |
|
|
sendAT(GF("+CGDCONT=1,\"IP\",\""), apn, '"'); |
|
|
sendAT(GF("+CGDCONT=1,\"IP\",\""), apn, '"'); |
|
|
waitResponse(); |
|
|
waitResponse(); |
|
|
|
|
|
|
|
|
|
|
|
// Activate the PDP context |
|
|
sendAT(GF("+CGACT=1,1")); |
|
|
sendAT(GF("+CGACT=1,1")); |
|
|
waitResponse(60000L); |
|
|
waitResponse(60000L); |
|
|
|
|
|
|
|
|
// Open a GPRS context |
|
|
|
|
|
|
|
|
// Open a the definied bearer context |
|
|
sendAT(GF("+SAPBR=1,1")); |
|
|
sendAT(GF("+SAPBR=1,1")); |
|
|
waitResponse(85000L); |
|
|
waitResponse(85000L); |
|
|
// Query the GPRS context |
|
|
|
|
|
|
|
|
// Query the GPRS bearer context status |
|
|
sendAT(GF("+SAPBR=2,1")); |
|
|
sendAT(GF("+SAPBR=2,1")); |
|
|
if (waitResponse(30000L) != 1) |
|
|
if (waitResponse(30000L) != 1) |
|
|
return false; |
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
// Attach to GPRS |
|
|
sendAT(GF("+CGATT=1")); |
|
|
sendAT(GF("+CGATT=1")); |
|
|
if (waitResponse(60000L) != 1) |
|
|
if (waitResponse(60000L) != 1) |
|
|
return false; |
|
|
return false; |
|
|
|
|
|
|
|
|
// TODO: wait AT+CGATT? |
|
|
// TODO: wait AT+CGATT? |
|
|
|
|
|
|
|
|
|
|
|
// Set to multi-IP |
|
|
sendAT(GF("+CIPMUX=1")); |
|
|
sendAT(GF("+CIPMUX=1")); |
|
|
if (waitResponse() != 1) { |
|
|
if (waitResponse() != 1) { |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Put in "quick send" mode (thus no extra "Send OK") |
|
|
sendAT(GF("+CIPQSEND=1")); |
|
|
sendAT(GF("+CIPQSEND=1")); |
|
|
if (waitResponse() != 1) { |
|
|
if (waitResponse() != 1) { |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Set to get data manually |
|
|
sendAT(GF("+CIPRXGET=1")); |
|
|
sendAT(GF("+CIPRXGET=1")); |
|
|
if (waitResponse() != 1) { |
|
|
if (waitResponse() != 1) { |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Start Task and Set APN, USER NAME, PASSWORD |
|
|
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; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Bring Up Wireless Connection with GPRS or CSD |
|
|
sendAT(GF("+CIICR")); |
|
|
sendAT(GF("+CIICR")); |
|
|
if (waitResponse(60000L) != 1) { |
|
|
if (waitResponse(60000L) != 1) { |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Get Local IP Address, only assigned after connection |
|
|
sendAT(GF("+CIFSR;E0")); |
|
|
sendAT(GF("+CIFSR;E0")); |
|
|
if (waitResponse(10000L) != 1) { |
|
|
if (waitResponse(10000L) != 1) { |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Configure Domain Name Server (DNS) |
|
|
sendAT(GF("+CDNSCFG=\"8.8.8.8\",\"8.8.4.4\"")); |
|
|
sendAT(GF("+CDNSCFG=\"8.8.8.8\",\"8.8.4.4\"")); |
|
|
if (waitResponse() != 1) { |
|
|
if (waitResponse() != 1) { |
|
|
return false; |
|
|
return false; |
|
@ -517,11 +528,11 @@ public: |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
bool gprsDisconnect() { |
|
|
bool gprsDisconnect() { |
|
|
sendAT(GF("+CIPSHUT")); |
|
|
|
|
|
|
|
|
sendAT(GF("+CIPSHUT")); // Shut the TCP/IP connection |
|
|
if (waitResponse(60000L) != 1) |
|
|
if (waitResponse(60000L) != 1) |
|
|
return false; |
|
|
return false; |
|
|
|
|
|
|
|
|
sendAT(GF("+CGATT=0")); |
|
|
|
|
|
|
|
|
sendAT(GF("+CGATT=0")); // Deactivate the bearer context |
|
|
if (waitResponse(60000L) != 1) |
|
|
if (waitResponse(60000L) != 1) |
|
|
return false; |
|
|
return false; |
|
|
|
|
|
|
|
|