Simple example program to demonstrate and test cellular connection using the MTSAS library (over PPP protocol)

Dependencies:   mbed mtsas

Revision:
1:4c54ec0a3a20
Parent:
0:47bc9ce390cc
Child:
2:99606ba5d1bf
diff -r 47bc9ce390cc -r 4c54ec0a3a20 main.cpp
--- a/main.cpp	Thu Jul 24 18:56:55 2014 +0000
+++ b/main.cpp	Thu Jul 24 21:28:21 2014 +0000
@@ -32,15 +32,46 @@
     //MTSSerialFlowControl* io = new MTSSerialFlowControl(D1, D0, D3, D6);
     
     //Sets the baudrate for communicating with the radio
-    io->baud(115200); 
+    io->baud(115200);
     
     Cellular* radio = CellularFactory::create(io);
-    radio->setApn(APN); 
+    for (int i = 0; i < 10; i++) {
+        if (i >= 10) {
+            printf("Failed to set APN\n");
+        }
+        if (radio->setApn(APN) == MTS_SUCCESS) {
+            printf("Successfully set APN\n");
+            break;
+        } else {
+            wait(1);
+        }
+    }
     
     //Establish PPP link
-    radio->connect();
+    for (int i = 0; i < 10; i++) {
+        if (i >= 10) {
+            printf("Failed to connect to cell network\n");
+        }
+        if (radio->connect() == true) {
+            printf("Successfully established PPP link\n");
+            break;
+        } else {
+            wait(1);
+        }
+    }
     
-    printf("Ping was %s\n", radio->ping() ? "successful" : "unsuccessful"); 
+    //Ping google.com
+    for (int i = 0; i < 10; i++) {
+        if (i >= 10) {
+            printf("Failed to ping google.com\n");
+        }
+        if (radio->ping() == true) {
+            printf("Successfully pinged google.com\n");
+            break;
+        } else {
+            wait(1);
+        }
+    }
     
     //Disconnect ppp link
     radio->disconnect();