Fork of ublox-at-cellular-interface to add LARA-R2 support

Dependents:  

Fork of ublox-at-cellular-interface by u-blox

Revision:
16:da7f7b30c3de
Parent:
15:8cc9a80ac0ad
Child:
17:8696a2ecde3f
diff -r 8cc9a80ac0ad -r da7f7b30c3de UbloxATCellularInterface.cpp
--- a/UbloxATCellularInterface.cpp	Mon Mar 26 15:33:40 2018 +0100
+++ b/UbloxATCellularInterface.cpp	Mon Sep 10 18:48:43 2018 -0500
@@ -329,16 +329,19 @@
     bool success = false;
     int at_timeout = _at_timeout;
 
-    if (_at->send("AT+CGDCONT=%d,\"IP\",\"%s\"", cid, apn) && _at->recv("OK") &&
-        _at->send("AT+UAUTHREQ=%d,%d,\"%s\",\"%s\"", cid, nsapi_security_to_modem_security(auth),
-                  username, password) && _at->recv("OK") &&
-        _at->send("AT+UPSD=" PROFILE ",100,%d", cid) && _at->recv("OK")) {
+    // Must be detached to change CGDCONT
+    if (_at->send("AT+CGATT=0") && _at->recv("OK")) {
+        if (_at->send("AT+CGDCONT=%d,\"IP\",\"%s\"", cid, apn) && _at->recv("OK") &&
+            _at->send("AT+UAUTHREQ=%d,%d,\"%s\",\"%s\"", cid, nsapi_security_to_modem_security(auth),
+                      username, password) && _at->recv("OK") &&
+            _at->send("AT+UPSD=" PROFILE ",100,%d", cid) && _at->recv("OK")) {
 
-        // Wait 30 seconds for the connection to be made
-        at_set_timeout(30000);
-        // Activate the protocol
-        success = _at->send("AT+UPSDA=" PROFILE ",3") && _at->recv("OK");
-        at_set_timeout(at_timeout);
+            // Wait 30 seconds for the connection to be made
+            at_set_timeout(30000);
+            // Activate the protocol
+            success = _at->send("AT+UPSDA=" PROFILE ",3") && _at->recv("OK");
+            at_set_timeout(at_timeout);
+        }
     }
 
     return success;
@@ -366,7 +369,8 @@
                 // Set up APN and IP protocol for PDP context
                 get_next_credentials(&config);
                 _auth = (*_uname && *_pwd) ? _auth : NSAPI_SECURITY_NONE;
-                if ((_dev_info.dev != DEV_TOBY_L2) && (_dev_info.dev != DEV_MPCI_L2)) {
+                // TOBY-L2 / MPCI-L2 / LARA-R2 / TOBY-R2 mapped to <cid> via param tag 100
+                if ((_dev_info.dev != DEV_TOBY_L2) && (_dev_info.dev != DEV_MPCI_L2) && (_dev_info.dev != DEV_LARA_R2)) {
                     success = activate_profile(_apn, _uname, _pwd, _auth);
                 } else {
                     success = activate_profile_reuse_external();