Changes required by X-NUCLEO-IDWM01M1 and mbed-os 5.2.2

Dependencies:   ATParser

Dependents:   X_NUCLEO_IDW01M1v2-lapi-1

Fork of SPWF01SA by ST

Files at this revision

API Documentation at this revision

Comitter:
lapi
Date:
Sun Nov 20 20:20:25 2016 +0000
Parent:
23:0b01aa59bb6f
Commit message:
Changes required by X-NUCLEO-IDW01M1 and the new version of mbed-os

Changed in this revision

SPWFSA01.cpp Show annotated file Show diff for this revision Revisions of this file
SPWFSA01.h Show annotated file Show diff for this revision Revisions of this file
--- a/SPWFSA01.cpp	Thu Nov 03 06:53:47 2016 +0000
+++ b/SPWFSA01.cpp	Sun Nov 20 20:20:25 2016 +0000
@@ -23,13 +23,10 @@
 #define SPWFSA01_MISC_TIMEOUT       500
 #define SPWFSA01_SOCKQ_TIMEOUT      3000
 
-SPWFSA01::SPWFSA01(PinName tx, PinName rx, bool debug)
-    : _serial(tx, rx, 1024), _parser(_serial),
-      _wakeup(D14, PIN_INPUT, PullNone, 0), _reset(D15, PIN_INPUT, PullNone, 1),
-      //PC_12->D15, PC_8->D14 (re-wires needed in-case used, currently not used)
-      dbg_on(debug)
-      //Pin PC_8 is wakeup pin
-      //Pin PA_12 is reset pin
+SPWFSA01::SPWFSA01(PinName tx, PinName rx, bool debug, PinName resetPin, PinName wakeupPin) :
+        _serial(tx, rx, 1024), _parser(_serial),
+        _reset(resetPin, PIN_INPUT, PullNone, 1), _wakeup(wakeupPin, PIN_INPUT, PullNone, 0),
+        dbg_on(debug)
 {
     _serial.baud(115200);
     _reset.output();
@@ -115,12 +112,13 @@
 void SPWFSA01::waitSPWFReady(void)
 {
     //wait_ms(200);
-    while(1) 
-        if(_parser.send("AT") && _parser.recv("OK"))
+    while(1) {
+        if(_parser.send("AT") && _parser.recv("OK")) {
             //till we get OK from AT command
-            //printf("\r\nwaiting for reset to complete..\n");
+            printf("\r\nwaiting for SPWFSA01 Ready..\n");
             return;
-                
+        }
+    }  
 }
 
 /* Security Mode
@@ -128,7 +126,7 @@
     WEP           = 1,
     WPA_Personal  = 2,
 */
-bool SPWFSA01::connect(const char *ap, const char *passPhrase, int securityMode)
+bool SPWFSA01::connect(const char *ap, const char *passPhrase, int securityMode, int channel)
 {
     uint32_t n1, n2, n3, n4;
     
@@ -144,6 +142,12 @@
             debug_if(dbg_on, "SPWF> error ssid set\r\n");
             return false;
         }
+    //AT+S.SCFG=wifi_auth_type,%d\r, is 1 for WEP, 0 for none and WPA/WPA2
+    if(!(_parser.send("AT+S.SCFG=wifi_auth_type,%d", securityMode == 1 ? 1 : 0) && _parser.recv("OK"))) 
+        {
+            debug_if(dbg_on, "SPWF> error auth type set\r\n");
+            return false;
+        } 
     //AT+S.SCFG=wifi_priv_mode,%d\r
     if(!(_parser.send("AT+S.SCFG=wifi_priv_mode,%d", securityMode) && _parser.recv("OK"))) 
         {
@@ -157,6 +161,13 @@
             debug_if(dbg_on, "SPWF> error wifi mode set\r\n");
             return false;
         }
+    //"AT+S.SCFG=wifi_channelnum,%d\r"
+    /*set channel*/
+    if(!(_parser.send("AT+S.SCFG=wifi_channelnum,%d\r", channel) && _parser.recv("OK")))
+        {
+            debug_if(dbg_on, "SPWF> error wifi channel set\r\n");
+            return false;
+        }
     //AT&W
     /* save current setting in flash */
     if(!(_parser.send("AT&W") && _parser.recv("OK")))
@@ -210,6 +221,21 @@
 }
 
 
+int8_t SPWFSA01::getRSSI(void)
+{
+    int32_t rssi;
+    
+    if (!(_parser.send("AT+S.RCFG=rx_rssi")
+        && _parser.recv("#  rx_rssi = %d", &rssi)
+        && _parser.recv("OK"))) {
+            debug_if(dbg_on, "SPWF> getIPAddress error\r\n");
+        return 0;
+    }
+    
+    return (int8_t)rssi;
+}
+
+
 const char *SPWFSA01::getIPAddress(void)
 {
     uint32_t n1, n2, n3, n4;
--- a/SPWFSA01.h	Thu Nov 03 06:53:47 2016 +0000
+++ b/SPWFSA01.h	Sun Nov 20 20:20:25 2016 +0000
@@ -25,7 +25,9 @@
 class SPWFSA01
 {
 public:
-    SPWFSA01(PinName tx, PinName rx, bool debug=false);
+    //Pin PC_8 is wakeup pin, Pin PC_12 reset pin with X-NUCLEO-IDW01M1
+    SPWFSA01(PinName tx, PinName rx, bool debug=false, 
+             PinName resetPin=PC_12, PinName wakeupPin = PC_8);
  
     /**
     * Init the SPWFSA01
@@ -59,9 +61,10 @@
     * @param ap the name of the AP
     * @param passPhrase the password of AP
     * @param securityMode the security mode of AP (WPA/WPA2, WEP, Open)
+    * @param channel the WiFi channel number
     * @return true only if SPWFSA01 is connected successfully
     */
-    bool connect(const char *ap, const char *passPhrase, int securityMode);
+    bool connect(const char *ap, const char *passPhrase, int securityMode, int channel);
  
     /**
     * Disconnect SPWFSA01 from AP
@@ -70,6 +73,14 @@
     */
     bool disconnect(void);
  
+    
+    /**
+    * Get the RSSI of the last packet
+    *
+    * @return the RSSI (dBm)
+    */
+    int8_t getRSSI(void);
+    
     /**
     * Get the IP address of SPWFSA01
     *