Improve Wifly Interface

Fork of WiflyInterface by Components

Files at this revision

API Documentation at this revision

Comitter:
jollen
Date:
Mon Jun 08 11:22:09 2015 +0000
Parent:
11:fc3d86645d23
Commit message:
Improvement of Wifly Interface

Changed in this revision

Wifly/Wifly.cpp Show annotated file Show diff for this revision Revisions of this file
Wifly/Wifly.h Show annotated file Show diff for this revision Revisions of this file
WiflyInterface.cpp Show annotated file Show diff for this revision Revisions of this file
WiflyInterface.h Show annotated file Show diff for this revision Revisions of this file
diff -r fc3d86645d23 -r cd59e53b2cb4 Wifly/Wifly.cpp
--- a/Wifly/Wifly.cpp	Tue Jun 03 18:43:14 2014 +0000
+++ b/Wifly/Wifly.cpp	Mon Jun 08 11:22:09 2015 +0000
@@ -175,6 +175,34 @@
     return false;
 }
 
+bool Wifly::joinSSID()
+{
+    char cmd[20];
+            
+        // auto join
+        if (!sendCommand("set w j 1\r", "AOK"))
+            return false;
+
+        //key step
+        if (state.sec != NONE) {
+            if (state.sec == WPA)
+                sprintf(cmd, "set w p %s\r", phrase);
+            else if (state.sec == WEP_128)
+                sprintf(cmd, "set w k %s\r", phrase);
+
+            if (!sendCommand(cmd, "AOK", NULL, 1000))
+                return false;
+        }
+        
+        //join the network
+        sprintf(cmd, "join %s\r", ssid);
+        if (!sendCommand(cmd, "Associated", NULL, 2000))
+            return false;
+
+        state.associated = true;
+        INFO("\r\nssid: %s\r\nphrase: %s\r\nsecurity: %s\r\n\r\n", this->ssid, this->phrase, getStringSecurity());
+        return true;
+}
 
 bool Wifly::setProtocol(Protocol p)
 {
diff -r fc3d86645d23 -r cd59e53b2cb4 Wifly/Wifly.h
--- a/Wifly/Wifly.h	Tue Jun 03 18:43:14 2014 +0000
+++ b/Wifly/Wifly.h	Mon Jun 08 11:22:09 2015 +0000
@@ -72,6 +72,13 @@
     bool join();
 
     /**
+    * Connect the wifi module to the ssid contained in the constructor.
+    *
+    * @return true if connected, false otherwise
+    */
+    bool joinSSID();
+    
+    /**
     * Disconnect the wifly module from the access point
     *
     * @return true if successful
diff -r fc3d86645d23 -r cd59e53b2cb4 WiflyInterface.cpp
--- a/WiflyInterface.cpp	Tue Jun 03 18:43:14 2014 +0000
+++ b/WiflyInterface.cpp	Mon Jun 08 11:22:09 2015 +0000
@@ -32,6 +32,11 @@
     return join();
 }
 
+int WiflyInterface::reConnect()
+{
+    return joinSSID();
+}
+
 int WiflyInterface::disconnect()
 {
     return Wifly::disconnect();
diff -r fc3d86645d23 -r cd59e53b2cb4 WiflyInterface.h
--- a/WiflyInterface.h	Tue Jun 03 18:43:14 2014 +0000
+++ b/WiflyInterface.h	Mon Jun 08 11:22:09 2015 +0000
@@ -61,6 +61,12 @@
   * \return 0 on success, a negative number on failure
   */
   int connect();
+
+  /** reConnect
+  * Retry join
+  * \return 0 on success, a negative number on failure
+  */
+  int reConnect();
   
   /** Disconnect
   * Bring the interface down