From bcf27579684dc495c7e718d6fa60fdad57acbd5f Mon Sep 17 00:00:00 2001 From: Hieromon Ikasamo Date: Tue, 18 Sep 2018 17:27:54 +0900 Subject: [PATCH] Supports ESP32 --- examples/HandleClient/HandleClient.ino | 8 ++++++++ examples/HandlePortal/HandlePortal.ino | 8 ++++++++ examples/HandlePortalEX/HandlePortalEX.ino | 8 ++++++++ examples/mqttRSSI/mqttRSSI.ino | 3 ++- src/AutoConnect.cpp | 2 +- src/AutoConnectPage.cpp | 11 ++++++++++- 6 files changed, 37 insertions(+), 3 deletions(-) diff --git a/examples/HandleClient/HandleClient.ino b/examples/HandleClient/HandleClient.ino index 959b09e..2b16e44 100644 --- a/examples/HandleClient/HandleClient.ino +++ b/examples/HandleClient/HandleClient.ino @@ -22,6 +22,10 @@ ESP8266WebServer server; WebServer server; #endif +#ifndef BUILTIN_LED +#define BUILTIN_LED 2 // backward compatibility +#endif + AutoConnect portal(server); void handleRoot() { @@ -114,7 +118,11 @@ void loop() { server.handleClient(); portal.handleRequest(); // Need to handle AutoConnect menu. if (WiFi.status() == WL_IDLE_STATUS) { +#if defined(ARDUINO_ARCH_ESP8266) ESP.reset(); +#elif defined(ARDUINO_ARCH_ESP32) + ESP.restart(); +#endif delay(1000); } } diff --git a/examples/HandlePortal/HandlePortal.ino b/examples/HandlePortal/HandlePortal.ino index 00357e9..0957ea2 100644 --- a/examples/HandlePortal/HandlePortal.ino +++ b/examples/HandlePortal/HandlePortal.ino @@ -23,6 +23,10 @@ #endif #include +#ifndef BUILTIN_LED +#define BUILTIN_LED 2 // backward compatibility +#endif + AutoConnect portal; void handleRoot() { @@ -116,7 +120,11 @@ void setup() { void loop() { portal.handleClient(); if (WiFi.status() == WL_IDLE_STATUS) { +#if defined(ARDUINO_ARCH_ESP8266) ESP.reset(); +#elif defined(ARDUINO_ARCH_ESP32) + ESP.restart(); +#endif delay(1000); } } diff --git a/examples/HandlePortalEX/HandlePortalEX.ino b/examples/HandlePortalEX/HandlePortalEX.ino index d1b33d1..bd1ecbd 100644 --- a/examples/HandlePortalEX/HandlePortalEX.ino +++ b/examples/HandlePortalEX/HandlePortalEX.ino @@ -25,6 +25,10 @@ #include #include +#ifndef BUILTIN_LED +#define BUILTIN_LED 2 // backward compatibility +#endif + #if defined(ARDUINO_ARCH_ESP8266) ESP8266WebServer server; #elif defined(ARDUINO_ARCH_ESP32) @@ -147,7 +151,11 @@ void setup() { void loop() { portal.handleClient(); if (WiFi.status() == WL_IDLE_STATUS) { +#if defined(ARDUINO_ARCH_ESP8266) ESP.reset(); +#elif defined(ARDUINO_ARCH_ESP32) + ESP.restart(); +#endif delay(1000); } } diff --git a/examples/mqttRSSI/mqttRSSI.ino b/examples/mqttRSSI/mqttRSSI.ino index 5bf7eba..1a16c18 100644 --- a/examples/mqttRSSI/mqttRSSI.ino +++ b/examples/mqttRSSI/mqttRSSI.ino @@ -55,10 +55,11 @@ bool mqttConnect() { } else { Serial.println("Connection failed:" + String(mqttClient.state())); if (!--retry) - return false; + break; } delay(3000); } + return false; } void mqttPublish(String msg) { diff --git a/src/AutoConnect.cpp b/src/AutoConnect.cpp index 07ab8d4..63d914b 100644 --- a/src/AutoConnect.cpp +++ b/src/AutoConnect.cpp @@ -392,7 +392,7 @@ void AutoConnect::onNotFound(WebServerClass::THandlerFunction fn) { bool AutoConnect::_loadAvailCredential() { AutoConnectCredential credential(_apConfig.boundaryOffset); - if (credential.entries() >= 0) { + if (credential.entries() > 0) { // Scan the vicinity only when the saved credentials are existing. int8_t nn = WiFi.scanNetworks(false, true); AC_DBG("%d network(s) found\n", (int)nn); diff --git a/src/AutoConnectPage.cpp b/src/AutoConnectPage.cpp index 7df3e8f..2f01857 100644 --- a/src/AutoConnectPage.cpp +++ b/src/AutoConnectPage.cpp @@ -804,6 +804,11 @@ String AutoConnect::_token_WIFI_MODE(PageArgument& args) { case WIFI_AP_STA: wifiMode = "AP_STA"; break; +#ifdef ARDUINO_ARCH_ESP32 + case WIFI_MODE_MAX: + wifiMode = "MAX"; + break; +#endif } return String(wifiMode); } @@ -855,7 +860,8 @@ String AutoConnect::_token_STATION_STATUS(PageArgument& args) { "CONNECTED", "CONNECT_FAILED", "CONNECTION_LOST", - "DISCONNECTED" + "DISCONNECTED", + "NO_SHIELD" }; st = WiFi.status(); switch (st) { @@ -880,6 +886,9 @@ String AutoConnect::_token_STATION_STATUS(PageArgument& args) { case WL_DISCONNECTED: wlStatusSymbol = wlStatusSymbols[6]; break; + case WL_NO_SHIELD: + wlStatusSymbol = wlStatusSymbols[7]; + break; } #endif