Using PDP commands

This commit is contained in:
Sara Damiano
2019-07-17 13:56:45 -04:00
parent a059354629
commit d4d63dabe7

View File

@@ -359,47 +359,56 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK()
return false; return false;
} }
// Actually open the packet network sendAT(GF("+CGATT=1")); // attach to GPRS
// NOTE: AT command manual hints this might be depricated or other options preferred if (waitResponse(360000L) != 1) {
// but all application notes use it
sendAT(GF("+NETOPEN"));
if (waitResponse(60000L) != 1) {
return false; return false;
} }
/* // Using CGDCONT sets up an "external" PCP context, i.e. a data connection
sendAT(GF("+CGATT=1")); // attach to GPRS // using the external IP stack (e.g. Windows dial up) and PPP link over the
if (waitResponse(360000L) != 1) { // serial interface. Is this preferred?
return false;
}
// Using CGDCONT sets up an "external" PCP context, i.e. a data connection if (user && strlen(user) > 0) {
// using the external IP stack (e.g. Windows dial up) and PPP link over the sendAT(GF("+CGAUTH=1,0,\""), user, GF("\",\""), pwd, '"'); // Set the authentication
// serial interface. Is this preferred? waitResponse();
}
if (user && strlen(user) > 0) { sendAT(GF("+CGDCONT=1,\"IP\",\""), apn, '"'); // Define PDP context 1
sendAT(GF("+CGAUTH=1,0,\""), user, GF("\",\""), pwd, '"'); // Set the authentication waitResponse();
waitResponse();
}
sendAT(GF("+CGDCONT=1,\"IP\",\""), apn, '"'); // Define PDP context 1 sendAT(GF("+CGACT=1,1")); // activate PDP profile/context 1
waitResponse(); if (waitResponse(75000L) != 1) {
return false;
}
sendAT(GF("+CGACT=1,1")); // activate PDP profile/context 1 // Actually open network socket
if (waitResponse(150000L) != 1) { // NOTE: AT command manual hints this might be depricated or other options preferred
return false; // but all application notes use it (and nothing states what *IS* preferred)
} sendAT(GF("+NETOPEN"));
*/ if (waitResponse(75000L) != 1) {
return false;
}
return true; return true;
} }
bool gprsDisconnect() { bool gprsDisconnect() {
// Close the network (note, all sockets should be closed first) // Close the network (note, all sockets should be closed first)
sendAT(GF("+NETCLOSE")); sendAT(GF("+NETCLOSE"));
if (waitResponse(60000L) != 1) if (waitResponse(60000L) != 1)
return false; return false;
sendAT(GF("+CGACT=1,0")); // Deactivate PDP context 1
if (waitResponse(40000L) != 1) {
return false;
}
sendAT(GF("+CGATT=0")); // detach from GPRS
if (waitResponse(360000L) != 1) {
return false;
}
return true; return true;
} }