Skip to content

Commit

Permalink
Merge pull request letscontrolit#4975 from TD-er/bugfix/esp32_wifi_co…
Browse files Browse the repository at this point in the history
…nnect

[WiFi] Fix slow WiFi connect after scan on ESP32
  • Loading branch information
TD-er authored Feb 15, 2024
2 parents 75bafa5 + 4cc4f0f commit dfe2bda
Show file tree
Hide file tree
Showing 16 changed files with 90 additions and 40 deletions.
2 changes: 2 additions & 0 deletions docs/source/Hardware/Hardware.rst
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ Currently the default SPI frequency of 20 MHz is used, so not all other SPI devi

Some boards like the ETH01-EVO (ESP32-C3 based) do not even have the SPI bus pins made accesible.

.. note:: Switching to ECO mode can sometimes result in an unreachable node when using SPI Ethernet. After a reboot the node works just fine again (in ECO mode). This is currently being investigated.


GPIO Configuration
""""""""""""""""""
Expand Down
25 changes: 24 additions & 1 deletion docs/source/Reference/SPI_Ethernet_ESP32_boards.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ N.B. As there is not yet support in ESPEasy for multiple SPI busses, it cannot b
- 3
- 10
- SPI2_HOST
* - M5Stack PoECAM
- ESP32-classic
- W5500
-
- 4
-
-
- 23
- 38
- 13
- SPI2_HOST
* - M5Stack Atom PoE Kit (ATOM LITE)
- ESP32-classic
- W5500
Expand All @@ -47,6 +58,17 @@ N.B. As there is not yet support in ESPEasy for multiple SPI busses, it cannot b
- 23
- 33
- SPI2_HOST
* - M5Stack Atom PoE Kit (AtomS3)
- ESP32-S3
- W5500
-
- 6
-
-
- 5
- 7
- 8
- SPI2_HOST
* - M5Stack Base LAN (End-of-life)
- M5Core
- W5500
Expand Down Expand Up @@ -119,8 +141,9 @@ See:

* `M5 Stack Base LAN <https://docs.m5stack.com/en/base/lan_base>`_
* `M5 Stack LAN Base V12 <https://docs.m5stack.com/en/base/lan_v12>`_
* `M5 Stack PoECAM <https://docs.m5stack.com/en/unit/poe_cam>`_
* `M5 Stack LAN PoE Base V12 <https://docs.m5stack.com/en/base/lan_poe_v12>`_
* `M5 Stack LAN Module V13.2 <https://docs.m5stack.com/en/module/LAN%20Module%2013.2>`_
* `M5 Stack ATOM PoE <https://docs.m5stack.com/en/atom/atom_poe>`_
* `M5 Stack ATOM PoE <https://docs.m5stack.com/en/atom/atom_poe>`_ `ATOM Lite <https://docs.m5stack.com/en/core/ATOM%20Lite>`_ `AtomS3 <https://docs.m5stack.com/en/core/AtomS3>`_
* `M5 Stack Base PoE <https://docs.m5stack.com/en/base/w5500PoE>`_
* `TTGO/LilyGO Ethernet boards <https://github.com/Xinyuan-LilyGO/LilyGO-T-ETH-Series/blob/dda7a2ad4ab33d550c8dbaff5db1e61a0eda5aad/examples/ETHOTA/utilities.h#L12>`_
5 changes: 3 additions & 2 deletions platformio_core_defs.ini
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,10 @@ lib_ignore =

