Library that implements the CellularInterface using PPP and LWIP on the mbed MCU. May be used on the C027 and C030 (non-N2xx flavour) boards from mbed 5.5 onwards.

Dependents:   example-ublox-cellular-interface HelloMQTT example-ublox-cellular-interface_r410M example-ublox-mbed-client

Revision:
2:4c533665168c
Parent:
0:44dd95724bc2
Child:
3:9863dcade75d
--- a/UbloxPPPCellularInterface.cpp	Thu Jun 15 14:05:47 2017 +0100
+++ b/UbloxPPPCellularInterface.cpp	Fri Jun 30 13:30:20 2017 +0100
@@ -78,12 +78,12 @@
 }
 
 // Get the next set of credentials, based on IMSI.
-void UbloxPPPCellularInterface::get_next_credentials(const char * config)
+void UbloxPPPCellularInterface::get_next_credentials(const char ** config)
 {
-    if (config) {
-        _apn    = _APN_GET(config);
-        _uname  = _APN_GET(config);
-        _pwd    = _APN_GET(config);
+    if (*config) {
+        _apn    = _APN_GET(*config);
+        _uname  = _APN_GET(*config);
+        _pwd    = _APN_GET(*config);
     }
 
     _apn    = _apn     ?  _apn    : "";
@@ -212,16 +212,26 @@
             // Attempt to connect
             do {
                 // Set up APN and IP protocol for external PDP context
-                get_next_credentials(config);
+                get_next_credentials(&config);
                 nsapi_error = setup_context_and_credentials();
 
                 // Attempt to enter data mode
                 if ((nsapi_error == NSAPI_ERROR_OK) && set_atd()) {
+                    wait_ms(1000);
                     // Initialise PPP
                     // nsapi_ppp_connect() is a blocking call, it will block until
                     // connected, or timeout after 30 seconds
                     nsapi_error = nsapi_ppp_connect(_fh, _connection_status_cb, _uname, _pwd);
                     _ppp_connection_up = (nsapi_error == NSAPI_ERROR_OK);
+                    if (!_ppp_connection_up) {
+                        // If the connection has failed we may or may not still be
+                        // in data mode, depending on the nature of the failure,
+                        // so it's safest to force us back to command mode here
+                        // (if we're already in command mode the recv() call will
+                        // just time out)
+                        _at->send("~+++");
+                        _at->recv("NO CARRIER");
+                    }
                 }
             } while (!_ppp_connection_up && config && *config);
         }