'ESP8266 Station connection to Raspberry PI Access Point is stable but ESP32 connection breaks after 3 seconds

  1. Have a Raspberry PI configured to be Access Point
  2. I write the code under Arduino IDE
  3. I created a simple code for ESP8266 to connect to the Access Point
// Code for ESP8266

#include <ESP8266WiFi.h>

char* ssid = "Central-Station-006";
char* password = "*****";

void setup() {
  
  Serial.begin(115200);
  
  Serial.print("\nConnecting to ");
  Serial.print(ssid);
  Serial.print(" ");
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  // Print local IP address and start web server
  Serial.println("");
  Serial.print("WiFi connected. ");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

}

void loop() {
  Serial.println(WiFi.status());
  delay(1000);  
}
  1. The output on the Serial is this:
WiFi connected. IP address: 192.168.50.106
3
3
3
3
7
3
3
3
3
7
3
3
3
3
7
7
3

  1. I started the ping on console before the code started to run. I got this:
pi@raspberrypi:~/.greenwall $ ping 192.168.50.106
PING 192.168.50.106 (192.168.50.106) 56(84) bytes of data.
From 192.168.50.3 icmp_seq=13 Destination Host Unreachable
From 192.168.50.3 icmp_seq=14 Destination Host Unreachable
From 192.168.50.3 icmp_seq=15 Destination Host Unreachable
From 192.168.50.3 icmp_seq=16 Destination Host Unreachable
From 192.168.50.3 icmp_seq=17 Destination Host Unreachable
From 192.168.50.3 icmp_seq=18 Destination Host Unreachable
64 bytes from 192.168.50.106: icmp_seq=20 ttl=255 time=20.4 ms
64 bytes from 192.168.50.106: icmp_seq=21 ttl=255 time=5.75 ms
64 bytes from 192.168.50.106: icmp_seq=22 ttl=255 time=5.44 ms
64 bytes from 192.168.50.106: icmp_seq=25 ttl=255 time=20.5 ms
64 bytes from 192.168.50.106: icmp_seq=26 ttl=255 time=5.66 ms
64 bytes from 192.168.50.106: icmp_seq=27 ttl=255 time=4.73 ms
64 bytes from 192.168.50.106: icmp_seq=30 ttl=255 time=17.8 ms
64 bytes from 192.168.50.106: icmp_seq=31 ttl=255 time=5.05 ms
64 bytes from 192.168.50.106: icmp_seq=32 ttl=255 time=9.61 ms
64 bytes from 192.168.50.106: icmp_seq=35 ttl=255 time=20.5 ms
64 bytes from 192.168.50.106: icmp_seq=36 ttl=255 time=2.51 ms
64 bytes from 192.168.50.106: icmp_seq=37 ttl=255 time=5.32 ms
64 bytes from 192.168.50.106: icmp_seq=42 ttl=255 time=8.21 ms
64 bytes from 192.168.50.106: icmp_seq=45 ttl=255 time=8.35 ms
64 bytes from 192.168.50.106: icmp_seq=46 ttl=255 time=5.78 ms
64 bytes from 192.168.50.106: icmp_seq=47 ttl=255 time=5.47 ms

Result: EVERYTHING LOOKS OK So now, I try to do the same on a ESP32 module

  1. The code is here. The only difference is the "include"
#include <WiFi.h>

// Code for ESP32
char* ssid = "Central-Station-006";
char* password = "*****";

void setup() {
  
  Serial.begin(115200);
  
  Serial.print("\nConnecting to ");
  Serial.print(ssid);
  Serial.print(" ");
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  // Print local IP address and start web server
  Serial.println("");
  Serial.print("WiFi connected. ");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

}

void loop() {
  Serial.println(WiFi.status());
  delay(1000);  
}
  1. Here is the Serial output:
Connecting to Central-Station-006 ...
WiFi connected. IP address: 192.168.50.109
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
6
6
6

  1. Here is the result of the ping on the console. (I started it before the code)
From 192.168.50.3 icmp_seq=4 Destination Host Unreachable
From 192.168.50.3 icmp_seq=5 Destination Host Unreachable
From 192.168.50.3 icmp_seq=6 Destination Host Unreachable
From 192.168.50.3 icmp_seq=7 Destination Host Unreachable
From 192.168.50.3 icmp_seq=8 Destination Host Unreachable
From 192.168.50.3 icmp_seq=9 Destination Host Unreachable
From 192.168.50.3 icmp_seq=10 Destination Host Unreachable
From 192.168.50.3 icmp_seq=11 Destination Host Unreachable
From 192.168.50.3 icmp_seq=12 Destination Host Unreachable
From 192.168.50.3 icmp_seq=13 Destination Host Unreachable
From 192.168.50.3 icmp_seq=14 Destination Host Unreachable
From 192.168.50.3 icmp_seq=15 Destination Host Unreachable
64 bytes from 192.168.50.109: icmp_seq=16 ttl=255 time=2748 ms
64 bytes from 192.168.50.109: icmp_seq=17 ttl=255 time=1710 ms
64 bytes from 192.168.50.109: icmp_seq=18 ttl=255 time=670 ms
64 bytes from 192.168.50.109: icmp_seq=20 ttl=255 time=102 ms
From 192.168.50.3 icmp_seq=27 Destination Host Unreachable
From 192.168.50.3 icmp_seq=28 Destination Host Unreachable
From 192.168.50.3 icmp_seq=29 Destination Host Unreachable
From 192.168.50.3 icmp_seq=30 Destination Host Unreachable
From 192.168.50.3 icmp_seq=31 Destination Host Unreachable
From 192.168.50.3 icmp_seq=32 Destination Host Unreachable
From 192.168.50.3 icmp_seq=33 Destination Host Unreachable
From 192.168.50.3 icmp_seq=34 Destination Host Unreachable
From 192.168.50.3 icmp_seq=35 Destination Host Unreachable
From 192.168.50.3 icmp_seq=36 Destination Host Unreachable
From 192.168.50.3 icmp_seq=37 Destination Host Unreachable
From 192.168.50.3 icmp_seq=38 Destination Host Unreachable

Expected result: I expected the ping could reach the host until the ESP32 is ON Actual result:

  1. After the code started, the ping command could reach the ESP32, then after 3 seconds it is not able to reach it anymore
  2. When the code started to run, the WiFi status was 3=WL_CONNECTED. But after 20 seconds the WiFi status changed to 6=WL_CONNECT_WRONG_PASSWORD. It does not make too much sense as the connection was already OK. Plus, using the same password, the ESP8266 was totally satisfied

Comments:

  1. I have other ESP32 modules, and I got the same result. So I think it is ESP32 specific issue
  2. I'd like to emphasize the timing. After 3 seconds, the ping was not able to find the node, but the status of the WiFi was still 3=WL_CONNECTED. The WiFi status changed only 20 seconds later

Can you help me to find out what went wrong here?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source