; ESP_IDF 5.1
[core_esp32_IDF5_1__3_0_0]
platform = https://github.com/tasmota/platform-espressif32/releases/download/2024.01.11/platform-espressif32.zip
;platform = https://github.com/Jason2866/platform-espressif32.git
platform = https://github.com/tasmota/platform-espressif32/releases/download/2024.02.10/platform-espressif32.zip
;platform_packages =
platform_packages = framework-arduinoespressif32 @ https://github.com/Jason2866/esp32-arduino-lib-builder/releases/download/2010/framework-arduinoespressif32-release_v5.1-4c5ed1f.zip
platform_packages = framework-arduinoespressif32 @ https://github.com/Jason2866/esp32-arduino-lib-builder/releases/download/2036/framework-arduinoespressif32-release_v5.1-246cad0.zip
build_flags = -DESP32_STAGE
-DESP_IDF_VERSION_MAJOR=5
-DLIBRARIES_NO_LOG=1
Expand Down
2 changes: 1 addition & 1 deletion platformio_esp32_solo1.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ build_unflags = ${esp32_base.build_unflags}
; IDF 5.1.2
[esp32_solo1_common_LittleFS]
extends = esp32_base_idf5
platform_packages = framework-arduino-solo1 @ https://github.com/Jason2866/esp32-arduino-lib-builder/releases/download/2013/framework-arduinoespressif32-solo1-release_v5.1-4c5ed1f.zip
platform_packages = framework-arduino-solo1 @ https://github.com/Jason2866/esp32-arduino-lib-builder/releases/download/2038/framework-arduinoespressif32-solo1-release_v5.1-246cad0.zip
build_flags = ${esp32_base_idf5.build_flags}
-DFEATURE_ARDUINO_OTA=1
-DUSE_LITTLEFS
Expand Down
29 changes: 16 additions & 13 deletions platformio_esp32s3_envs.ini
Original file line number Diff line number Diff line change
Expand Up @@ -138,68 +138,71 @@ build_flags = ${esp32s3_common.build_flags}
-DPLUGIN_NEOPIXEL_COLLECTION


[env:custom_ESP32s3_8M1M_LittleFS_CDC]
[env:custom_ESP32s3_8M1M_LittleFS_CDC_ETH]
extends = esp32s3_common_LittleFS
board = esp32s3cdc-qio_qspi-8M
build_flags = ${esp32s3_common_LittleFS.build_flags}
-DFEATURE_ETHERNET=1
-DFEATURE_ARDUINO_OTA=1
-DPLUGIN_BUILD_CUSTOM
-DFEATURE_SD=1
extra_scripts = ${esp32s3_common_LittleFS.extra_scripts}
pre:tools/pio/pre_custom_esp32.py

[env:custom_ESP32s3_8M1M_LittleFS_OPI_PSRAM_CDC]
extends = env:custom_ESP32s3_8M1M_LittleFS_CDC
[env:custom_ESP32s3_8M1M_LittleFS_OPI_PSRAM_CDC_ETH]
extends = env:custom_ESP32s3_8M1M_LittleFS_CDC_ETH
board = esp32s3cdc-qio_opi-8M


[env:max_ESP32s3_8M1M_LittleFS_CDC]
[env:max_ESP32s3_8M1M_LittleFS_CDC_ETH]
extends = esp32s3_common_LittleFS
board = esp32s3cdc-qio_qspi-8M
build_flags = ${esp32s3_common_LittleFS.build_flags}
-DFEATURE_ETHERNET=1
-DFEATURE_ARDUINO_OTA=1
-DPLUGIN_BUILD_MAX_ESP32
-DPLUGIN_BUILD_IR_EXTENDED
extra_scripts = ${esp32s3_common_LittleFS.extra_scripts}


[env:max_ESP32s3_8M1M_LittleFS_OPI_PSRAM_CDC]
extends = env:max_ESP32s3_8M1M_LittleFS_CDC
[env:max_ESP32s3_8M1M_LittleFS_OPI_PSRAM_CDC_ETH]
extends = env:max_ESP32s3_8M1M_LittleFS_CDC_ETH
board = esp32s3cdc-qio_opi-8M


