Implementation of the CellularInterface for u-blox C027 and C030 (non-N2xx flavour) modems that uses the IP stack on-board the cellular modem, hence not requiring LWIP (and so less RAM) and allowing any AT command exchanges to be carried out at the same time as data transfers (since the modem remains in AT mode all the time). This library may be used from mbed 5.5 onwards. If you need to use SMS, USSD or access the modem file system at the same time as using the CellularInterface then use ublox-at-cellular-interface-ext instead.

Dependents:   example-ublox-cellular-interface example-ublox-cellular-interface_r410M example-ublox-mbed-client example-ublox-cellular-interface ... more

Files at this revision

API Documentation at this revision

Comitter:
wajahat.abbas@u-blox.com
Date:
Fri Apr 19 15:40:46 2019 +0500
Parent:
20:2e8e1c573e18
Child:
25:aabc50bc418e
Commit message:
define and activate context in case of R412M

Changed in this revision

UbloxATCellularInterface.cpp Show annotated file Show diff for this revision Revisions of this file
UbloxATCellularInterface.h Show annotated file Show diff for this revision Revisions of this file
--- a/UbloxATCellularInterface.cpp	Tue Feb 12 18:42:43 2019 +0500
+++ b/UbloxATCellularInterface.cpp	Fri Apr 19 15:40:46 2019 +0500
@@ -114,12 +114,18 @@
         case NSAPI_SECURITY_CHAP:
             modem_security = 2;
             break;
+#ifndef TARGET_UBLOX_C030_R41XM
         case NSAPI_SECURITY_UNKNOWN:
             modem_security = 3;
             break;
         default:
             modem_security = 3;
             break;
+#else
+        default:
+            modem_security = 0;
+            break;
+#endif
     }
 
     return modem_security;
@@ -329,6 +335,7 @@
     bool success = false;
     int at_timeout = _at_timeout;
 
+#ifndef TARGET_UBLOX_C030_R41XM
     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") &&
@@ -340,10 +347,79 @@
         success = _at->send("AT+UPSDA=" PROFILE ",3") && _at->recv("OK");
         at_set_timeout(at_timeout);
     }
+#else
+    int modem_security = nsapi_security_to_modem_security(auth);
+    if (_at->send("AT+CGDCONT=%d,\"IP\",\"%s\"", cid, apn) && _at->recv("OK")) {
+        if ( modem_security == NSAPI_SECURITY_CHAP) {
+            if (_at->send("AT+UAUTHREQ=%d,%d,\"%s\",\"%s\"", cid, modem_security,
+                        password, username) && _at->recv("OK")) {
+                success = true;
+            }
+        } else if (modem_security == NSAPI_SECURITY_NONE) {
+            if (_at->send("AT+UAUTHREQ=%d,%d", cid, modem_security) && _at->recv("OK")) {
+                success = true;
+            }
+        } else {
+            if (_at->send("AT+UAUTHREQ=%d,%d,\"%s\",\"%s\"", cid, modem_security,
+                          username, password) && _at->recv("OK")) {
+                success = true;
+            }
+        }
+    }
+#endif
 
     return success;
 }
 
+#ifdef TARGET_UBLOX_C030_R41XM
+//define PDP context for R412M
+bool UbloxATCellularInterface::define_context()
+{
+    bool success = false;
+    const char * config = NULL;
+    LOCK();
+
+    // If the caller hasn't entered an APN, try to find it
+    if (_apn == NULL) {
+        config = apnconfig(_dev_info.imsi);
+    }
+
+    // Attempt to connect
+    do {
+        // Set up APN and IP protocol for PDP context
+        get_next_credentials(&config);
+        _auth = (*_uname && *_pwd) ? _auth : NSAPI_SECURITY_NONE;
+        if (activate_profile_by_cid(1, _apn, _uname, _pwd, _auth)) {
+            success = true;
+        }
+    } while (!success && config && *config);
+
+    if (!success) {
+        tr_error("Failed to connect, check your APN/username/password");
+    }
+
+    UNLOCK();
+    return success;
+}
+bool UbloxATCellularInterface::activate_context()
+{
+    bool status = false;
+    int at_timeout;
+    LOCK();
+
+    at_timeout = _at_timeout; // Has to be inside LOCK()s
+    at_set_timeout(150000);
+    if (_at->send("AT+CGACT=1,1") && _at->recv("OK")) {
+        status = true;
+    }
+
+    at_set_timeout(at_timeout);
+
+    UNLOCK();
+    return status;
+}
+#endif
+
 // Connect the on board IP stack of the modem.
 bool UbloxATCellularInterface::connect_modem_stack()
 {
@@ -1094,25 +1170,28 @@
             }
             _sim_pin_change_pending = false;
         }
-
+#ifdef TARGET_UBLOX_C030_R41XM
+        define_context();
+#endif
         if (nsapi_error == NSAPI_ERROR_NO_CONNECTION) {
             for (int retries = 0; !registered && (retries < 3); retries++) {
                 if (nwk_registration()) {
-                    registered = true;;
+                    registered = true;
+#ifdef TARGET_UBLOX_C030_R41XM
+                    if (activate_context()) {
+                        nsapi_error = NSAPI_ERROR_OK;
+                    }
+#endif
                 }
             }
         }
     }
-
+#ifndef TARGET_UBLOX_C030_R41XM
     // Attempt to establish a connection
-#ifdef TARGET_UBLOX_C030_R41XM
-    if (registered) {
-#else
     if (registered && connect_modem_stack()) {
-#endif
         nsapi_error = NSAPI_ERROR_OK;
     }
-
+#endif
     return nsapi_error;
 }
 
--- a/UbloxATCellularInterface.h	Tue Feb 12 18:42:43 2019 +0500
+++ b/UbloxATCellularInterface.h	Fri Apr 19 15:40:46 2019 +0500
@@ -627,6 +627,10 @@
     void UUSORF_URC();
     void UUSOCL_URC();
     void UUPSDD_URC();
+#ifdef TARGET_UBLOX_C030_R41XM
+    bool activate_context();
+    bool define_context();
+#endif
 };
 
 #endif // _UBLOX_AT_CELLULAR_INTERFACE_