Skip to content

Commit dfe2bda

Browse files
authored
Merge pull request #4975 from TD-er/bugfix/esp32_wifi_connect
[WiFi] Fix slow WiFi connect after scan on ESP32
2 parents 75bafa5 + 4cc4f0f commit dfe2bda

16 files changed

+90
-40
lines changed

docs/source/Hardware/Hardware.rst

+2
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,8 @@ Currently the default SPI frequency of 20 MHz is used, so not all other SPI devi
323323

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

326+
.. 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.
327+
326328

327329
GPIO Configuration
328330
""""""""""""""""""

docs/source/Reference/SPI_Ethernet_ESP32_boards.rst

+24-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ N.B. As there is not yet support in ESPEasy for multiple SPI busses, it cannot b
3636
- 3
3737
- 10
3838
- SPI2_HOST
39+
* - M5Stack PoECAM
40+
- ESP32-classic
41+
- W5500
42+
-
43+
- 4
44+
-
45+
-
46+
- 23
47+
- 38
48+
- 13
49+
- SPI2_HOST
3950
* - M5Stack Atom PoE Kit (ATOM LITE)
4051
- ESP32-classic
4152
- W5500
@@ -47,6 +58,17 @@ N.B. As there is not yet support in ESPEasy for multiple SPI busses, it cannot b
4758
- 23
4859
- 33
4960
- SPI2_HOST
61+
* - M5Stack Atom PoE Kit (AtomS3)
62+
- ESP32-S3
63+
- W5500
64+
-
65+
- 6
66+
-
67+
-
68+
- 5
69+
- 7
70+
- 8
71+
- SPI2_HOST
5072
* - M5Stack Base LAN (End-of-life)
5173
- M5Core
5274
- W5500
@@ -119,8 +141,9 @@ See:
119141

120142
* `M5 Stack Base LAN <https://docs.m5stack.com/en/base/lan_base>`_
121143
* `M5 Stack LAN Base V12 <https://docs.m5stack.com/en/base/lan_v12>`_
144+
* `M5 Stack PoECAM <https://docs.m5stack.com/en/unit/poe_cam>`_
122145
* `M5 Stack LAN PoE Base V12 <https://docs.m5stack.com/en/base/lan_poe_v12>`_
123146
* `M5 Stack LAN Module V13.2 <https://docs.m5stack.com/en/module/LAN%20Module%2013.2>`_
124-
* `M5 Stack ATOM PoE <https://docs.m5stack.com/en/atom/atom_poe>`_
147+
* `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>`_
125148
* `M5 Stack Base PoE <https://docs.m5stack.com/en/base/w5500PoE>`_
126149
* `TTGO/LilyGO Ethernet boards <https://github.com/Xinyuan-LilyGO/LilyGO-T-ETH-Series/blob/dda7a2ad4ab33d550c8dbaff5db1e61a0eda5aad/examples/ETHOTA/utilities.h#L12>`_

platformio_core_defs.ini

+3-2
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,10 @@ lib_ignore =
208208

209209
; ESP_IDF 5.1
210210
[core_esp32_IDF5_1__3_0_0]
211-
platform = https://github.com/tasmota/platform-espressif32/releases/download/2024.01.11/platform-espressif32.zip
211+
;platform = https://github.com/Jason2866/platform-espressif32.git
212+
platform = https://github.com/tasmota/platform-espressif32/releases/download/2024.02.10/platform-espressif32.zip
212213
;platform_packages =
213-
platform_packages = framework-arduinoespressif32 @ https://github.com/Jason2866/esp32-arduino-lib-builder/releases/download/2010/framework-arduinoespressif32-release_v5.1-4c5ed1f.zip
214+
platform_packages = framework-arduinoespressif32 @ https://github.com/Jason2866/esp32-arduino-lib-builder/releases/download/2036/framework-arduinoespressif32-release_v5.1-246cad0.zip
214215
build_flags = -DESP32_STAGE
215216
-DESP_IDF_VERSION_MAJOR=5
216217
-DLIBRARIES_NO_LOG=1

