This commit is contained in:
Magnus Persson 2022-04-28 20:01:45 +02:00
parent 8dcadf4240
commit 304903564d
18 changed files with 215 additions and 5088 deletions

View File

@ -101,6 +101,10 @@
<div class="col-md-4 bg-light">Platform:</div>
<div class="col-md-4 bg-light" id="platform">Loading...</div>
</div>
<div class="row mb-3">
<div class="col-md-4 bg-light">SSID:</div>
<div class="col-md-4 bg-light" id="wifi-ssid">Loading...</div>
</div>
<script>
$("#log-btn").click(function(e){
@ -198,6 +202,7 @@
$("#mdns").text(cfg["mdns"]);
$("#id").text(cfg["id"]);
$("#platform").text(cfg["platform"]);
$("#wifi-ssid").text(cfg["wifi-ssid"]);
$("#runtime").text(cfg["runtime-average"] + " seconds");
var angle = cfg["angle"];

File diff suppressed because one or more lines are too long

View File

@ -1,399 +0,0 @@
/****************************************************************************************************************************
ESP_DoubleResetDetector.h
For ESP8266 / ESP32 boards
ESP_DoubleResetDetector is a library for the ESP8266/Arduino platform
to enable trigger configure mode by resetting ESP32 / ESP8266 twice.
Forked from DataCute https://github.com/datacute/DoubleResetDetector
Built by Khoi Hoang https://github.com/khoih-prog/ESP_DoubleResetDetector
Licensed under MIT license
Version: 1.3.1
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K Hoang 15/12/2019 Initial coding
1.0.1 K Hoang 30/12/2019 Now can use EEPROM or SPIFFS for both ESP8266 and ESP32. RTC still OK for ESP8266
1.0.2 K Hoang 10/04/2020 Fix bug by left-over cpp file and in example.
1.0.3 K Hoang 13/05/2020 Update to use LittleFS for ESP8266 core 2.7.1+
1.1.0 K Hoang 04/12/2020 Add support to LittleFS for ESP32 using LITTLEFS Library
1.1.1 K Hoang 28/12/2020 Suppress all possible compiler warnings
1.1.2 K Hoang 10/10/2021 Update `platform.ini` and `library.json`
1.2.0 K Hoang 26/11/2021 Auto detect ESP32 core and use either built-in LittleFS or LITTLEFS library
1.2.1 K Hoang 26/11/2021 Fix compile error for ESP32 core v1.0.5-
1.3.0 K Hoang 10/02/2022 Add support to new ESP32-S3
1.3.1 K Hoang 04/03/2022 Add waitingForDRD() function to signal in DRD wating period
*****************************************************************************************************************************/
#pragma once
#ifndef ESP_DoubleResetDetector_H
#define ESP_DoubleResetDetector_H
#ifndef DOUBLERESETDETECTOR_DEBUG
#define DOUBLERESETDETECTOR_DEBUG false
#endif
#if defined(ARDUINO) && (ARDUINO >= 100)
#include <Arduino.h>
#else
#include <WProgram.h>
#endif
#ifndef ESP_DOUBLE_RESET_DETECTOR_VERSION
#define ESP_DOUBLE_RESET_DETECTOR_VERSION "ESP_DoubleResetDetector v1.3.1"
#define ESP_DOUBLE_RESET_DETECTOR_VERSION_MAJOR 1
#define ESP_DOUBLE_RESET_DETECTOR_VERSION_MINOR 3
#define ESP_DOUBLE_RESET_DETECTOR_VERSION_PATCH 1
#define ESP_DOUBLE_RESET_DETECTOR_VERSION_INT 1003001
#endif
#define ESP_DOUBLERESETDETECTOR_VERSION ESP_DOUBLE_RESET_DETECTOR_VERSION
//#define ESP_DRD_USE_EEPROM false
//#define ESP_DRD_USE_LITTLEFS false
//#define ESP_DRD_USE_SPIFFS false
//#define ESP8266_DRD_USE_RTC false //true
#ifdef ESP32
#if (!ESP_DRD_USE_EEPROM && !ESP_DRD_USE_SPIFFS && !ESP_DRD_USE_LITTLEFS)
#if (DOUBLERESETDETECTOR_DEBUG)
#warning Neither EEPROM, SPIFFS nor LittleFS selected. Default to EEPROM
#endif
#ifdef ESP_DRD_USE_EEPROM
#undef ESP_DRD_USE_EEPROM
#define ESP_DRD_USE_EEPROM true
#endif
#endif
#endif
#ifdef ESP8266
#if (!ESP8266_DRD_USE_RTC && !ESP_DRD_USE_EEPROM && !ESP_DRD_USE_SPIFFS && !ESP_DRD_USE_LITTLEFS)
#if (DOUBLERESETDETECTOR_DEBUG)
#warning Neither RTC, EEPROM, LITTLEFS nor SPIFFS selected. Default to EEPROM
#endif
#ifdef ESP_DRD_USE_EEPROM
#undef ESP_DRD_USE_EEPROM
#define ESP_DRD_USE_EEPROM true
#endif
#endif
#endif
//default to use EEPROM, otherwise, use LITTLEFS (higher priority), then SPIFFS
#if ESP_DRD_USE_EEPROM
#include <EEPROM.h>
#define FLAG_DATA_SIZE 4
#ifndef EEPROM_SIZE
#define EEPROM_SIZE 512
#endif
#ifndef EEPROM_START
#define EEPROM_START 256
#endif
#elif ( ESP_DRD_USE_LITTLEFS || ESP_DRD_USE_SPIFFS )
#include <FS.h>
#ifdef ESP32
#if ESP_DRD_USE_LITTLEFS
// Check cores/esp32/esp_arduino_version.h and cores/esp32/core_version.h
//#if ( ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(2, 0, 0) ) //(ESP_ARDUINO_VERSION_MAJOR >= 2)
#if ( defined(ESP_ARDUINO_VERSION_MAJOR) && (ESP_ARDUINO_VERSION_MAJOR >= 2) )
#if (DOUBLERESETDETECTOR_DEBUG)
#warning Using ESP32 Core 1.0.6 or 2.0.0+
#endif
// The library has been merged into esp32 core from release 1.0.6
#include <LittleFS.h>
#define FileFS LittleFS
#define FS_Name "LittleFS"
#else
#if (DOUBLERESETDETECTOR_DEBUG)
#warning Using ESP32 Core 1.0.5-. You must install LITTLEFS library
#endif
// The library has been merged into esp32 core from release 1.0.6
#include <LITTLEFS.h> // https://github.com/lorol/LITTLEFS
#define FileFS LITTLEFS
#define FS_Name "LittleFS"
#endif
#else
#include "SPIFFS.h"
// ESP32 core 1.0.4 still uses SPIFFS
#define FileFS SPIFFS
#endif
#else
// From ESP8266 core 2.7.1
#include <LittleFS.h>
#if ESP_DRD_USE_LITTLEFS
#define FileFS LittleFS
#else
#define FileFS SPIFFS
#endif
#endif // #if ESP_DRD_USE_EEPROM
#define DRD_FILENAME "/drd.dat"
#endif //#if ESP_DRD_USE_EEPROM
#define DOUBLERESETDETECTOR_FLAG_SET 0xD0D01234
#define DOUBLERESETDETECTOR_FLAG_CLEAR 0xD0D04321
class DoubleResetDetector
{
public:
DoubleResetDetector(int timeout, int address)
{
#if ESP_DRD_USE_EEPROM
#if (DOUBLERESETDETECTOR_DEBUG)
Serial.printf("EEPROM size = %d, start = %d\n", EEPROM_SIZE, EEPROM_START);
#endif
EEPROM.begin(EEPROM_SIZE);
#elif ( ESP_DRD_USE_LITTLEFS || ESP_DRD_USE_SPIFFS )
// LittleFS / SPIFFS code
if (!FileFS.begin())
{
#if (DOUBLERESETDETECTOR_DEBUG)
#if ESP_DRD_USE_LITTLEFS
Serial.println("LittleFS failed!. Please use SPIFFS or EEPROM.");
#else
Serial.println("SPIFFS failed!. Please use LittleFS or EEPROM.");
#endif
#endif
}
#else
#ifdef ESP8266
//RTC only for ESP8266
#endif
#endif
this->timeout = timeout * 1000;
this->address = address;
doubleResetDetected = false;
waitingForDoubleReset = false;
};
bool detectDoubleReset()
{
doubleResetDetected = detectRecentlyResetFlag();
if (doubleResetDetected)
{
#if (DOUBLERESETDETECTOR_DEBUG)
Serial.println("doubleResetDetected");
#endif
clearRecentlyResetFlag();
}
else
{
#if (DOUBLERESETDETECTOR_DEBUG)
Serial.println("No doubleResetDetected");
#endif
setRecentlyResetFlag();
waitingForDoubleReset = true;
}
return doubleResetDetected;
};
bool waitingForDRD()
{
return waitingForDoubleReset;
}
void loop()
{
if (waitingForDoubleReset && millis() > timeout)
{
#if (DOUBLERESETDETECTOR_DEBUG)
Serial.println("Stop doubleResetDetecting");
#endif
stop();
}
};
void stop()
{
clearRecentlyResetFlag();
waitingForDoubleReset = false;
};
bool doubleResetDetected;
private:
uint32_t DOUBLERESETDETECTOR_FLAG;
unsigned long timeout;
int address;
bool waitingForDoubleReset;
bool detectRecentlyResetFlag()
{
#if (ESP_DRD_USE_EEPROM)
EEPROM.get(EEPROM_START, DOUBLERESETDETECTOR_FLAG);
doubleResetDetectorFlag = DOUBLERESETDETECTOR_FLAG;
#if (DOUBLERESETDETECTOR_DEBUG)
Serial.printf("EEPROM Flag read = 0x%X\n", DOUBLERESETDETECTOR_FLAG);
#endif
#elif ( ESP_DRD_USE_LITTLEFS || ESP_DRD_USE_SPIFFS )
// LittleFS / SPIFFS code
if (FileFS.exists(DRD_FILENAME))
{
// if config file exists, load
File file = FileFS.open(DRD_FILENAME, "r");
if (!file)
{
#if (DOUBLERESETDETECTOR_DEBUG)
Serial.println("Loading config file failed");
#endif
}
file.readBytes((char *) &DOUBLERESETDETECTOR_FLAG, sizeof(DOUBLERESETDETECTOR_FLAG));
doubleResetDetectorFlag = DOUBLERESETDETECTOR_FLAG;
#if (DOUBLERESETDETECTOR_DEBUG)
#if ESP_DRD_USE_LITTLEFS
Serial.printf("LittleFS Flag read = 0x%X\n", DOUBLERESETDETECTOR_FLAG);
#else
Serial.printf("SPIFFS Flag read = 0x%X\n", DOUBLERESETDETECTOR_FLAG);
#endif
#endif
file.close();
}
#else
#ifdef ESP8266
//RTC only for ESP8266
ESP.rtcUserMemoryRead(address, &doubleResetDetectorFlag, sizeof(doubleResetDetectorFlag));
#endif
#endif
doubleResetDetected = (doubleResetDetectorFlag == DOUBLERESETDETECTOR_FLAG_SET);
return doubleResetDetected;
};
void setRecentlyResetFlag()
{
doubleResetDetectorFlag = DOUBLERESETDETECTOR_FLAG_SET;
DOUBLERESETDETECTOR_FLAG = DOUBLERESETDETECTOR_FLAG_SET;
#if (ESP_DRD_USE_EEPROM)
EEPROM.put(EEPROM_START, DOUBLERESETDETECTOR_FLAG);
EEPROM.commit();
#if (DOUBLERESETDETECTOR_DEBUG)
delay(1000);
EEPROM.get(EEPROM_START, DOUBLERESETDETECTOR_FLAG);
Serial.printf("SetFlag write = 0x%X\n", DOUBLERESETDETECTOR_FLAG);
#endif
#elif ( ESP_DRD_USE_LITTLEFS || ESP_DRD_USE_SPIFFS )
// LittleFS / SPIFFS code
File file = FileFS.open(DRD_FILENAME, "w");
#if (DOUBLERESETDETECTOR_DEBUG)
Serial.println("Saving config file...");
#endif
if (file)
{
file.write((uint8_t *) &DOUBLERESETDETECTOR_FLAG, sizeof(DOUBLERESETDETECTOR_FLAG));
file.close();
#if (DOUBLERESETDETECTOR_DEBUG)
Serial.println("Saving config file OK");
#endif
}
else
{
#if (DOUBLERESETDETECTOR_DEBUG)
Serial.println("Saving config file failed");
#endif
}
#else
#ifdef ESP8266
//RTC only for ESP8266
ESP.rtcUserMemoryWrite(address, &doubleResetDetectorFlag, sizeof(doubleResetDetectorFlag));
#endif
#endif
};
void clearRecentlyResetFlag()
{
doubleResetDetectorFlag = DOUBLERESETDETECTOR_FLAG_CLEAR;
DOUBLERESETDETECTOR_FLAG = DOUBLERESETDETECTOR_FLAG_CLEAR;
#if (ESP_DRD_USE_EEPROM)
//DOUBLERESETDETECTOR_FLAG = DOUBLERESETDETECTOR_FLAG_CLEAR;
EEPROM.put(EEPROM_START, DOUBLERESETDETECTOR_FLAG);
EEPROM.commit();
#if (DOUBLERESETDETECTOR_DEBUG)
delay(1000);
EEPROM.get(EEPROM_START, DOUBLERESETDETECTOR_FLAG);
Serial.printf("ClearFlag write = 0x%X\n", DOUBLERESETDETECTOR_FLAG);
#endif
#elif ( ESP_DRD_USE_LITTLEFS || ESP_DRD_USE_SPIFFS )
// LittleFS / SPIFFS code
File file = FileFS.open(DRD_FILENAME, "w");
#if (DOUBLERESETDETECTOR_DEBUG)
Serial.println("Saving config file...");
#endif
if (file)
{
file.write((uint8_t *) &DOUBLERESETDETECTOR_FLAG, sizeof(DOUBLERESETDETECTOR_FLAG));
file.close();
#if (DOUBLERESETDETECTOR_DEBUG)
Serial.println("Saving config file OK");
#endif
}
else
{
#if (DOUBLERESETDETECTOR_DEBUG)
Serial.println("Saving config file failed");
#endif
}
#else
#ifdef ESP8266
//RTC only for ESP8266
ESP.rtcUserMemoryWrite(address, &doubleResetDetectorFlag, sizeof(doubleResetDetectorFlag));
#endif
#endif
};
uint32_t doubleResetDetectorFlag;
};
#endif // ESP_DoubleResetDetector_H

File diff suppressed because it is too large Load Diff

View File

@ -1,74 +0,0 @@
/****************************************************************************************************************************
ESP_WiFiManager.h
For ESP8266 / ESP32 boards
ESP_WiFiManager is a library for the ESP8266/Arduino platform
(https://github.com/esp8266/Arduino) to enable easy
configuration and reconfiguration of WiFi credentials using a Captive Portal
inspired by:
http://www.esp8266.com/viewtopic.php?f=29&t=2520
https://github.com/chriscook8/esp-arduino-apboot
https://github.com/esp8266/Arduino/blob/master/libraries/DNSServer/examples/CaptivePortalAdvanced/
Modified from Tzapu https://github.com/tzapu/WiFiManager
and from Ken Taylor https://github.com/kentaylor
Built by Khoi Hoang https://github.com/khoih-prog/ESP_WiFiManager
Licensed under MIT license
Version: 1.10.1
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K Hoang 07/10/2019 Initial coding
1.0.1 K Hoang 13/12/2019 Fix bug. Add features. Add support for ESP32
1.0.2 K Hoang 19/12/2019 Fix bug thatkeeps ConfigPortal in endless loop if Portal/Router SSID or Password is NULL.
1.0.3 K Hoang 05/01/2020 Option not displaying AvailablePages in Info page. Enhance README.md. Modify examples
1.0.4 K Hoang 07/01/2020 Add RFC952 setHostname feature.
1.0.5 K Hoang 15/01/2020 Add configurable DNS feature. Thanks to @Amorphous of https://community.blynk.cc
1.0.6 K Hoang 03/02/2020 Add support for ArduinoJson version 6.0.0+ ( tested with v6.14.1 )
1.0.7 K Hoang 13/04/2020 Reduce start time, fix SPIFFS bug in examples, update README.md
1.0.8 K Hoang 10/06/2020 Fix STAstaticIP issue. Restructure code. Add LittleFS support for ESP8266 core 2.7.1+
1.0.9 K Hoang 29/07/2020 Fix ESP32 STAstaticIP bug. Permit changing from DHCP <-> static IP using Config Portal.
Add, enhance examples (fix MDNS for ESP32)
1.0.10 K Hoang 08/08/2020 Add more features to Config Portal. Use random WiFi AP channel to avoid conflict.
1.0.11 K Hoang 17/08/2020 Add CORS feature. Fix bug in softAP, autoConnect, resetSettings.
1.1.0 K Hoang 28/08/2020 Add MultiWiFi feature to autoconnect to best WiFi at runtime
1.1.1 K Hoang 30/08/2020 Add setCORSHeader function to allow flexible CORS. Fix typo and minor improvement.
1.1.2 K Hoang 17/08/2020 Fix bug. Add example.
1.2.0 K Hoang 09/10/2020 Restore cpp code besides Impl.h code to use if linker error. Fix bug.
1.3.0 K Hoang 04/12/2020 Add LittleFS support to ESP32 using LITTLEFS Library
1.4.1 K Hoang 22/12/2020 Fix staticIP not saved. Add functions. Add complex examples. Sync with ESPAsync_WiFiManager
1.4.2 K Hoang 14/01/2021 Fix examples' bug not using saved WiFi Credentials after losing all WiFi connections.
1.4.3 K Hoang 23/01/2021 Fix examples' bug not saving Static IP in certain cases.
1.5.0 K Hoang 12/02/2021 Add support to new ESP32-S2
1.5.1 K Hoang 26/03/2021 Fix compiler error if setting Compiler Warnings to All. Retest with esp32 core v1.0.6
1.5.2 K Hoang 08/04/2021 Fix example misleading messages.
1.5.3 K Hoang 13/04/2021 Add dnsServer error message.
1.6.0 K Hoang 20/04/2021 Add support to new ESP32-C3 using SPIFFS or EEPROM
1.6.1 K Hoang 25/04/2021 Fix MultiWiFi bug. Fix captive-portal bug if CP AP address is not default 192.168.4.1
1.7.0 K Hoang 06/05/2021 Set _timezoneName. Add support to new ESP32-S2 (METRO_ESP32S2, FUNHOUSE_ESP32S2, etc.)
1.7.1 K Hoang 08/05/2021 Fix Json bug. Fix timezoneName not displayed in Info page.
1.7.2 K Hoang 08/05/2021 Fix warnings with ESP8266 core v3.0.0
1.7.3 K Hoang 29/07/2021 Fix MultiWiFi connection issue with ESP32 core v2.0.0-rc1+
1.7.4 K Hoang 13/08/2021 Add WiFi scanning of hidden SSIDs
1.7.5 K Hoang 10/10/2021 Update `platform.ini` and `library.json`
1.7.6 K Hoang 26/11/2021 Auto detect ESP32 core and use either built-in LittleFS or LITTLEFS library
1.7.7 K Hoang 26/11/2021 Fix compile error for ESP32 core v1.0.5-
1.7.8 K Hoang 30/11/2021 Fix bug to permit using HTTP port different from 80. Fix bug
1.8.0 K Hoang 29/12/2021 Fix `multiple-definitions` linker error and weird bug related to src_cpp
1.9.0 K Hoang 17/01/2022 Enable compatibility with old code to include only ESP_WiFiManager.h
1.10.0 K Hoang 10/02/2022 Add support to new ESP32-S3
1.10.1 K Hoang 11/02/2022 Add LittleFS support to ESP32-C3. Use core LittleFS instead of Lorol's LITTLEFS for v2.0.0+
*****************************************************************************************************************************/
#pragma once
#ifndef ESP_WiFiManager_h
#define ESP_WiFiManager_h
#include <ESP_WiFiManager.hpp> //https://github.com/khoih-prog/ESP_WiFiManager
#include <ESP_WiFiManager-Impl.h> //https://github.com/khoih-prog/ESP_WiFiManager
#endif // ESP_WiFiManager_h

File diff suppressed because one or more lines are too long

View File

@ -1,130 +0,0 @@
/****************************************************************************************************************************
ESP_WiFiManager_Debug.h
For ESP8266 / ESP32 boards
ESP_WiFiManager is a library for the ESP8266/Arduino platform
(https://github.com/esp8266/Arduino) to enable easy
configuration and reconfiguration of WiFi credentials using a Captive Portal
inspired by:
http://www.esp8266.com/viewtopic.php?f=29&t=2520
https://github.com/chriscook8/esp-arduino-apboot
https://github.com/esp8266/Arduino/blob/master/libraries/DNSServer/examples/CaptivePortalAdvanced/
Modified from Tzapu https://github.com/tzapu/WiFiManager
and from Ken Taylor https://github.com/kentaylor
Built by Khoi Hoang https://github.com/khoih-prog/ESP_WiFiManager
Licensed under MIT license
Version: 1.10.1
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K Hoang 07/10/2019 Initial coding
1.0.1 K Hoang 13/12/2019 Fix bug. Add features. Add support for ESP32
1.0.2 K Hoang 19/12/2019 Fix bug thatkeeps ConfigPortal in endless loop if Portal/Router SSID or Password is NULL.
1.0.3 K Hoang 05/01/2020 Option not displaying AvailablePages in Info page. Enhance README.md. Modify examples
1.0.4 K Hoang 07/01/2020 Add RFC952 setHostname feature.
1.0.5 K Hoang 15/01/2020 Add configurable DNS feature. Thanks to @Amorphous of https://community.blynk.cc
1.0.6 K Hoang 03/02/2020 Add support for ArduinoJson version 6.0.0+ ( tested with v6.14.1 )
1.0.7 K Hoang 13/04/2020 Reduce start time, fix SPIFFS bug in examples, update README.md
1.0.8 K Hoang 10/06/2020 Fix STAstaticIP issue. Restructure code. Add LittleFS support for ESP8266 core 2.7.1+
1.0.9 K Hoang 29/07/2020 Fix ESP32 STAstaticIP bug. Permit changing from DHCP <-> static IP using Config Portal.
Add, enhance examples (fix MDNS for ESP32)
1.0.10 K Hoang 08/08/2020 Add more features to Config Portal. Use random WiFi AP channel to avoid conflict.
1.0.11 K Hoang 17/08/2020 Add CORS feature. Fix bug in softAP, autoConnect, resetSettings.
1.1.0 K Hoang 28/08/2020 Add MultiWiFi feature to autoconnect to best WiFi at runtime
1.1.1 K Hoang 30/08/2020 Add setCORSHeader function to allow flexible CORS. Fix typo and minor improvement.
1.1.2 K Hoang 17/08/2020 Fix bug. Add example.
1.2.0 K Hoang 09/10/2020 Restore cpp code besides Impl.h code to use if linker error. Fix bug.
1.3.0 K Hoang 04/12/2020 Add LittleFS support to ESP32 using LITTLEFS Library
1.4.1 K Hoang 22/12/2020 Fix staticIP not saved. Add functions. Add complex examples. Sync with ESPAsync_WiFiManager
1.4.2 K Hoang 14/01/2021 Fix examples' bug not using saved WiFi Credentials after losing all WiFi connections.
1.4.3 K Hoang 23/01/2021 Fix examples' bug not saving Static IP in certain cases.
1.5.0 K Hoang 12/02/2021 Add support to new ESP32-S2
1.5.1 K Hoang 26/03/2021 Fix compiler error if setting Compiler Warnings to All. Retest with esp32 core v1.0.6
1.5.2 K Hoang 08/04/2021 Fix example misleading messages.
1.5.3 K Hoang 13/04/2021 Add dnsServer error message.
1.6.0 K Hoang 20/04/2021 Add support to new ESP32-C3 using SPIFFS or EEPROM
1.6.1 K Hoang 25/04/2021 Fix MultiWiFi bug. Fix captive-portal bug if CP AP address is not default 192.168.4.1
1.7.0 K Hoang 06/05/2021 Set _timezoneName. Add support to new ESP32-S2 (METRO_ESP32S2, FUNHOUSE_ESP32S2, etc.)
1.7.1 K Hoang 08/05/2021 Fix Json bug. Fix timezoneName not displayed in Info page.
1.7.2 K Hoang 08/05/2021 Fix warnings with ESP8266 core v3.0.0
1.7.3 K Hoang 29/07/2021 Fix MultiWiFi connection issue with ESP32 core v2.0.0-rc1+
1.7.4 K Hoang 13/08/2021 Add WiFi scanning of hidden SSIDs
1.7.5 K Hoang 10/10/2021 Update `platform.ini` and `library.json`
1.7.6 K Hoang 26/11/2021 Auto detect ESP32 core and use either built-in LittleFS or LITTLEFS library
1.7.7 K Hoang 26/11/2021 Fix compile error for ESP32 core v1.0.5-
1.7.8 K Hoang 30/11/2021 Fix bug to permit using HTTP port different from 80. Fix bug
1.8.0 K Hoang 29/12/2021 Fix `multiple-definitions` linker error and weird bug related to src_cpp
1.9.0 K Hoang 17/01/2022 Enable compatibility with old code to include only ESP_WiFiManager.h
1.10.0 K Hoang 10/02/2022 Add support to new ESP32-S3
1.10.1 K Hoang 11/02/2022 Add LittleFS support to ESP32-C3. Use core LittleFS instead of Lorol's LITTLEFS for v2.0.0+
*****************************************************************************************************************************/
#pragma once
#ifndef ESP_WiFiManager_Debug_H
#define ESP_WiFiManager_Debug_H
#ifdef WIFIMGR_DEBUG_PORT
#define WM_DBG_PORT WIFIMGR_DEBUG_PORT
#else
#define WM_DBG_PORT Serial
#endif
// Change _WIFIMGR_LOGLEVEL_ to set tracing and logging verbosity
// 0: DISABLED: no logging
// 1: ERROR: errors
// 2: WARN: errors and warnings
// 3: INFO: errors, warnings and informational (default)
// 4: DEBUG: errors, warnings, informational and debug
#ifndef _WIFIMGR_LOGLEVEL_
#define _WIFIMGR_LOGLEVEL_ 0
#endif
const char WM_MARK[] = "[WM] ";
const char WM_SP[] = " ";
#define WM_PRINT WM_DBG_PORT.print
#define WM_PRINTLN WM_DBG_PORT.println
#define WM_PRINT_MARK WM_PRINT(WM_MARK)
#define WM_PRINT_SP WM_PRINT(WM_SP)
////////////////////////////////////////////////////
#define LOGERROR(x) if(_WIFIMGR_LOGLEVEL_>0) { WM_PRINT_MARK; WM_PRINTLN(x); }
#define LOGERROR0(x) if(_WIFIMGR_LOGLEVEL_>0) { WM_PRINT(x); }
#define LOGERROR1(x,y) if(_WIFIMGR_LOGLEVEL_>0) { WM_PRINT_MARK; WM_PRINT(x); WM_PRINT_SP; WM_PRINTLN(y); }
#define LOGERROR2(x,y,z) if(_WIFIMGR_LOGLEVEL_>0) { WM_PRINT_MARK; WM_PRINT(x); WM_PRINT_SP; WM_PRINT(y); WM_PRINT_SP; WM_PRINTLN(z); }
#define LOGERROR3(x,y,z,w) if(_WIFIMGR_LOGLEVEL_>0) { WM_PRINT_MARK; WM_PRINT(x); WM_PRINT_SP; WM_PRINT(y); WM_PRINT_SP; WM_PRINT(z); WM_PRINT_SP; WM_PRINTLN(w); }
////////////////////////////////////////////////////
#define LOGWARN(x) if(_WIFIMGR_LOGLEVEL_>1) { WM_PRINT_MARK; WM_PRINTLN(x); }
#define LOGWARN0(x) if(_WIFIMGR_LOGLEVEL_>1) { WM_PRINT(x); }
#define LOGWARN1(x,y) if(_WIFIMGR_LOGLEVEL_>1) { WM_PRINT_MARK; WM_PRINT(x); WM_PRINT_SP; WM_PRINTLN(y); }
#define LOGWARN2(x,y,z) if(_WIFIMGR_LOGLEVEL_>1) { WM_PRINT_MARK; WM_PRINT(x); WM_PRINT_SP; WM_PRINT(y); WM_PRINT_SP; WM_PRINTLN(z); }
#define LOGWARN3(x,y,z,w) if(_WIFIMGR_LOGLEVEL_>1) { WM_PRINT_MARK; WM_PRINT(x); WM_PRINT_SP; WM_PRINT(y); WM_PRINT_SP; WM_PRINT(z); WM_PRINT_SP; WM_PRINTLN(w); }
////////////////////////////////////////////////////
#define LOGINFO(x) if(_WIFIMGR_LOGLEVEL_>2) { WM_PRINT_MARK; WM_PRINTLN(x); }
#define LOGINFO0(x) if(_WIFIMGR_LOGLEVEL_>2) { WM_PRINT(x); }
#define LOGINFO1(x,y) if(_WIFIMGR_LOGLEVEL_>2) { WM_PRINT_MARK; WM_PRINT(x); WM_PRINT_SP; WM_PRINTLN(y); }
#define LOGINFO2(x,y,z) if(_WIFIMGR_LOGLEVEL_>2) { WM_PRINT_MARK; WM_PRINT(x); WM_PRINT_SP; WM_PRINT(y); WM_PRINT_SP; WM_PRINTLN(z); }
#define LOGINFO3(x,y,z,w) if(_WIFIMGR_LOGLEVEL_>2) { WM_PRINT_MARK; WM_PRINT(x); WM_PRINT_SP; WM_PRINT(y); WM_PRINT_SP; WM_PRINT(z); WM_PRINT_SP; WM_PRINTLN(w); }
////////////////////////////////////////////////////
#define LOGDEBUG(x) if(_WIFIMGR_LOGLEVEL_>3) { WM_PRINT_MARK; WM_PRINTLN(x); }
#define LOGDEBUG0(x) if(_WIFIMGR_LOGLEVEL_>3) { WM_PRINT(x); }
#define LOGDEBUG1(x,y) if(_WIFIMGR_LOGLEVEL_>3) { WM_PRINT_MARK; WM_PRINT(x); WM_PRINT_SP; WM_PRINTLN(y); }
#define LOGDEBUG2(x,y,z) if(_WIFIMGR_LOGLEVEL_>3) { WM_PRINT_MARK; WM_PRINT(x); WM_PRINT_SP; WM_PRINT(y); WM_PRINT_SP; WM_PRINTLN(z); }
#define LOGDEBUG3(x,y,z,w) if(_WIFIMGR_LOGLEVEL_>3) { WM_PRINT_MARK; WM_PRINT(x); WM_PRINT_SP; WM_PRINT(y); WM_PRINT_SP; WM_PRINT(z); WM_PRINT_SP; WM_PRINTLN(w); }
////////////////////////////////////////////////////
#endif //ESP_WiFiManager_Debug_H

File diff suppressed because it is too large Load Diff

View File

@ -38,8 +38,8 @@ build_flags =
lib_deps = # Switched to forks for better version control.
# Using local copy of these libraries
#https://github.com/jrowberg/i2cdevlib.git#<document>
#https://github.com/khoih-prog/ESP_WiFiManager#<document>
#https://github.com/khoih-prog/ESP_DoubleResetDetector#<document>
https://github.com/mp-se/ESP_WiFiManager#v1.9.0 # https://github.com/khoih-prog/ESP_WiFiManager
https://github.com/mp-se/ESP_DoubleResetDetector#v1.2.1 # https://github.com/khoih-prog/ESP_DoubleResetDetector
#https://github.com/PaulStoffregen/OneWire
#https://github.com/milesburton/Arduino-Temperature-Control-Library
https://github.com/mp-se/tinyexpr # https://github.com/codeplea/tinyexpr

View File

@ -62,8 +62,10 @@ void Config::createJson(DynamicJsonDocument& doc) {
// doc[PARAM_CONFIG_VER] = getConfigVersion();
doc[PARAM_ID] = getID();
doc[PARAM_OTA] = getOtaURL();
doc[PARAM_SSID] = getWifiSSID();
doc[PARAM_PASS] = getWifiPass();
doc[PARAM_SSID] = getWifiSSID(0);
doc[PARAM_PASS] = getWifiPass(0);
doc[PARAM_SSID2] = getWifiSSID(1);
doc[PARAM_PASS2] = getWifiPass(1);
doc[PARAM_BLE] = getColorBLE();
doc[PARAM_TEMPFORMAT] = String(getTempFormat());
doc[PARAM_TOKEN] = getToken();
@ -207,8 +209,10 @@ bool Config::loadFile() {
#endif
if (!doc[PARAM_OTA].isNull()) setOtaURL(doc[PARAM_OTA]);
if (!doc[PARAM_MDNS].isNull()) setMDNS(doc[PARAM_MDNS]);
if (!doc[PARAM_SSID].isNull()) setWifiSSID(doc[PARAM_SSID]);
if (!doc[PARAM_PASS].isNull()) setWifiPass(doc[PARAM_PASS]);
if (!doc[PARAM_SSID].isNull()) setWifiSSID(doc[PARAM_SSID], 0);
if (!doc[PARAM_PASS].isNull()) setWifiPass(doc[PARAM_PASS], 0);
if (!doc[PARAM_SSID2].isNull()) setWifiSSID(doc[PARAM_SSID2], 1);
if (!doc[PARAM_PASS2].isNull()) setWifiPass(doc[PARAM_PASS2], 1);
if (!doc[PARAM_BLE].isNull()) setColorBLE(doc[PARAM_BLE]);
if (!doc[PARAM_TEMPFORMAT].isNull()) {

View File

@ -114,7 +114,12 @@ class AdvancedConfig {
int getPushIntervalMqtt() { return _pushIntervalMqtt; }
void setPushIntervalMqtt(int t) { _pushIntervalMqtt = t; }
bool isPushIntervalActive() { return (_pushIntervalHttp1+_pushIntervalHttp2+_pushIntervalHttp3+_pushIntervalInflux+_pushIntervalMqtt) == 0 ? false : true; }
bool isPushIntervalActive() {
return (_pushIntervalHttp1 + _pushIntervalHttp2 + _pushIntervalHttp3 +
_pushIntervalInflux + _pushIntervalMqtt) == 0
? false
: true;
}
bool saveFile();
bool loadFile();
@ -136,8 +141,8 @@ class Config {
bool _gyroTemp = false;
// Wifi Config
String _wifiSSID = "";
String _wifiPASS = "";
String _wifiSSID[2] = {"", ""};
String _wifiPASS[2] = {"", ""};
// Push target settings
String _token = "";
@ -199,14 +204,29 @@ class Config {
bool isOtaActive() { return _otaURL.length() ? true : false; }
bool isOtaSSL() { return _otaURL.startsWith("https://"); }
const char* getWifiSSID() { return _wifiSSID.c_str(); }
void setWifiSSID(String s) {
_wifiSSID = s;
const char* getWifiSSID(int idx) { return _wifiSSID[idx].c_str(); }
void setWifiSSID(String s, int idx) {
_wifiSSID[idx] = s;
_saveNeeded = true;
}
const char* getWifiPass() { return _wifiPASS.c_str(); }
void setWifiPass(String s) {
_wifiPASS = s;
const char* getWifiPass(int idx) { return _wifiPASS[idx].c_str(); }
void setWifiPass(String s, int idx) {
_wifiPASS[idx] = s;
_saveNeeded = true;
}
bool dualWifiConfigured() {
return _wifiSSID[0].length() > 0 && _wifiSSID[1].length() > 0 ? true
: false;
}
void swapPrimaryWifi() {
String s = _wifiSSID[0];
_wifiSSID[0] = _wifiSSID[1];
_wifiSSID[1] = s;
String p = _wifiPASS[0];
_wifiPASS[0] = _wifiPASS[1];
_wifiPASS[1] = p;
_saveNeeded = true;
}

View File

@ -61,8 +61,7 @@ void checkSleepMode(float angle, float volt) {
#endif
#if defined(FORCE_GRAVITY_MODE)
Log.notice(
F("MAIN: Forcing device into gravity mode for debugging" CR));
Log.notice(F("MAIN: Forcing device into gravity mode for debugging" CR));
runMode = RunMode::gravityMode;
#endif
@ -215,6 +214,7 @@ void setup() {
switch (runMode) {
case RunMode::configurationMode:
if (myWifi.isConnected()) {
Log.notice(F("Main: Activating web server." CR));
#if defined(ACTIVATE_OTA)
LOG_PERF_START("main-wifi-ota");
if (myWifi.checkFirmwareVersion()) myWifi.updateFirmware();
@ -355,7 +355,8 @@ void goToSleep(int sleepInterval) {
void loop() {
switch (runMode) {
case RunMode::configurationMode:
myWebServerHandler.loop();
if (myWifi.isConnected()) myWebServerHandler.loop();
myWifi.loop();
loopGravityOnInterval();

View File

@ -49,7 +49,6 @@ void PushIntervalTracker::update(const int index, const int defaultValue) {
//
void PushIntervalTracker::load() {
File intFile = LittleFS.open(PUSHINT_FILENAME, "r");
int i = 0;
if (intFile) {
String line = intFile.readStringUntil('\n');
@ -68,7 +67,8 @@ void PushIntervalTracker::load() {
}
#if !defined(PUSH_DISABLE_LOGGING)
Log.verbose(F("PUSH: Parsed trackers: %d:%d:%d:%d:%d." CR), _counters[0], _counters[1], _counters[2], _counters[3], _counters[4] );
Log.verbose(F("PUSH: Parsed trackers: %d:%d:%d:%d:%d." CR), _counters[0],
_counters[1], _counters[2], _counters[3], _counters[4]);
#endif
}
@ -89,12 +89,14 @@ void PushIntervalTracker::save() {
#endif
LittleFS.remove(PUSHINT_FILENAME);
} else {
Log.notice(F("PUSH: Variabled push interval enabled, updating counters." CR));
Log.notice(
F("PUSH: Variabled push interval enabled, updating counters." CR));
File intFile = LittleFS.open(PUSHINT_FILENAME, "w");
if (intFile) {
// Format=http1:http2:http3:influx:mqtt
intFile.printf("%d:%d:%d:%d:%d\n", _counters[0], _counters[1], _counters[2], _counters[3], _counters[4] );
intFile.printf("%d:%d:%d:%d:%d\n", _counters[0], _counters[1],
_counters[2], _counters[3], _counters[4]);
intFile.close();
}
}
@ -155,9 +157,8 @@ void PushTarget::probeMaxFragement( String& serverPath ) {
#if defined(ESP8266) // Looks like this is feature is not supported by influxdb
// Format: http:://servername:port/path
int port = 443;
String host =
serverPath.substring(8); // remove the prefix or the probe will fail,
// it needs a pure host name.
String host = serverPath.substring(8); // remove the prefix or the probe will
// fail, it needs a pure host name.
// Remove the path if it exist
int idx = host.indexOf("/");
if (idx != -1) host = host.substring(0, idx);
@ -170,7 +171,8 @@ void PushTarget::probeMaxFragement( String& serverPath ) {
host = host.substring(0, idx);
}
Log.notice(F("PUSH: Probing server to max fragment %s:%d" CR), host.c_str(), port);
Log.notice(F("PUSH: Probing server to max fragment %s:%d" CR), host.c_str(),
port);
if (_wifiSecure.probeMaxFragmentLength(host, port, 512)) {
Log.notice(F("PUSH: Server supports smaller SSL buffer." CR));
_wifiSecure.setBufferSizes(512, 512);

View File

@ -31,6 +31,8 @@ SOFTWARE.
#define PARAM_OTA "ota-url"
#define PARAM_SSID "wifi-ssid"
#define PARAM_PASS "wifi-pass"
#define PARAM_SSID2 "wifi-ssid2"
#define PARAM_PASS2 "wifi-pass2"
#define PARAM_RUNTIME_AVERAGE "runtime-average"
#define PARAM_TOKEN "token"
#define PARAM_TOKEN2 "token2"

View File

@ -357,6 +357,7 @@ void WebServerHandler::webHandleStatus() {
doc[PARAM_APP_VER] = CFG_APPVER;
doc[PARAM_APP_BUILD] = CFG_GITREV;
doc[PARAM_MDNS] = myConfig.getMDNS();
doc[PARAM_SSID] = WiFi.SSID();
FloatHistoryLog runLog(RUNTIME_FILENAME);
doc[PARAM_RUNTIME_AVERAGE] = reduceFloatPrecision(
@ -390,8 +391,10 @@ void WebServerHandler::webHandleClearWIFI() {
if (!id.compareTo(myConfig.getID())) {
_server->send(200, "text/plain",
"Clearing WIFI credentials and doing reset...");
myConfig.setWifiPass("");
myConfig.setWifiSSID("");
myConfig.setWifiPass("", 0);
myConfig.setWifiSSID("", 0);
myConfig.setWifiPass("", 1);
myConfig.setWifiSSID("", 1);
myConfig.saveFile();
delay(1000);
WiFi.disconnect(); // Clear credentials
@ -642,31 +645,44 @@ void WebServerHandler::webHandleConfigAdvancedWrite() {
#endif
if (_server->hasArg(PARAM_HW_GYRO_READ_COUNT))
myAdvancedConfig.setGyroReadCount(_server->arg(PARAM_HW_GYRO_READ_COUNT).toInt());
myAdvancedConfig.setGyroReadCount(
_server->arg(PARAM_HW_GYRO_READ_COUNT).toInt());
if (_server->hasArg(PARAM_HW_GYRO_READ_DELAY))
myAdvancedConfig.setGyroReadDelay(_server->arg(PARAM_HW_GYRO_READ_DELAY).toInt());
myAdvancedConfig.setGyroReadDelay(
_server->arg(PARAM_HW_GYRO_READ_DELAY).toInt());
if (_server->hasArg(PARAM_HW_GYRO_MOVING_THREASHOLD))
myAdvancedConfig.setGyroSensorMovingThreashold(_server->arg(PARAM_HW_GYRO_MOVING_THREASHOLD).toInt());
myAdvancedConfig.setGyroSensorMovingThreashold(
_server->arg(PARAM_HW_GYRO_MOVING_THREASHOLD).toInt());
if (_server->hasArg(PARAM_HW_FORMULA_DEVIATION))
myAdvancedConfig.setMaxFormulaCreationDeviation(_server->arg(PARAM_HW_FORMULA_DEVIATION).toFloat());
myAdvancedConfig.setMaxFormulaCreationDeviation(
_server->arg(PARAM_HW_FORMULA_DEVIATION).toFloat());
if (_server->hasArg(PARAM_HW_FORMULA_CALIBRATION_TEMP))
myAdvancedConfig.SetDefaultCalibrationTemp(_server->arg(PARAM_HW_FORMULA_CALIBRATION_TEMP).toFloat());
myAdvancedConfig.SetDefaultCalibrationTemp(
_server->arg(PARAM_HW_FORMULA_CALIBRATION_TEMP).toFloat());
if (_server->hasArg(PARAM_HW_WIFI_PORTAL_TIMEOUT))
myAdvancedConfig.setWifiPortalTimeout(_server->arg(PARAM_HW_WIFI_PORTAL_TIMEOUT).toInt());
myAdvancedConfig.setWifiPortalTimeout(
_server->arg(PARAM_HW_WIFI_PORTAL_TIMEOUT).toInt());
if (_server->hasArg(PARAM_HW_WIFI_CONNECT_TIMEOUT))
myAdvancedConfig.setWifiConnectTimeout(_server->arg(PARAM_HW_WIFI_CONNECT_TIMEOUT).toInt());
myAdvancedConfig.setWifiConnectTimeout(
_server->arg(PARAM_HW_WIFI_CONNECT_TIMEOUT).toInt());
if (_server->hasArg(PARAM_HW_PUSH_TIMEOUT))
myAdvancedConfig.setPushTimeout(_server->arg(PARAM_HW_PUSH_TIMEOUT).toInt());
myAdvancedConfig.setPushTimeout(
_server->arg(PARAM_HW_PUSH_TIMEOUT).toInt());
if (_server->hasArg(PARAM_HW_PUSH_INTERVAL_HTTP1))
myAdvancedConfig.setPushIntervalHttp1(_server->arg(PARAM_HW_PUSH_INTERVAL_HTTP1).toInt());
myAdvancedConfig.setPushIntervalHttp1(
_server->arg(PARAM_HW_PUSH_INTERVAL_HTTP1).toInt());
if (_server->hasArg(PARAM_HW_PUSH_INTERVAL_HTTP2))
myAdvancedConfig.setPushIntervalHttp2(_server->arg(PARAM_HW_PUSH_INTERVAL_HTTP2).toInt());
myAdvancedConfig.setPushIntervalHttp2(
_server->arg(PARAM_HW_PUSH_INTERVAL_HTTP2).toInt());
if (_server->hasArg(PARAM_HW_PUSH_INTERVAL_HTTP3))
myAdvancedConfig.setPushIntervalHttp3(_server->arg(PARAM_HW_PUSH_INTERVAL_HTTP3).toInt());
myAdvancedConfig.setPushIntervalHttp3(
_server->arg(PARAM_HW_PUSH_INTERVAL_HTTP3).toInt());
if (_server->hasArg(PARAM_HW_PUSH_INTERVAL_INFLUX))
myAdvancedConfig.setPushIntervalInflux(_server->arg(PARAM_HW_PUSH_INTERVAL_INFLUX).toInt());
myAdvancedConfig.setPushIntervalInflux(
_server->arg(PARAM_HW_PUSH_INTERVAL_INFLUX).toInt());
if (_server->hasArg(PARAM_HW_PUSH_INTERVAL_MQTT))
myAdvancedConfig.setPushIntervalMqtt(_server->arg(PARAM_HW_PUSH_INTERVAL_MQTT).toInt());
myAdvancedConfig.setPushIntervalMqtt(
_server->arg(PARAM_HW_PUSH_INTERVAL_MQTT).toInt());
myAdvancedConfig.saveFile();
_server->sendHeader("Location", "/config.htm#collapseAdvanced", true);
@ -674,7 +690,6 @@ void WebServerHandler::webHandleConfigAdvancedWrite() {
LOG_PERF_STOP("webserver-api-config-advanced");
}
//
// Read advanced settings
//

View File

@ -52,20 +52,8 @@ SOFTWARE.
#define USE_STATIC_IP_CONFIG_IN_CP false
#define _WIFIMGR_LOGLEVEL_ 3
#include <ESP_WiFiManager.h>
// Override the look and feel of the standard ui (hide secondary forms)
const char WM_HTTP_FORM_START[] PROGMEM =
"<form method='get' "
"action='wifisave'><fieldset><div><label>SSID</label><input id='s' "
"name='s' length=32 "
"placeholder='SSID'><div></div></div><div><label>Password</label><input "
"id='p' name='p' length=64 placeholder='password'><div></div></div><div "
"hidden><label>SSID1</label><input id='s1' name='s1' length=32 "
"placeholder='SSID1'><div></div></div><div "
"hidden><label>Password</label><input id='p1' name='p1' length=64 "
"placeholder='password1'><div></div></div></fieldset>";
ESP_WiFiManager *myWifiManager;
DoubleResetDetector *myDRD;
WifiConnection myWifi;
const char *userSSID = USER_SSID;
@ -82,17 +70,20 @@ void WifiConnection::init() {
// Check if we have a valid wifi configuration
//
bool WifiConnection::hasConfig() {
if (strlen(myConfig.getWifiSSID())) return true;
if (strlen(myConfig.getWifiSSID(0))) return true;
if (strlen(userSSID)) return true;
// Check if there are stored WIFI Settings we can use.
#if defined(ESP32)
#warning \
"Cant read SSID on ESP32 until a connection has been made, this part will not work, change to WifiManager"
#endif
String ssid = WiFi.SSID();
if (ssid.length()) {
Log.notice(F("WIFI: Found credentials in EEPORM." CR));
myConfig.setWifiSSID(ssid);
myConfig.setWifiSSID(ssid, 0);
if (WiFi.psk().length())
myConfig.setWifiPass(WiFi.psk());
if (WiFi.psk().length()) myConfig.setWifiPass(WiFi.psk(), 0);
myConfig.saveFile();
return true;
@ -145,21 +136,29 @@ void WifiConnection::startPortal() {
ESP_WMParameter deviceName(mdns.c_str());
myWifiManager->addParameter(&deviceName);
if (myWifiManager->startConfigPortal(WIFI_DEFAULT_SSID, WIFI_DEFAULT_PWD)) {
Log.notice(F("WIFI: Exited portal, connected to wifi. Rebooting..." CR));
myWifiManager->startConfigPortal(WIFI_DEFAULT_SSID, WIFI_DEFAULT_PWD);
if (myWifiManager->getSSID().length())
myConfig.setWifiSSID(myWifiManager->getSSID());
if (myWifiManager->getSSID(0).length()) {
myConfig.setWifiSSID(myWifiManager->getSSID(0), 0);
myConfig.setWifiPass(myWifiManager->getPW(0), 0);
myConfig.setWifiSSID(myWifiManager->getSSID(1), 1);
myConfig.setWifiPass(myWifiManager->getPW(1), 1);
if (myWifiManager->getPW().length())
myConfig.setWifiPass(myWifiManager->getPW());
// If the same SSID has been used, lets delete the second
if (!strcmp(myConfig.getWifiSSID(0), myConfig.getWifiSSID(1))) {
myConfig.setWifiSSID("", 1);
myConfig.setWifiPass("", 1);
}
Log.notice(F("WIFI: Stored SSID1:'%s' SSID2:'%s'" CR),
myConfig.getWifiSSID(0), myConfig.getWifiSSID(1));
myConfig.saveFile();
} else {
Log.notice(
F("WIFI: Exited portal, no connection to wifi. Rebooting..." CR));
F("WIFI: Could not find first SSID so assuming we got a timeout." CR));
}
Log.notice(F("WIFI: Exited wifi config portal. Rebooting..." CR));
stopDoubleReset();
delay(500);
ESP_RESET();
@ -173,7 +172,7 @@ void WifiConnection::loop() { myDRD->loop(); }
//
// Connect to last known access point, non blocking mode.
//
void WifiConnection::connectAsync() {
void WifiConnection::connectAsync(int wifiIndex) {
WiFi.persistent(true);
WiFi.mode(WIFI_STA);
if (strlen(userSSID)) {
@ -181,9 +180,10 @@ void WifiConnection::connectAsync() {
userSSID);
WiFi.begin(userSSID, userPWD);
} else {
Log.notice(F("WIFI: Connecting to wifi using stored settings %s." CR),
myConfig.getWifiSSID());
WiFi.begin(myConfig.getWifiSSID(), myConfig.getWifiPass());
Log.notice(F("WIFI: Connecting to wifi (%d) using stored settings %s." CR),
wifiIndex, myConfig.getWifiSSID(wifiIndex));
WiFi.begin(myConfig.getWifiSSID(wifiIndex),
myConfig.getWifiPass(wifiIndex));
}
}
@ -211,17 +211,91 @@ bool WifiConnection::waitForConnection(int maxTime) {
}
}
Serial.print(CR);
Log.notice(F("WIFI: Connected to wifi ip=%s." CR), getIPAddress().c_str());
Log.notice(F("WIFI: Connected to wifi %s ip=%s." CR), WiFi.SSID().c_str(),
getIPAddress().c_str());
Log.notice(F("WIFI: Using mDNS name %s." CR), myConfig.getMDNS());
return true;
}
//
// Check what network is the strongest.
//
int WifiConnection::findStrongestNetwork() {
if (!myConfig.dualWifiConfigured()) {
Log.notice(F("WIFI: Only one wifi SSID is configured, skipping scan." CR));
return -1;
}
Log.notice(F("WIFI: Scanning for wifi." CR));
int noNetwork = WiFi.scanNetworks(false, false);
int strenght[2] = {-100, -100};
for (int i = 0; i < noNetwork; i++) {
int rssi = WiFi.RSSI(i);
String ssid = WiFi.SSID(i);
if (ssid.compareTo(myConfig.getWifiSSID(0)))
strenght[0] = rssi;
else if (ssid.compareTo(myConfig.getWifiSSID(1)))
strenght[1] = rssi;
#if LOG_LEVEL == 6
Log.verbose(F("WIFI: Found %s %d." CR), ssid.c_str(), rssi);
#endif
}
if (strenght[0] == -100 && strenght[1] == -100)
return -1; // None of the stored networks can be seen
if (strenght[0] >= strenght[1])
return 0; // First network is strongest or they have equal strength
return 1; // Second network is the strongest
}
//
// Connect to last known access point, blocking mode.
//
bool WifiConnection::connect() {
connectAsync();
/*
// Alternative code for connecting to strongest wifi.
// Takes approximatly 2 seconds to scan for available network
int i = findStrongestNetwork();
if (i != -1) {
Log.notice(F("WIFI: Wifi %d:'%s' is strongest." CR), i,
myConfig.getWifiSSID(i)); } else { i = 0; // Use first SSID as default.
}
connectAsync(i);
return waitForConnection(myAdvancedConfig.getWifiConnectTimeout());
*/
// Alternative code for using seconday wifi settings as fallback.
// If success to seconday is successful this is used as standard
int timeout = myAdvancedConfig.getWifiConnectTimeout();
connectAsync(0);
if (!waitForConnection(timeout)) {
Log.warning(F("WIFI: Failed to connect to first SSID %s." CR),
myConfig.getWifiSSID(0));
connectAsync(1);
if (waitForConnection(timeout)) {
Log.notice(
F("WIFI: Connected to second SSID %s, making secondary default." CR),
myConfig.getWifiSSID(1));
myConfig.swapPrimaryWifi();
myConfig.saveFile();
return true;
}
Log.warning(F("WIFI: Failed to connect to any SSID." CR));
return false;
}
return true;
}
//

View File

@ -42,8 +42,11 @@ class WifiConnection {
bool _newFirmware = false;
bool parseFirmwareVersionString(int (&num)[3], const char* version);
void downloadFile(HTTPClient& http, String& fname);
void connectAsync();
// WIFI
void connectAsync(int wifiIndex);
bool waitForConnection(int maxTime = 20);
int findStrongestNetwork();
public:
// WIFI

View File

@ -14,5 +14,6 @@
"app-build": "gitrev",
"mdns": "gravmon",
"platform": "esp32",
"wifi-ssid": "wifi",
"runtime-average": 3.12
}