Skip to content

Commit 757b6ec

Browse files
committed
Avoid WiFi static buffer
Static buffers fix the ESP-Now multicast issue, but break WiFi normally. Thus, only use static buffers when only ESP-Now is on. It's not yet clear if we can have both WiFi and ESP-Now Multicast. There may be a fix in v2.0.4.
1 parent a93bf56 commit 757b6ec

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

Firmware/RTK_Surveyor/WiFi.ino

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,16 +209,25 @@ void wifiStart(char* ssid, char* pw)
209209
#ifdef COMPILE_WIFI
210210
if ((wifiState == WIFI_OFF) || (wifiState == WIFI_ON))
211211
{
212-
WiFi.useStaticBuffers(true); //Fix for one to many ESP-Now bug, prior to ESP32 core v2.0.4: https://github.com/espressif/esp-idf/issues/8992
213-
WiFi.mode(WIFI_STA);
214212

215213
#ifdef COMPILE_ESPNOW
216214
if (espnowState > ESPNOW_OFF)
215+
{
216+
WiFi.mode(WIFI_MODE_NULL); //We must go Null before setting static buffers
217+
WiFi.useStaticBuffers(true); //Fix for one to many ESP-Now bug, prior to ESP32 core v2.0.4: https://github.com/espressif/esp-idf/issues/8992
218+
WiFi.mode(WIFI_STA);
219+
217220
esp_wifi_set_protocol(WIFI_IF_STA, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N | WIFI_PROTOCOL_LR); //Enable WiFi + ESP-Now
221+
}
218222
else
223+
{
224+
WiFi.mode(WIFI_STA);
225+
219226
esp_wifi_set_protocol(WIFI_IF_STA, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N); //Set basic WiFi protocols
227+
}
220228
#else
221229
//Be sure the standard protocols are turned on. ESP Now have have previously turned them off.
230+
WiFi.mode(WIFI_STA);
222231
esp_wifi_set_protocol(WIFI_IF_STA, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N);
223232
#endif
224233

@@ -257,6 +266,7 @@ void wifiStop()
257266
//If ESP-Now is active, change protocol to only Long Range
258267
else if (espnowState > ESPNOW_OFF)
259268
{
269+
WiFi.mode(WIFI_MODE_NULL); //We must go Null before setting static buffers
260270
WiFi.useStaticBuffers(true); //Fix for one to many ESP-Now bug, prior to ESP32 core v2.0.4: https://github.com/espressif/esp-idf/issues/8992
261271
WiFi.mode(WIFI_STA);
262272

0 commit comments

Comments
 (0)