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

Files at this revision

API Documentation at this revision

Comitter:
rob.meades@u-blox.com
Date:
Fri Jun 30 13:30:20 2017 +0100
Parent:
1:80ec3fccad9e
Child:
3:9863dcade75d
Commit message:
Connect now fails correctly if it cannot achieve a connection, rather than trying for ever.

Changed in this revision

UbloxPPPCellularInterface.cpp Show annotated file Show diff for this revision Revisions of this file
UbloxPPPCellularInterface.h Show annotated file Show diff for this revision Revisions of this file
--- 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);
         }
--- a/UbloxPPPCellularInterface.h	Thu Jun 15 14:05:47 2017 +0100
+++ b/UbloxPPPCellularInterface.h	Fri Jun 30 13:30:20 2017 +0100
@@ -225,7 +225,7 @@
 
     /** Get the next set of credentials from the database.
      */
-    void get_next_credentials(const char * config);
+    void get_next_credentials(const char ** config);
 
 private:
     bool _sim_pin_check_change_pending;