From 99085bab56ef1344240adf658a25df77634bd74c Mon Sep 17 00:00:00 2001 From: Cri4Key Date: Thu, 10 Apr 2025 08:56:36 +0200 Subject: [PATCH 1/2] Support for ESP32 Arduino Core 3.x and ArduinoJson 7 --- src/AutoConnectCoreImpl.hpp | 13 +++++++++++-- src/AutoConnectJsonDefs.h | 11 +++++++++++ src/AutoConnectPageImpl.hpp | 12 ++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/AutoConnectCoreImpl.hpp b/src/AutoConnectCoreImpl.hpp index e5116b79..a9b373f6 100644 --- a/src/AutoConnectCoreImpl.hpp +++ b/src/AutoConnectCoreImpl.hpp @@ -246,7 +246,11 @@ bool AutoConnectCore::begin(const char* ssid, const char* passphrase, unsigne if (_apConfig.autoRise) { // Change WiFi working mode, Enable AP with STA - WiFi.setAutoConnect(false); +#if defined(ARDUINO_ARCH_ESP32) && ((ESP_IDF_VERSION_MAJOR > 3) || ((ESP_IDF_VERSION_MAJOR == 3) && (ESP_IDF_VERSION_MINOR >= 1))) + WiFi.setAutoReconnect(false); +#else + WiFi.setAutoConnect(false); // Deprecated in ESP32 from ESP-IDF v3.1 +#endif disconnect(false, true); // Activate the AP mode with configured softAP and start the access point. @@ -559,8 +563,13 @@ void AutoConnectCore::handleRequest(void) { if (_apConfig.retainPortal && _apConfig.autoRise) { // Cancel AutoReconnect to ensure detection for queries to penetrate // to the internet from a client. - if (WiFi.getAutoConnect()) +#if defined(ARDUINO_ARCH_ESP32) && ((ESP_IDF_VERSION_MAJOR > 3) || ((ESP_IDF_VERSION_MAJOR == 3) && (ESP_IDF_VERSION_MINOR >= 1))) + if (WiFi.getAutoReconnect()) WiFi.setAutoReconnect(false); +#else + if (WiFi.getAutoConnect()) // Deprecated in ESP32 from ESP-IDF v3.1 + WiFi.setAutoReconnect(false); +#endif // Restart the responder for the captive portal detection. if (!(WiFi.getMode() & WIFI_AP)) { diff --git a/src/AutoConnectJsonDefs.h b/src/AutoConnectJsonDefs.h index 76fa8ec4..0df3b8e0 100644 --- a/src/AutoConnectJsonDefs.h +++ b/src/AutoConnectJsonDefs.h @@ -58,6 +58,17 @@ struct SpiRamAllocatorST { void deallocate(void* pointer) { heap_caps_free(pointer); } + void* reallocate(void *pointer, size_t new_size) { + uint32_t caps; + if (psramFound()) + caps = MALLOC_CAP_SPIRAM; + else + { + caps = MALLOC_CAP_8BIT; + AC_DBG("PSRAM not found, JSON buffer allocates to the heap.\n"); + } + return heap_caps_realloc(pointer, new_size, caps); + } }; #define AUTOCONNECT_JSONBUFFER_PRIMITIVE_SIZE AUTOCONNECT_JSONPSRAM_SIZE using ArduinoJsonBuffer = BasicJsonDocument; diff --git a/src/AutoConnectPageImpl.hpp b/src/AutoConnectPageImpl.hpp index 204ae838..4ba5fc43 100644 --- a/src/AutoConnectPageImpl.hpp +++ b/src/AutoConnectPageImpl.hpp @@ -16,7 +16,13 @@ extern "C" { #include } #elif defined(ARDUINO_ARCH_ESP32) +#ifdef ESP_IDF_VERSION_MAJOR +#if ESP_IDF_VERSION_MAJOR >= 5 +#include +#else #include +#endif +#endif #include #define ENC_TYPE_NONE WIFI_AUTH_OPEN #endif @@ -998,8 +1004,14 @@ uint32_t AutoConnectCore::_getFlashChipRealSize() { #if defined(ARDUINO_ARCH_ESP8266) return ESP.getFlashChipRealSize(); #elif defined(ARDUINO_ARCH_ESP32) +#if ESP_IDF_VERSION_MAJOR >= 5 + uint32_t size_flash_chip; + esp_flash_get_size(NULL, &size_flash_chip); + return size_flash_chip; +#else return (uint32_t)spi_flash_get_chip_size(); #endif +#endif } template From a1de1df7d9f5cb18c2d23a5054d56b3ae4d73a07 Mon Sep 17 00:00:00 2001 From: Cri4Key Date: Thu, 10 Apr 2025 09:20:24 +0200 Subject: [PATCH 2/2] Rename definition --- src/AutoConnectCoreImpl.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/AutoConnectCoreImpl.hpp b/src/AutoConnectCoreImpl.hpp index a9b373f6..7c8a1be6 100644 --- a/src/AutoConnectCoreImpl.hpp +++ b/src/AutoConnectCoreImpl.hpp @@ -31,10 +31,10 @@ // An actual reset function dependent on the architecture #if defined(ARDUINO_ARCH_ESP8266) -#define SOFT_RESET() ESP.reset() +#define SOFT_RESET_ESP() ESP.reset() #define SET_HOSTNAME(x) do { WiFi.hostname(x); } while(0) #elif defined(ARDUINO_ARCH_ESP32) -#define SOFT_RESET() ESP.restart() +#define SOFT_RESET_ESP() ESP.restart() #define SET_HOSTNAME(x) do { WiFi.setHostname(x); } while(0) #endif @@ -728,7 +728,7 @@ void AutoConnectCore::handleRequest(void) { _stopPortal(); AC_DBG("Reset\n"); delay(1000); - SOFT_RESET(); + SOFT_RESET_ESP(); delay(1000); } @@ -756,7 +756,7 @@ void AutoConnectCore::handleRequest(void) { if (_apConfig.autoReset) { delay(1000); - SOFT_RESET(); + SOFT_RESET_ESP(); delay(1000); } }