platformio_esp32_solo1.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ build_unflags = ${esp32_base.build_unflags}
1818
; IDF 5.1.2
1919
[esp32_solo1_common_LittleFS]
2020
extends = esp32_base_idf5
21-
platform_packages = framework-arduino-solo1 @ https://github.com/Jason2866/esp32-arduino-lib-builder/releases/download/2013/framework-arduinoespressif32-solo1-release_v5.1-4c5ed1f.zip
21+
platform_packages = framework-arduino-solo1 @ https://github.com/Jason2866/esp32-arduino-lib-builder/releases/download/2038/framework-arduinoespressif32-solo1-release_v5.1-246cad0.zip
2222
build_flags = ${esp32_base_idf5.build_flags}
2323
-DFEATURE_ARDUINO_OTA=1
2424
-DUSE_LITTLEFS

platformio_esp32s3_envs.ini

+16-13
Original file line numberDiff line numberDiff line change
@@ -138,68 +138,71 @@ build_flags = ${esp32s3_common.build_flags}
138138
-DPLUGIN_NEOPIXEL_COLLECTION
139139

140140

141-
[env:custom_ESP32s3_8M1M_LittleFS_CDC]
141+
[env:custom_ESP32s3_8M1M_LittleFS_CDC_ETH]
142142
extends = esp32s3_common_LittleFS
143143
board = esp32s3cdc-qio_qspi-8M
144144
build_flags = ${esp32s3_common_LittleFS.build_flags}
145+
-DFEATURE_ETHERNET=1
145146
-DFEATURE_ARDUINO_OTA=1
146147
-DPLUGIN_BUILD_CUSTOM
147148
-DFEATURE_SD=1
148149
extra_scripts = ${esp32s3_common_LittleFS.extra_scripts}
149150
pre:tools/pio/pre_custom_esp32.py
150151

151-
[env:custom_ESP32s3_8M1M_LittleFS_OPI_PSRAM_CDC]
152-
extends = env:custom_ESP32s3_8M1M_LittleFS_CDC
152+
[env:custom_ESP32s3_8M1M_LittleFS_OPI_PSRAM_CDC_ETH]
153+
extends = env:custom_ESP32s3_8M1M_LittleFS_CDC_ETH
153154
board = esp32s3cdc-qio_opi-8M
154155

155156

156-
[env:max_ESP32s3_8M1M_LittleFS_CDC]
157+
[env:max_ESP32s3_8M1M_LittleFS_CDC_ETH]
157158
extends = esp32s3_common_LittleFS
158159
board = esp32s3cdc-qio_qspi-8M
159160
build_flags = ${esp32s3_common_LittleFS.build_flags}
161+
-DFEATURE_ETHERNET=1
160162
-DFEATURE_ARDUINO_OTA=1
161163
-DPLUGIN_BUILD_MAX_ESP32
162164
-DPLUGIN_BUILD_IR_EXTENDED
163165
extra_scripts = ${esp32s3_common_LittleFS.extra_scripts}
164166

165167

166-
[env:max_ESP32s3_8M1M_LittleFS_OPI_PSRAM_CDC]
167-
extends = env:max_ESP32s3_8M1M_LittleFS_CDC
168+
[env:max_ESP32s3_8M1M_LittleFS_OPI_PSRAM_CDC_ETH]
169+
extends = env:max_ESP32s3_8M1M_LittleFS_CDC_ETH
168170
board = esp32s3cdc-qio_opi-8M
169171

170172

171-
[env:custom_ESP32s3_16M8M_LittleFS_CDC]
173+
[env:custom_ESP32s3_16M8M_LittleFS_CDC_ETH]
172174
extends = esp32s3_common_LittleFS
173175
board = esp32s3cdc-qio_qspi-16M
174176
build_flags = ${esp32s3_common_LittleFS.build_flags}
177+
-DFEATURE_ETHERNET=1
175178
-DFEATURE_ARDUINO_OTA=1
176179
-DPLUGIN_BUILD_CUSTOM
177180
-DPLUGIN_BUILD_IR_EXTENDED
178181
-DFEATURE_SD=1
179182
extra_scripts = ${esp32s3_common_LittleFS.extra_scripts}
180183
pre:tools/pio/pre_custom_esp32.py
181184

