I am using Arduino to program some ESP32-WROOM-32U modules on different projects. To use the Long Range function I have included 2 libraries #include <WiFi.h> and #include <esp_wifi.h> In the sketch I use esp_wifi_set_protocol( WIFI_IF_STA, WIFI_PROTOCOL_LR );
The problem I have is that although the sketch will work perfectly for days, occasionally the ESP32 will not connect anymore. No amount of resetting, reloading will restore it's ability to wifi connect. The only way I can recover the ESP32 is to perform a Flash Erase and reload the sketch, and everything is back to normal. I have heard that I should not use WiFi.h and esp_wifi.h in the same sketch.
However there are numerous examples of this on the internet and I know of no other way to start LongRange.
By experimenting I have discovered that i can induce the problem at will by running a sketch that attempts a second connect whilst already connected. Once that is attempted the ESP32 remains wifi 'dead' until Flash Erased.
Clearly i am doing something wrong [ a little knowledge is a dangerous thing! ] but I would like to be able to reliably use the LR function.
I will post the 'kill ESP32 wifi' sketch below, in case anyone is interested to look into this. But have a Flash Erase tool handy !
#include <WiFi.h>
#include <esp_wifi.h>
const char* ssid = "xxx";
const char* password = "zzz";
float kattempt = 0;
int kill=1; // Change this to kill=1 to issue 2nd connect and kill ESP32
void setup() {
// FIRST CONNECT
Serial.begin(9600); delay(500);
Serial.println("Start Konnect 1");
esp_wifi_set_protocol( WIFI_IF_STA, WIFI_PROTOCOL_LR );
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(400);
Serial.println("...");
kattempt++;
if (kattempt>20) {kattempt=0;WiFi.disconnect();
Serial.print("Connect 1 FAILED");
return; }
}
Serial.print("#1 WiFi connected with IP: ");
if (kill==1) {
Serial.println("Start Konnect 2");
esp_wifi_set_protocol( WIFI_IF_STA, WIFI_PROTOCOL_LR );
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(400);
Serial.println("///");
kattempt++;
if (kattempt>20) {kattempt=0;WiFi.disconnect();
Serial.println("Connect 2 FAILED");
return; }
}
Serial.print("#2 WiFi connected with IP: ");
}
}
void loop() {
// put your main code here, to run repeatedly:
}
ESP32U loses ability to connect........permanently
Who is online
Users browsing this forum: Baidu [Spider] and 91 guests