Browse Source

Wait X milliseconds for autoConnection and skip non-defined SSIDs

fastled
Xose Pérez 8 years ago
parent
commit
10ae26da46
1 changed files with 17 additions and 3 deletions
  1. +17
    -3
      code/lib/JustWifi/JustWifi.cpp

+ 17
- 3
code/lib/JustWifi/JustWifi.cpp View File

@ -30,19 +30,30 @@ bool JustWifi::connected() {
bool JustWifi::autoConnect() { bool JustWifi::autoConnect() {
unsigned long timeout;
// Return if already connected // Return if already connected
if (connected()) return true; if (connected()) return true;
// Try to connect to last successful network // Try to connect to last successful network
WiFi.mode(WIFI_STA);
if (WiFi.SSID()) {
if (WiFi.SSID().length() > 0) {
_doCallback(MESSAGE_AUTO_CONNECTING, (char *) WiFi.SSID().c_str());
ETS_UART_INTR_DISABLE(); ETS_UART_INTR_DISABLE();
wifi_station_disconnect(); wifi_station_disconnect();
ETS_UART_INTR_ENABLE(); ETS_UART_INTR_ENABLE();
_doCallback(MESSAGE_AUTO_CONNECTING, (char *) WiFi.SSID().c_str());
WiFi.mode(WIFI_STA);
WiFi.begin(); WiFi.begin();
// Check connection with timeout
timeout = millis();
while (millis() - timeout < _connect_timeout) {
_doCallback(MESSAGE_CONNECT_WAITING);
if (WiFi.status() == WL_CONNECTED) break;
delay(100);
}
if (WiFi.status() == WL_CONNECTED) { if (WiFi.status() == WL_CONNECTED) {
_mode = MODE_STATION; _mode = MODE_STATION;
_doCallback(MESSAGE_CONNECTED); _doCallback(MESSAGE_CONNECTED);
@ -72,6 +83,9 @@ bool JustWifi::connect() {
// Loop through configured networks // Loop through configured networks
for (unsigned char i=0; i<_network_count; i++) { for (unsigned char i=0; i<_network_count; i++) {
// Skip if no SSID defined
if (_network[i].ssid.length() == 0) continue;
// TODO: Static IP options here // TODO: Static IP options here
// Connect // Connect


Loading…
Cancel
Save