182-
[env:custom_ESP32s3_16M8M_LittleFS_OPI_PSRAM_CDC]
183-
extends = env:custom_ESP32s3_16M8M_LittleFS_CDC
185+
[env:custom_ESP32s3_16M8M_LittleFS_OPI_PSRAM_CDC_ETH]
186+
extends = env:custom_ESP32s3_16M8M_LittleFS_CDC_ETH
184187
board = esp32s3cdc-qio_opi-16M
185188

186189

187-
[env:max_ESP32s3_16M8M_LittleFS_CDC]
190+
[env:max_ESP32s3_16M8M_LittleFS_CDC_ETH]
188191
extends = esp32s3_common_LittleFS
189192
board = esp32s3cdc-qio_qspi-16M
190193
build_flags = ${esp32s3_common_LittleFS.build_flags}
191-
-DUSE_LITTLEFS
194+
-DFEATURE_ETHERNET=1
192195
-DFEATURE_ARDUINO_OTA=1
193196
-DPLUGIN_BUILD_MAX_ESP32
194197
-DPLUGIN_BUILD_IR_EXTENDED
195198
extra_scripts = ${esp32s3_common_LittleFS.extra_scripts}
196199

197200

198-
[env:max_ESP32s3_16M8M_LittleFS_OPI_PSRAM_CDC]
201+
[env:max_ESP32s3_16M8M_LittleFS_OPI_PSRAM_CDC_ETH]
199202
extends = esp32s3_common_LittleFS
200203
board = esp32s3cdc-qio_opi-16M
201204
build_flags = ${esp32s3_common_LittleFS.build_flags}
202-
-DUSE_LITTLEFS
205+
-DFEATURE_ETHERNET=1
203206
-DFEATURE_ARDUINO_OTA=1
204207
-DPLUGIN_BUILD_MAX_ESP32
205208
-DPLUGIN_BUILD_IR_EXTENDED

src/src/ESPEasyCore/ESPEasyEth.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,11 @@ bool ethCheckSettings() {
6969
#endif
7070
&& isValid(Settings.NetworkMedium)
7171
&& validGpio(Settings.ETH_Pin_mdc_cs)
72-
&& validGpio(Settings.ETH_Pin_mdio_irq)
73-
&& (validGpio(Settings.ETH_Pin_power_rst) || (Settings.ETH_Pin_power_rst == -1)); // Some boards have fixed power
72+
&& (isSPI_EthernetType(Settings.ETH_Phy_Type) ||
73+
( validGpio(Settings.ETH_Pin_mdio_irq) &&
74+
(validGpio(Settings.ETH_Pin_power_rst) || (Settings.ETH_Pin_power_rst == -1))
75+
)
76+
); // Some boards have fixed power
7477
}
7578

7679
bool ethPrepare() {
@@ -249,6 +252,8 @@ bool ETHConnectRelaxed() {
249252
// We might miss the connected event, since we are already connected.
250253
EthEventData.markConnected();
251254
}
255+
} else {
256+
addLog(LOG_LEVEL_ERROR, F("ETH : Failed to initialize ETH"));
252257
}
253258
return EthEventData.ethInitSuccess;
254259
}

src/src/ESPEasyCore/ESPEasyWifi.cpp

+18-8
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,19 @@ bool WiFiConnected() {
235235
}
236236
#endif
237237

238+
if (!WifiIsSTA(WiFi.getMode())) {
239+
lastState = false;
240+
return lastState;
241+
}
242+
238243

239244
if (lastCheckedTime != 0 && timePassedSince(lastCheckedTime) < 100) {
240-
// Try to rate-limit the nr of calls to this function or else it will be called 1000's of times a second.
241-
return lastState;
245+
if (WiFiEventData.lastDisconnectMoment.isSet() &&
246+
WiFiEventData.lastDisconnectMoment.millisPassedSince() > timePassedSince(lastCheckedTime))
247+
{
248+
// Try to rate-limit the nr of calls to this function or else it will be called 1000's of times a second.
249+
return lastState;
250+
}
242251
}
243252

