A library for talking to Multi-Tech's Cellular SocketModem Devices.

Dependents:   M2X_dev axeda_wrapper_dev MTS_M2x_Example1 MTS_Cellular_Connect_Example ... more

Revision:
115:b26176f23e89
Parent:
105:1977b7154940
--- a/tests/blinky_ping_test.h	Tue Dec 31 17:32:57 2013 +0000
+++ b/tests/blinky_ping_test.h	Tue Dec 31 21:47:11 2013 +0000
@@ -1,24 +1,35 @@
 #include "mbed.h"
 #include "include_me.h"
 
-using namespace mts;
-
 #define MAX_TRIES 5
 #define MAX_REGISTRATION_TRIES 10
 
-bool ping_test(const std::string& apn, const std::string& server);
+#define CELL_SHIELD 0 // if using a cell shield board, change to 1
+
+using namespace mts;
+
+/* APN is ignored if using wifi */
+bool cellPingTest(const std::string& apn, const std::string& server);
+bool wifiPingTest(const std::string& server, const std::string& ssid, Wifi::SecurityType type, const std::string& key);
 void blinkLed(DigitalOut led);
 
-void blinkyPingTest() {
+void pingTest() {
     DigitalOut ledG(LED1);
     DigitalOut ledR(LED2);
-    std::string apn = "wap.cingular";
-    std::string server = "8.8.8.8";
     
     ledG = 1;
     ledR = 1;
-        
-    if (ping_test(apn, server)) {
+    
+    std::string server = "8.8.8.8"; // Google's DNS server
+#if CELL_SHIELD
+    std::string apn = "wap.cingular"; // APN of sim card
+    if (cellPingTest(apn, server)) {
+#else
+    std::string ssid = "Mtech_guest"; // ssid of wireless network
+    Wifi::SecurityType type = Wifi::WPA2; // NONE, WEP64, WEP128, WPA, WPA2
+    std::string key = "MultiModem2!"; // password for network (if type is not "NONE")
+    if (wifiPingTest(server, ssid, type, key)) {
+#endif
         printf("success!\n\r");
         blinkLed(ledG);
     } else {
@@ -27,9 +38,59 @@
     }
 }
 
-bool ping_test(const std::string& apn, const std::string& server) {
+bool wifiPingTest(const std::string& server, const std::string& ssid, Wifi::SecurityType type, const std::string& key) {
     int i;
     
+    Transport::setTransport(Transport::WIFI);
+    MTSSerial* serial = new MTSSerial(PTD3, PTD2, 256, 256);
+    serial->baud(9600);
+    Wifi* wifi = Wifi::getInstance();
+    wifi->init(serial);
+    
+    printf("waiting for radio to come up\r\n");
+    wait(5);
+    
+    i = 0;
+    while (i++ < MAX_TRIES) {
+        if (wifi->setNetwork(ssid, type, key) == SUCCESS) {
+            printf("set network\r\n");
+            break;
+        } else {
+            printf("failed to set network\r\n");
+        }
+        wait(1);
+    }
+    
+    i = 0;
+    while (i++ < MAX_TRIES) {
+        if (wifi->setDeviceIP() == SUCCESS) {
+            printf("set IP\r\n");
+            break;
+        } else {
+            printf("failed to set IP\r\n");
+        }
+        wait(1);
+    }
+        
+    i = 0;
+    while (i++ < MAX_TRIES) {
+        if (wifi->connect()) {
+            printf("connected\r\n");
+            break;
+        } else {
+            printf("failed to connect\r\n");
+        }
+        wait(1);
+    }
+    
+    printf("pinging %s\n\r", server.c_str());
+    return wifi->ping(server);
+}
+
+bool cellPingTest(const std::string& apn, const std::string& server) {
+    int i;
+    
+    Transport::setTransport(Transport::CELLULAR);
     MTSSerialFlowControl* serial = new MTSSerialFlowControl(PTD3, PTD2, PTA12, PTC8);
     serial->baud(115200);
     Cellular* cell = Cellular::getInstance();
@@ -50,8 +111,6 @@
         wait(3);
     }
     
-    printf("signal strength: %d\n\r", cell->getSignalStrength());
-
     i = 0;
     printf("setting APN to %s\n\r", apn.c_str());
     while (i++ < MAX_TRIES) {