Improve Wifly Interface
Fork of WiflyInterface by
Diff: Wifly/Wifly.cpp
- Revision:
- 12:cd59e53b2cb4
- Parent:
- 11:fc3d86645d23
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) {