i most likely doing something incorrect. Appreciate pointing out my mistakes.
Code: Select all
#include <WiFi.h>
const char* ssid = "myssid";
const char* password = "very_big_secret";
void connectToNetwork() {
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Establishing connection to WiFi..");
}
Serial.println("Connected to network");
}
void setup() {
Serial.begin(115200);
connectToNetwork();
Serial.println(WiFi.macAddress());
Serial.println(WiFi.localIP());
}
void loop() {
static long oldTime = 0;
uint8_t counter = 0;
if (( millis() - oldTime ) >= 5000) { //5 seconds check
oldTime = millis();
if (WiFi.getMode() == WIFI_MODE_STA && WiFi.status() != WL_CONNECTED ) {
Serial.println("Wifi is not connected ");
Serial.printf("Mode - %d, connection status - %d \n" ,WiFi.getMode(),WiFi.status());
Serial.println("Reconnecting....");
connectToNetwork();
}
}
}
what i observe is :
1. after a minute or so, i finally start getting reply from the host :
Code: Select all
From 192.168.1.5 icmp_seq=433 Destination Host Unreachable
From 192.168.1.5 icmp_seq=434 Destination Host Unreachable
From 192.168.1.5 icmp_seq=435 Destination Host Unreachable
From 192.168.1.5 icmp_seq=436 Destination Host Unreachable
From 192.168.1.5 icmp_seq=437 Destination Host Unreachable
64 bytes from 192.168.1.17: icmp_seq=438 ttl=255 time=2097 ms
64 bytes from 192.168.1.17: icmp_seq=439 ttl=255 time=1076 ms
64 bytes from 192.168.1.17: icmp_seq=440 ttl=255 time=54.7 ms
64 bytes from 192.168.1.17: icmp_seq=443 ttl=255 time=730 ms
64 bytes from 192.168.1.17: icmp_seq=452 ttl=255 time=591 ms
64 bytes from 192.168.1.17: icmp_seq=461 ttl=255 time=358 ms
64 bytes from 192.168.1.17: icmp_seq=468 ttl=255 time=1279 ms
64 bytes from 192.168.1.17: icmp_seq=469 ttl=255 time=256 ms
64 bytes from 192.168.1.17: icmp_seq=474 ttl=255 time=1147 ms
64 bytes from 192.168.1.17: icmp_seq=475 ttl=255 time=187 ms
2. after some time (within 5minutes). the reply becomes unstable and eventually stops:
Code: Select all
From 192.168.1.5 icmp_seq=557 Destination Host Unreachable
From 192.168.1.5 icmp_seq=558 Destination Host Unreachable
From 192.168.1.5 icmp_seq=559 Destination Host Unreachable
64 bytes from 192.168.1.17: icmp_seq=569 ttl=255 time=937 ms
From 192.168.1.5 icmp_seq=570 Destination Host Unreachable
From 192.168.1.5 icmp_seq=571 Destination Host Unreachable
From 192.168.1.5 icmp_seq=572 Destination Host Unreachable
From 192.168.1.5 icmp_seq=573 Destination Host Unreachable
at the time of writing, I got lucky and it did succeed in reconnecting. But all day yesterday it would return WL_DISCONNECTED and WL_IDLE_STATUS during the reconnect attempts.
This is regular home wifi. the laptop esp is connected to does not drop connection at the time of the experiment.
P.S. I have 2 ESp32 ( dev1 Kits ), they both exibit the same exact behaviour .
P.P.S. something new WL_CONNECTION_LOST and after reconnect - stable ping replies.