Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions src/AutoConnectCoreImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -246,7 +246,11 @@ bool AutoConnectCore<T>::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.
Expand Down Expand Up @@ -559,8 +563,13 @@ void AutoConnectCore<T>::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)) {
Expand Down Expand Up @@ -719,7 +728,7 @@ void AutoConnectCore<T>::handleRequest(void) {
_stopPortal();
AC_DBG("Reset\n");
delay(1000);
SOFT_RESET();
SOFT_RESET_ESP();
delay(1000);
}

Expand Down Expand Up @@ -747,7 +756,7 @@ void AutoConnectCore<T>::handleRequest(void) {

if (_apConfig.autoReset) {
delay(1000);
SOFT_RESET();
SOFT_RESET_ESP();
delay(1000);
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/AutoConnectJsonDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<SpiRamAllocatorST>;
Expand Down
12 changes: 12 additions & 0 deletions src/AutoConnectPageImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ extern "C" {
#include <user_interface.h>
}
#elif defined(ARDUINO_ARCH_ESP32)
#ifdef ESP_IDF_VERSION_MAJOR
#if ESP_IDF_VERSION_MAJOR >= 5
#include <esp_flash.h>
#else
#include <esp_spi_flash.h>
#endif
#endif
#include <WiFi.h>
#define ENC_TYPE_NONE WIFI_AUTH_OPEN
#endif
Expand Down Expand Up @@ -998,8 +1004,14 @@ uint32_t AutoConnectCore<T>::_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 <typename T>
Expand Down