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:
76:371aab9902a4
Parent:
73:bb5bbca971ae
Parent:
75:7ad32827b39e
Child:
79:f356009dbc12
--- a/wifi/Wifi.cpp	Thu Dec 26 16:21:11 2013 +0000
+++ b/wifi/Wifi.cpp	Thu Dec 26 16:35:29 2013 +0000
@@ -16,8 +16,11 @@
         return false;
     }
     instance->io = io;
-    //sendCommand("$$$", 1000, Cellular::NONE);
-    return true;
+    if(cmdMode()) {
+        return true;
+    }
+    printf("[ERROR] Failed to enter command mode\r\n");
+    return false;
 }
 
 Wifi::Wifi(MTSBufferedIO* io)
@@ -176,21 +179,6 @@
 {
 }
 
-Code Wifi::echo(bool state)
-{
-    //Code code;
-    if (state) {
-        //code = sendBasicCommand("ATE0", 1000);
-        //set uart mode 1 - Disabled
-        //echoMode = (code == CELL_OK) ? false : echoMode;
-    } else {
-        //code = sendBasicCommand("ATE1", 1000);
-        //set uart mode 0 - Enabled
-        //echoMode = (code == CELL_OK) ? true : echoMode;
-    }
-    return SUCCESS;
-}
-
 Code Wifi::setNetwork(const std::string& ssid, const std::string& key, SecurityType type)
 {
     Code code;
@@ -222,11 +210,27 @@
 
 int Wifi::getSignalStrength()
 {
-    //show rssi
-    return 0;
+    string response = sendCommand("show rssi", 2000);
+    if (response.find("RSSI") == string::npos) {
+        return -1;
+    }
+    int start = response.find('(');
+    int stop = response.find(')', start);
+    string signal = response.substr(start + 1, stop - start - 1);
+    int value;
+    sscanf(signal.c_str(), "%d", &value);
+    return value;
 }
 
-
+bool Wifi::cmdMode()
+{
+    wait(.5);
+    std::string response = sendCommand("$$$", 2000, NONE);
+    if (response.find("CMD") != string::npos) {
+        return true;
+    }
+    return false;
+}
 
 Code Wifi::sendBasicCommand(string command, int timeoutMillis, char esc)
 {