[env:custom_ESP32s3_16M8M_LittleFS_CDC]
[env:custom_ESP32s3_16M8M_LittleFS_CDC_ETH]
extends = esp32s3_common_LittleFS
board = esp32s3cdc-qio_qspi-16M
build_flags = ${esp32s3_common_LittleFS.build_flags}
-DFEATURE_ETHERNET=1
-DFEATURE_ARDUINO_OTA=1
-DPLUGIN_BUILD_CUSTOM
-DPLUGIN_BUILD_IR_EXTENDED
-DFEATURE_SD=1
extra_scripts = ${esp32s3_common_LittleFS.extra_scripts}
pre:tools/pio/pre_custom_esp32.py

[env:custom_ESP32s3_16M8M_LittleFS_OPI_PSRAM_CDC]
extends = env:custom_ESP32s3_16M8M_LittleFS_CDC
[env:custom_ESP32s3_16M8M_LittleFS_OPI_PSRAM_CDC_ETH]
extends = env:custom_ESP32s3_16M8M_LittleFS_CDC_ETH
board = esp32s3cdc-qio_opi-16M


[env:max_ESP32s3_16M8M_LittleFS_CDC]
[env:max_ESP32s3_16M8M_LittleFS_CDC_ETH]
extends = esp32s3_common_LittleFS
board = esp32s3cdc-qio_qspi-16M
build_flags = ${esp32s3_common_LittleFS.build_flags}
-DUSE_LITTLEFS
-DFEATURE_ETHERNET=1
-DFEATURE_ARDUINO_OTA=1
-DPLUGIN_BUILD_MAX_ESP32
-DPLUGIN_BUILD_IR_EXTENDED
extra_scripts = ${esp32s3_common_LittleFS.extra_scripts}


[env:max_ESP32s3_16M8M_LittleFS_OPI_PSRAM_CDC]
[env:max_ESP32s3_16M8M_LittleFS_OPI_PSRAM_CDC_ETH]
extends = esp32s3_common_LittleFS
board = esp32s3cdc-qio_opi-16M
build_flags = ${esp32s3_common_LittleFS.build_flags}
-DUSE_LITTLEFS
-DFEATURE_ETHERNET=1
-DFEATURE_ARDUINO_OTA=1
-DPLUGIN_BUILD_MAX_ESP32
-DPLUGIN_BUILD_IR_EXTENDED
Expand Down
9 changes: 7 additions & 2 deletions src/src/ESPEasyCore/ESPEasyEth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,11 @@ bool ethCheckSettings() {
#endif
&& isValid(Settings.NetworkMedium)
&& validGpio(Settings.ETH_Pin_mdc_cs)
&& validGpio(Settings.ETH_Pin_mdio_irq)
&& (validGpio(Settings.ETH_Pin_power_rst) || (Settings.ETH_Pin_power_rst == -1)); // Some boards have fixed power
&& (isSPI_EthernetType(Settings.ETH_Phy_Type) ||
( validGpio(Settings.ETH_Pin_mdio_irq) &&
(validGpio(Settings.ETH_Pin_power_rst) || (Settings.ETH_Pin_power_rst == -1))
)
); // Some boards have fixed power
}

bool ethPrepare() {
Expand Down Expand Up @@ -249,6 +252,8 @@ bool ETHConnectRelaxed() {
// We might miss the connected event, since we are already connected.
EthEventData.markConnected();
}
} else {
addLog(LOG_LEVEL_ERROR, F("ETH : Failed to initialize ETH"));
}
return EthEventData.ethInitSuccess;
}
Expand Down
26 changes: 18 additions & 8 deletions src/src/ESPEasyCore/ESPEasyWifi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,19 @@ bool WiFiConnected() {
}
#endif

if (!WifiIsSTA(WiFi.getMode())) {
lastState = false;
return lastState;
}


if (lastCheckedTime != 0 && timePassedSince(lastCheckedTime) < 100) {
// Try to rate-limit the nr of calls to this function or else it will be called 1000's of times a second.
return lastState;
if (WiFiEventData.lastDisconnectMoment.isSet() &&
WiFiEventData.lastDisconnectMoment.millisPassedSince() > timePassedSince(lastCheckedTime))
{
// Try to rate-limit the nr of calls to this function or else it will be called 1000's of times a second.
return lastState;
}
}