244253

@@ -887,16 +896,17 @@ void WifiDisconnect()
887896
return;
888897
}
889898
// Prevent recursion
890-
static bool processingDisconnect = false;
891-
if (processingDisconnect) return;
892-
processingDisconnect = true;
899+
static LongTermTimer processingDisconnectTimer;
900+
if (processingDisconnectTimer.isSet() &&
901+
!processingDisconnectTimer.timeoutReached(200)) return;
902+
processingDisconnectTimer.setNow();
893903
# ifndef BUILD_NO_DEBUG
894904
addLog(LOG_LEVEL_INFO, F("WiFi : WifiDisconnect()"));
895905
#endif
896906
#ifdef ESP32
897-
WiFi.disconnect();
898-
delay(1);
899907
removeWiFiEventHandler();
908+
WiFi.disconnect();
909+
delay(100);
900910
{
901911
const IPAddress ip;
902912
const IPAddress gw;
@@ -927,7 +937,7 @@ void WifiDisconnect()
927937
WiFiEventData.processingDisconnect.clear();
928938
WiFiEventData.processedDisconnect = false;
929939
processDisconnect();
930-
processingDisconnect = false;
940+
processingDisconnectTimer.clear();
931941
}
932942

933943
// ********************************************************************************

src/src/ESPEasyCore/ESPEasyWifi_ProcessEvent.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -590,9 +590,10 @@ void processScanDone() {
590590
addLog(LOG_LEVEL_INFO, F("WiFi : Added known candidate, try to connect"));
591591
}
592592
#endif
593-
593+
#ifdef ESP32
594594
// setSTA(false);
595-
// NetworkConnectRelaxed();
595+
#endif
596+
NetworkConnectRelaxed();
596597
#ifdef USES_ESPEASY_NOW
597598
temp_disable_EspEasy_now_timer = millis() + 20000;
598599
#endif

src/src/Helpers/Hardware_device_info.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "../Helpers/Hardware_defines.h"
44
#include "../Helpers/StringConverter.h"
5+
#include "../Helpers/FS_Helper.h"
56

67
#ifdef ESP32
78
# include <soc/soc.h>

