Skip to content

Commit 72a55a0

Browse files
committed
Stop/start ESP-Now when starting WiFi
Prevents AUTH_EXP errors
1 parent f191b76 commit 72a55a0

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Firmware/RTK_Surveyor/WiFi.ino

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,15 +209,23 @@ bool wifiConnectionTimeout()
209209
void wifiStart(char* ssid, char* pw)
210210
{
211211
#ifdef COMPILE_WIFI
212+
bool restartESPNow = false;
213+
212214
if ((wifiState == WIFI_OFF) || (wifiState == WIFI_ON))
213215
{
214216
wifiSetState(WIFI_NOTCONNECTED);
215217

216218
#ifdef COMPILE_ESPNOW
217219
if (espnowState > ESPNOW_OFF)
220+
{
221+
restartESPNow = true;
222+
espnowStop();
218223
esp_wifi_set_protocol(WIFI_IF_STA, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N | WIFI_PROTOCOL_LR); //Enable WiFi + ESP-Now. Stops WiFi Station.
224+
}
219225
else
226+
{
220227
esp_wifi_set_protocol(WIFI_IF_STA, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N); //Set basic WiFi protocols. Stops WiFi Station.
228+
}
221229
#else
222230
//Be sure the standard protocols are turned on. ESP Now have have previously turned them off.
223231
esp_wifi_set_protocol(WIFI_IF_STA, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N); //Set basic WiFi protocols. Stops WiFi Station.
@@ -229,6 +237,11 @@ void wifiStart(char* ssid, char* pw)
229237
WiFi.begin(ssid, pw);
230238
wifiTimer = millis();
231239

240+
#ifdef COMPILE_ESPNOW
241+
if (restartESPNow == true)
242+
espnowStart();
243+
#endif
244+
232245
//Display the heap state
233246
reportHeapNow();
234247
}

0 commit comments

Comments
 (0)