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

Revision:
34:ca02f8448085
Parent:
33:5d5ce25405d4
Child:
36:9d48ec522cb4
--- a/UbloxATCellularInterface.cpp	Tue Aug 06 12:14:22 2019 +0500
+++ b/UbloxATCellularInterface.cpp	Thu Aug 08 16:47:36 2019 +0500
@@ -431,6 +431,26 @@
     UNLOCK();
     return status;
 }
+
+bool UbloxATCellularInterface::is_context_active()
+{
+    bool status = false;
+    int at_timeout;
+    int active = 0;
+    LOCK();
+
+    at_timeout = _at_timeout; // Has to be inside LOCK()s
+    at_set_timeout(150000);
+    if (_at->send("AT+CGACT?") && _at->recv("+CGACT: %*d,%d\n", &active)) {
+        if (active == 1) {
+        	status = true;
+        }
+    }
+    at_set_timeout(at_timeout);
+
+    UNLOCK();
+    return status;
+}
 #endif
 
 // Connect the on board IP stack of the modem.
@@ -1214,11 +1234,14 @@
                 if (nwk_registration()) {
                     registered = true;
 #ifdef TARGET_UBLOX_C030_R41XM
-                    if(is_registered_psd() || is_registered_eps()) {
+                    if (is_context_active()) {
                         nsapi_error = NSAPI_ERROR_OK;
-                    }
-                    else if (activate_context()) {
-                        nsapi_error = NSAPI_ERROR_OK;
+                        tr_info("Context is already active\r\n");
+                    } else {
+                        tr_info("Context is not active, activating it.\r\n");
+                        if (activate_context()) {
+                            nsapi_error = NSAPI_ERROR_OK;
+                        }
                     }
 #endif
                 }