src/src/Helpers/StringProvider.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ const __FlashStringHelper * getLabel(LabelType::Enum label) {
269269
case LabelType::ETH_STATE: return F("Eth State");
270270
case LabelType::ETH_SPEED_STATE: return F("Eth Speed State");
271271
case LabelType::ETH_CONNECTED: return F("Eth connected");
272+
case LabelType::ETH_CHIP: return F("Eth chip");
272273
#endif // if FEATURE_ETHERNET
273274
# if FEATURE_ETHERNET || defined(USES_ESPEASY_NOW)
274275
case LabelType::ETH_WIFI_MODE: return F("Network Type");
@@ -583,6 +584,7 @@ String getValue(LabelType::Enum label) {
583584
case LabelType::ETH_STATE: return EthLinkUp() ? F("Link Up") : F("Link Down");
584585
case LabelType::ETH_SPEED_STATE: return EthLinkUp() ? getEthLinkSpeedState() : F("Link Down");
585586
case LabelType::ETH_CONNECTED: return ETHConnected() ? F("CONNECTED") : F("DISCONNECTED"); // 0=disconnected, 1=connected
587+
case LabelType::ETH_CHIP: return toString(Settings.ETH_Phy_Type);
586588
#endif // if FEATURE_ETHERNET
587589
# if FEATURE_ETHERNET || defined(USES_ESPEASY_NOW)
588590
case LabelType::ETH_WIFI_MODE: return toString(active_network_medium);

src/src/Helpers/StringProvider.h

+1
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ struct LabelType {
212212
ETH_STATE,
213213
ETH_SPEED_STATE,
214214
ETH_CONNECTED,
215+
ETH_CHIP,
215216
#endif // if FEATURE_ETHERNET
216217
# if FEATURE_ETHERNET || defined(USES_ESPEASY_NOW)
217218
ETH_WIFI_MODE,

src/src/WebServer/DevicesPage.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1068,6 +1068,7 @@ void devicePage_show_pin_config(taskIndex_t taskIndex, deviceIndex_t DeviceIndex
10681068
if (device.PullUpOption)
10691069
{
10701070
addFormCheckBox(F("Internal PullUp"), F("TDPPU"), Settings.TaskDevicePin1PullUp[taskIndex]); // ="taskdevicepin1pullup"
1071+
addFormNote(F("Best to (also) configure pull-up on Hardware tab under \"GPIO boot states\""));
10711072
# if defined(ESP8266)
10721073

10731074
if ((Settings.TaskDevicePin1[taskIndex] == 16) || (Settings.TaskDevicePin2[taskIndex] == 16) ||

src/src/WebServer/JSON.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ void handle_json()
299299
{
300300
LabelType::ETH_WIFI_MODE,
301301
LabelType::ETH_CONNECTED,
302+
LabelType::ETH_CHIP,
302303
LabelType::ETH_DUPLEX,
303304
LabelType::ETH_SPEED,
304305
LabelType::ETH_STATE,

src/src/WebServer/Rules.cpp

+3-11
Original file line numberDiff line numberDiff line change
@@ -552,17 +552,9 @@ void Rule_showRuleTextArea(const String& fileName) {
552552
addHtml(F("<script>initCM();</script>"));
553553

554554
html_TR_TD();
555-
{
556-
addHtml(F("Current size: <span id='size'>"));
557-
addHtmlInt(size);
558-
addHtml(F("</span> characters (Max "));
559-
addHtmlInt(RULES_MAX_SIZE);
560-
addHtml(F(")"));
561-
}
562-
563-
if (size > RULES_MAX_SIZE) {
564-
addHtml(F("<span style=\"color:red\">Filesize exceeds web editor limit!</span>"));
565-
}
555+
addHtml(F("Current size: <span id='size'>"));
556+
addHtmlInt(size);
557+
addHtml(F("</span> characters"));
566558
}
567559

568560
bool Rule_Download(const String& path)

src/src/WebServer/SysInfoPage.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ void handle_sysinfo_json() {
147147
json_open(false, F("ethernet"));
148148
json_prop(F("ethwifimode"), getValue(LabelType::ETH_WIFI_MODE));
149149
json_prop(F("ethconnected"), getValue(LabelType::ETH_CONNECTED));
150+
json_prop(F("ethchip"), getValue(LabelType::ETH_CHIP));
150151
json_prop(F("ethduplex"), getValue(LabelType::ETH_DUPLEX));
151152
json_prop(F("ethspeed"), getValue(LabelType::ETH_SPEED));
152153
json_prop(F("ethstate"), getValue(LabelType::ETH_STATE));
@@ -407,6 +408,7 @@ void handle_sysinfo_Ethernet() {
407408

408409
static const LabelType::Enum labels[] PROGMEM =
409410
{
411+
LabelType::ETH_CHIP,
410412
LabelType::ETH_STATE,
411413
LabelType::ETH_SPEED,
412414
LabelType::ETH_DUPLEX,

tools/pio/generate_web_flasher_manifest.py

+5
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ def parse_filename(file, version, variant, file_suffix):
9393
elif '_16M8M' in variant:
9494
flash_size = '16M8M'
9595
main_group = '16M Flash'
96+
9697
else:
9798
if ".bin" in file_suffix and ".gz" not in file_suffix and 'ESP32' not in variant:
9899
chipFamily = 'ESP8266'
@@ -379,6 +380,10 @@ def generate_manifest_files(bin_folder, output_prefix):
379380
' <br>\n',
380381
' <br>\n',
381382
' See <a href="latest/" >latest/</a> for a pre-release test build.\n',
383+
' <br>\n',
384+
' See <a href="../" >../</a> for last official build.\n',
385+
' <br>\n',
386+
' <a href="all.zip" >all.zip</a> containing all bin files in a single zip file.\n',
382387
' <script>\n',
383388
' const selectEl = document.querySelector(".pick-variant select");\n',
384389
' const installEl = document.querySelector("esp-web-install-button");\n',

0 commit comments

Comments
 (0)