Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WiFi.localIP() reports 0.0.0.0 after succesfull connect - Arduino Core 3.0.7 #10580

Closed
1 task done
CelliesProjects opened this issue Nov 6, 2024 · 6 comments · Fixed by #10595
Closed
1 task done
Assignees
Labels
Area: BT&Wifi BT & Wifi related issues Status: In Progress Issue is in progress
Milestone

Comments

@CelliesProjects
Copy link
Contributor

CelliesProjects commented Nov 6, 2024

Board

esp32-s3

Device Description

Just a plain old esp32-s3

Hardware Configuration

Nothing of consequence

Version

v3.0.7

IDE Name

PlatformIO

Operating System

Mint Linux

Flash frequency

80

PSRAM enabled

yes

Upload speed

921600

Description

WiFi.localIP() should report the IP address. Instead it displays 0.0.0.0 after a succesfull connection. After a while it does show the correct IP.

Fix

A quick fix here was to change isConnected() in WiFiSTA.cpp to the snippet below.

This change gives the expected behaviour.

/**
 * is STA interface connected?
 * @return true if STA is connected and has a IP
 */
bool WiFiSTAClass::isConnected() {
  return STA.connected() && STA.hasIP();
}

Sketch

#include <Arduino.h>
#include <WiFi.h>

const char *SSID = "xxx";
const char *PSK = "xxx";

void setup()
{
    Serial.begin(115200);
    while (!Serial)
        delay(10);

    Serial.println("connecting..");

    WiFi.begin(SSID, PSK);

    while (!WiFi.isConnected())
        delay(10);

    Serial.println(WiFi.localIP());
}

void loop()
{
    delay(1000);
    Serial.println(WiFi.localIP());
}

Debug Message

connecting..
0.0.0.0
192.168.0.253
192.168.0.253
192.168.0.253
192.168.0.253
192.168.0.253
192.168.0.253
192.168.0.253
192.168.0.253

Other Steps to Reproduce

I did not try any other hw.

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@CelliesProjects CelliesProjects added the Status: Awaiting triage Issue is waiting for triage label Nov 6, 2024
@CelliesProjects CelliesProjects changed the title WiFi.localIP() reports 0.0.0.0 after succesfull connect on Arduino Core 3.0.7 WiFi.localIP() reports 0.0.0.0 after succesfull connect - Arduino Core 3.0.7 Nov 6, 2024
@SuGlider SuGlider self-assigned this Nov 7, 2024
@TD-er
Copy link
Contributor

TD-er commented Nov 9, 2024

I do agree it may sound confusing, but I am not sure this really is a bug.
Afterall these are two quite different concepts, connected and gotIP.
It can take a while to get an IP from the DHCP server, especially for IPv6 it may take several seconds.

Not sure what "Arduino" claims how 'connected' should be interpreted.

@CelliesProjects
Copy link
Contributor Author

@TD-er Maybe not all, but most example sketches for esp32 use this construct to connect to WiFi.

    while (!WiFi.isConnected())
        delay(10);

I don't claim it is a bug, but it surprised me. And my assumptions about code behaviour might be wrong.

@TD-er
Copy link
Contributor

TD-er commented Nov 9, 2024

Yep, that's why I also wonder what "the Arduino" expected interpretation should be.

@SuGlider
Copy link
Collaborator

SuGlider commented Nov 9, 2024

@me-no-dev - FYI.

Issue report confirmed. This behaviour started with Arduino Core 3.0.0.
Such behaviour is not noticed with Arduino Core 2.0.17, which marks a change break.

Arduino WiFi Library (upstream) has no isConnect() API.
It relies on status() to know when it is connected to WiFi.
https://docs.arduino.cc/libraries/wifi/

Possible Status are:

typedef enum {
	WL_NO_SHIELD = 255,
        WL_IDLE_STATUS = 0,
        WL_NO_SSID_AVAIL,
        WL_SCAN_COMPLETED,
        WL_CONNECTED,
        WL_CONNECT_FAILED,
        WL_CONNECTION_LOST,
        WL_DISCONNECTED
} wl_status_t;

The WiFi Arduino API may consider implicitly that as soon as status is WL_CONNECT, there is a valid IP address associated.

The current behaviour may be acceptable or not. We will discuss it internally.
I'll report here the results.

@SuGlider SuGlider added Area: BT&Wifi BT & Wifi related issues Status: In Progress Issue is in progress and removed Status: Awaiting triage Issue is waiting for triage labels Nov 9, 2024
@SuGlider
Copy link
Collaborator

Decision: We will change WiFi.isConnected() to only return when WiFi is connected and ESP32 has got an IP address to make it work as before. I'll add a PR to fix it.

@SuGlider
Copy link
Collaborator

@CelliesProjects - Thank you for the report and quick fix. We will apply it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: BT&Wifi BT & Wifi related issues Status: In Progress Issue is in progress
Projects
None yet
4 participants