Better support for ublox LTE modules

This commit is contained in:
Sara Damiano
2018-11-07 14:45:38 -05:00
parent d5dba5647f
commit f5c141c2cc
2 changed files with 77 additions and 30 deletions

View File

@@ -422,7 +422,11 @@ public:
bool isNetworkConnected() { bool isNetworkConnected() {
RegStatus s = getRegistrationStatus(); RegStatus s = getRegistrationStatus();
return (s == REG_OK_HOME || s == REG_OK_ROAMING); if (s == REG_OK_HOME || s == REG_OK_ROAMING)
return true;
else if (s == REG_UNKNOWN) // for some reason, it can hang at unknown..
return isGprsConnected();
else return false;
} }
/* /*
@@ -431,33 +435,48 @@ public:
bool gprsConnect(const char* apn, const char* user = NULL, const char* pwd = NULL) { bool gprsConnect(const char* apn, const char* user = NULL, const char* pwd = NULL) {
gprsDisconnect(); gprsDisconnect();
sendAT(GF("+CGATT=1")); sendAT(GF("+CGATT=1")); // attach to GPRS
if (waitResponse(60000L) != 1) { if (waitResponse(360000L) != 1) {
return false; return false;
} }
sendAT(GF("+UPSD=0,1,\""), apn, '"'); // NOTE: Setting up the PSD profile/PDP context with the UPSD commands
// sets up an "internal" PDP context, i.e. a data connection using the
// internal IP stack and related AT commands for sockets.
// Using CGDCONT would set up an "external" PCP context, i.e. a data
// connection using the external IP stack (e.g. Windows dial up) and PPP
// link over the serial interface.
sendAT(GF("+UPSD=0,1,\""), apn, '"'); // Set APN for PSD profile 0
waitResponse(); waitResponse();
if (user && strlen(user) > 0) { if (user && strlen(user) > 0) {
sendAT(GF("+UPSD=0,2,\""), user, '"'); sendAT(GF("+UPSD=0,2,\""), user, '"'); // Set user for PSD profile 0
waitResponse(); waitResponse();
} }
if (pwd && strlen(pwd) > 0) { if (pwd && strlen(pwd) > 0) {
sendAT(GF("+UPSD=0,3,\""), pwd, '"'); sendAT(GF("+UPSD=0,3,\""), pwd, '"'); // Set password for PSD profile 0
waitResponse(); waitResponse();
} }
sendAT(GF("+UPSD=0,7,\"0.0.0.0\"")); // Dynamic IP sendAT(GF("+UPSD=0,7,\"0.0.0.0\"")); // Dynamic IP on PSD profile 0
waitResponse(); waitResponse();
sendAT(GF("+UPSDA=0,3")); // LTE modules do not support UPSDA and UPSND commands, even for "internal" contexts
if (waitResponse(60000L) != 1) { if (getModemName().startsWith(GF("SARA-R")) or getModemName().startsWith(GF("SARA-N")))
sendAT(GF("+CGACT=0,1")); // activate PDP profile/context 0
if (waitResponse(150000L) != 1) {
return false; return false;
} }
// Open a GPRS context else {
sendAT(GF("+UPSND=0,8")); sendAT(GF("+UPSDA=0,3")); // Activate the PDP context associated with profile 0
if (waitResponse(360000L) != 1) {
return false;
}
sendAT(GF("+UPSND=0,8")); // Activate PSD profile 0
if (waitResponse(GF(",8,1")) != 1) { if (waitResponse(GF(",8,1")) != 1) {
return false; return false;
} }
@@ -465,13 +484,26 @@ public:
return true; return true;
} }
bool gprsDisconnect() { return true;
sendAT(GF("+UPSDA=0,4")); }
if (waitResponse(60000L) != 1)
return false;
sendAT(GF("+CGATT=0")); bool gprsDisconnect() {
if (waitResponse(60000L) != 1)
// LTE modules do not support UPSDA and UPSND commands, even for "internal" contexts
if (getModemName().startsWith(GF("SARA-R")) or getModemName().startsWith(GF("SARA-N")))
sendAT(GF("+CGACT=0,0")); // activate PDP profile/context 0
if (waitResponse(40000L) != 1) {
return false;
}
else {
sendAT(GF("+UPSDA=0,4")); // Deactivate the PDP context associated with profile 0
if (waitResponse(360000L) != 1)
return false;
}
sendAT(GF("+CGATT=0")); // detach from GPRS
if (waitResponse(360000L) != 1)
return false; return false;
return true; return true;
@@ -495,6 +527,20 @@ public:
*/ */
String getLocalIP() { String getLocalIP() {
// LTE modules do not support UPSDA and UPSND commands, even for "internal" contexts
if (getModemName().startsWith(GF("SARA-R")) or getModemName().startsWith(GF("SARA-N"))) {
sendAT(GF("+CGPADDR?"));
if (waitResponse(GF(GSM_NL "+CGPADDR:")) != 1) {
return "";
}
streamSkipUntil('\"'); // Skip context id
String res = stream.readStringUntil('\"');
if (waitResponse() != 1) {
return "";
}
return res;
}
else {
sendAT(GF("+UPSND=0,0")); sendAT(GF("+UPSND=0,0"));
if (waitResponse(GF(GSM_NL "+UPSND:")) != 1) { if (waitResponse(GF(GSM_NL "+UPSND:")) != 1) {
return ""; return "";
@@ -507,6 +553,7 @@ public:
} }
return res; return res;
} }
}
/* /*
* Phone Call functions * Phone Call functions