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:
103:da58d27c15d7
Parent:
100:9d96b4391151
Child:
106:358972176b89
--- a/wifi/Wifi.cpp	Mon Dec 30 22:54:55 2013 +0000
+++ b/wifi/Wifi.cpp	Mon Dec 30 23:55:43 2013 +0000
@@ -87,10 +87,6 @@
         return false;
     }
 
-    //Check RSSI: AT+CSQ
-    int rssi = getSignalStrength();
-    printf("[DEBUG] Signal strength (dBm): %d\r\n", rssi);
-
     //Possibly add a scan command here and look for the network....
 
     //Set device into DHCP mode
@@ -110,6 +106,11 @@
         local_address = result.substr(start + 3, stop - start - 3);
         printf("[INFO] WiFi Connection Established: IP[%s]\r\n", local_address.c_str());
         wifiConnected = true;
+        
+        //Report Signal Strength of new connection
+        wait(1); //Needed for signal strength to be available
+        int rssi = getSignalStrength();
+        printf("[DEBUG] Signal strength (dBm): %d\r\n", rssi);
     } else {
         wifiConnected = false;
     }
@@ -364,13 +365,13 @@
     }
 
     int bytesWritten = 0;
-    
+
     if(timeout >= 0) {
         bytesWritten = io->write(data, length, static_cast<unsigned int>(timeout));
     } else {
         bytesWritten = io->write(data, length);
     }
-    
+
     return bytesWritten;
 }
 
@@ -405,7 +406,7 @@
 {
 }
 
-Code Wifi::setNetwork(const std::string& ssid, const std::string& key, SecurityType type)
+Code Wifi::setNetwork(const std::string& ssid, SecurityType type, const std::string& key)
 {
     //Check the command mode
     if(!setCmdMode(true)) {
@@ -451,16 +452,22 @@
 
 int Wifi::getSignalStrength()
 {
+    //Signal strength does not report correctly if not connected
+    if(!wifiConnected) {
+        printf("[ERROR] Could not get RSSI, Wifi network not connected.\n\r");
+        return 99;
+    }
+
     //Check the command mode
     if(!setCmdMode(true)) {
         printf("[ERROR] Could not get RSSI\n\r");
-        return -1;
+        return 99;
     }
 
     string response = sendCommand("show rssi", 2000, "dBm");
     if (response.find("RSSI") == string::npos) {
         printf("[ERROR] Could not get RSSI\n\r");
-        return -1;
+        return 99;
     }
     int start = response.find('(');
     int stop = response.find(')', start);