Expand Down Expand Up @@ -887,16 +896,17 @@ void WifiDisconnect()
return;
}
// Prevent recursion
static bool processingDisconnect = false;
if (processingDisconnect) return;
processingDisconnect = true;
static LongTermTimer processingDisconnectTimer;
if (processingDisconnectTimer.isSet() &&
!processingDisconnectTimer.timeoutReached(200)) return;
processingDisconnectTimer.setNow();
# ifndef BUILD_NO_DEBUG
addLog(LOG_LEVEL_INFO, F("WiFi : WifiDisconnect()"));
#endif
#ifdef ESP32
WiFi.disconnect();
delay(1);
removeWiFiEventHandler();
WiFi.disconnect();
delay(100);
{
const IPAddress ip;
const IPAddress gw;
Expand Down Expand Up @@ -927,7 +937,7 @@ void WifiDisconnect()
WiFiEventData.processingDisconnect.clear();
WiFiEventData.processedDisconnect = false;
processDisconnect();
processingDisconnect = false;
processingDisconnectTimer.clear();
}

// ********************************************************************************
Expand Down
5 changes: 3 additions & 2 deletions src/src/ESPEasyCore/ESPEasyWifi_ProcessEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -590,9 +590,10 @@ void processScanDone() {
addLog(LOG_LEVEL_INFO, F("WiFi : Added known candidate, try to connect"));
}
#endif

#ifdef ESP32
// setSTA(false);
// NetworkConnectRelaxed();
#endif
NetworkConnectRelaxed();
#ifdef USES_ESPEASY_NOW
temp_disable_EspEasy_now_timer = millis() + 20000;
#endif
Expand Down
1 change: 1 addition & 0 deletions src/src/Helpers/Hardware_device_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "../Helpers/Hardware_defines.h"
#include "../Helpers/StringConverter.h"
#include "../Helpers/FS_Helper.h"

