ublox-at-cellular-interface

Branch:
profile_polling
Revision:
31:07c9c5c3fb88
Parent:
30:0f571a4920c8
Child:
33:5d5ce25405d4
--- a/UbloxATCellularInterface.cpp	Thu Aug 01 18:06:44 2019 +0500
+++ b/UbloxATCellularInterface.cpp	Fri Aug 02 11:32:14 2019 +0500
@@ -274,13 +274,29 @@
              success && (protocol <= nsapi_security_to_modem_security(NSAPI_SECURITY_CHAP)); protocol++) {
             if ((_auth == NSAPI_SECURITY_UNKNOWN) || (nsapi_security_to_modem_security(_auth) == protocol)) {
                 if (_at->send("AT+UPSD=" PROFILE ",6,%d", protocol) && _at->recv("OK")) {
-                    // Activate, waiting 30 seconds for the connection to be made
-                    at_set_timeout(30000);
-                    activated = _at->send("AT+UPSDA=" PROFILE ",3") && _at->recv("OK");
+                    at_set_timeout(3*60*1000);
+                    _at->send("AT+UPSDA=" PROFILE ",3") && _at->recv("OK");
                     at_set_timeout(at_timeout);
                 }
             }
         }
+
+        Timer timer;
+        timer.start();
+        while (timer.read() < 180) {
+            if (_at->send("AT+UPSND=" PROFILE ",8") && _at->recv("+UPSND: %*d,%*d,%d\n", &active) &&
+                _at->recv("OK")) {
+                if (active == 1) {
+                    tr_debug("Profile activated successfully");
+                    activated = true;
+                    break;
+                } else {
+                    tr_error("Profile still inactive");
+                    rtos::ThisThread::sleep_for(5000); //Wait for 5 seconds and then try again
+                }
+            }
+        }
+        timer.stop();
     }
 
     return activated;