#ifdef ESP32
# include <soc/soc.h>
Expand Down
2 changes: 2 additions & 0 deletions src/src/Helpers/StringProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ const __FlashStringHelper * getLabel(LabelType::Enum label) {
case LabelType::ETH_STATE: return F("Eth State");
case LabelType::ETH_SPEED_STATE: return F("Eth Speed State");
case LabelType::ETH_CONNECTED: return F("Eth connected");
case LabelType::ETH_CHIP: return F("Eth chip");
#endif // if FEATURE_ETHERNET
# if FEATURE_ETHERNET || defined(USES_ESPEASY_NOW)
case LabelType::ETH_WIFI_MODE: return F("Network Type");
Expand Down Expand Up @@ -583,6 +584,7 @@ String getValue(LabelType::Enum label) {
case LabelType::ETH_STATE: return EthLinkUp() ? F("Link Up") : F("Link Down");
case LabelType::ETH_SPEED_STATE: return EthLinkUp() ? getEthLinkSpeedState() : F("Link Down");
case LabelType::ETH_CONNECTED: return ETHConnected() ? F("CONNECTED") : F("DISCONNECTED"); // 0=disconnected, 1=connected
case LabelType::ETH_CHIP: return toString(Settings.ETH_Phy_Type);
#endif // if FEATURE_ETHERNET
# if FEATURE_ETHERNET || defined(USES_ESPEASY_NOW)
case LabelType::ETH_WIFI_MODE: return toString(active_network_medium);
Expand Down
1 change: 1 addition & 0 deletions src/src/Helpers/StringProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ struct LabelType {
ETH_STATE,
ETH_SPEED_STATE,
ETH_CONNECTED,
ETH_CHIP,
#endif // if FEATURE_ETHERNET
# if FEATURE_ETHERNET || defined(USES_ESPEASY_NOW)
ETH_WIFI_MODE,
Expand Down
1 change: 1 addition & 0 deletions src/src/WebServer/DevicesPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,7 @@ void devicePage_show_pin_config(taskIndex_t taskIndex, deviceIndex_t DeviceIndex
if (device.PullUpOption)
{
addFormCheckBox(F("Internal PullUp"), F("TDPPU"), Settings.TaskDevicePin1PullUp[taskIndex]); // ="taskdevicepin1pullup"
addFormNote(F("Best to (also) configure pull-up on Hardware tab under \"GPIO boot states\""));
# if defined(ESP8266)

if ((Settings.TaskDevicePin1[taskIndex] == 16) || (Settings.TaskDevicePin2[taskIndex] == 16) ||
Expand Down
1 change: 1 addition & 0 deletions src/src/WebServer/JSON.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ void handle_json()
{
LabelType::ETH_WIFI_MODE,
LabelType::ETH_CONNECTED,
LabelType::ETH_CHIP,
LabelType::ETH_DUPLEX,
LabelType::ETH_SPEED,
LabelType::ETH_STATE,
Expand Down
14 changes: 3 additions & 11 deletions src/src/WebServer/Rules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,17 +552,9 @@ void Rule_showRuleTextArea(const String& fileName) {
addHtml(F("<script>initCM();</script>"));

html_TR_TD();
{
addHtml(F("Current size: <span id='size'>"));
addHtmlInt(size);
addHtml(F("</span> characters (Max "));
addHtmlInt(RULES_MAX_SIZE);
addHtml(F(")"));
}

if (size > RULES_MAX_SIZE) {
addHtml(F("<span style=\"color:red\">Filesize exceeds web editor limit!</span>"));
}
addHtml(F("Current size: <span id='size'>"));
addHtmlInt(size);
addHtml(F("</span> characters"));
}

bool Rule_Download(const String& path)
Expand Down
2 changes: 2 additions & 0 deletions src/src/WebServer/SysInfoPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ void handle_sysinfo_json() {
json_open(false, F("ethernet"));
json_prop(F("ethwifimode"), getValue(LabelType::ETH_WIFI_MODE));
json_prop(F("ethconnected"), getValue(LabelType::ETH_CONNECTED));
json_prop(F("ethchip"), getValue(LabelType::ETH_CHIP));
json_prop(F("ethduplex"), getValue(LabelType::ETH_DUPLEX));
json_prop(F("ethspeed"), getValue(LabelType::ETH_SPEED));
json_prop(F("ethstate"), getValue(LabelType::ETH_STATE));
Expand Down Expand Up @@ -407,6 +408,7 @@ void handle_sysinfo_Ethernet() {

static const LabelType::Enum labels[] PROGMEM =
{
LabelType::ETH_CHIP,
LabelType::ETH_STATE,
LabelType::ETH_SPEED,
LabelType::ETH_DUPLEX,
Expand Down
5 changes: 5 additions & 0 deletions tools/pio/generate_web_flasher_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def parse_filename(file, version, variant, file_suffix):
elif '_16M8M' in variant:
flash_size = '16M8M'
main_group = '16M Flash'

else:
if ".bin" in file_suffix and ".gz" not in file_suffix and 'ESP32' not in variant:
chipFamily = 'ESP8266'
Expand Down Expand Up @@ -379,6 +380,10 @@ def generate_manifest_files(bin_folder, output_prefix):
' <br>\n',
' <br>\n',
' See <a href="latest/" >latest/</a> for a pre-release test build.\n',
' <br>\n',
' See <a href="../" >../</a> for last official build.\n',
' <br>\n',
' <a href="all.zip" >all.zip</a> containing all bin files in a single zip file.\n',
' <script>\n',
' const selectEl = document.querySelector(".pick-variant select");\n',
' const installEl = document.querySelector("esp-web-install-button");\n',
Expand Down

0 comments on commit dfe2bda

Please sign in to comment.