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

fix(wifi): fixes WiFi.isconnected() to return true when it is connected and it has an IP Addr #10595

Merged
merged 2 commits into from
Nov 11, 2024

Conversation

SuGlider
Copy link
Collaborator

Description of Change

After 3.0.x (including 3.1.x) the function WiFiSTAClass::isConnected() returns when it is connected to the WiFi AP but not necessarily when it has an IP address.
This is a breaking change because 2.0.x only returns true when both, it is connected and it has an IP.

This PR fixes it.

Tests scenarios

#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());
}

Related links

Fix #10580

@SuGlider SuGlider added the Area: WiFi Issue related to WiFi label Nov 11, 2024
@SuGlider SuGlider added this to the 3.1.0 milestone Nov 11, 2024
@SuGlider SuGlider self-assigned this Nov 11, 2024
Copy link
Contributor

github-actions bot commented Nov 11, 2024

Messages
📖 🎉 Good Job! All checks are passing!

👋 Hello SuGlider, we appreciate your contribution to this project!


Click to see more instructions ...


This automated output is generated by the PR linter DangerJS, which checks if your Pull Request meets the project's requirements and helps you fix potential issues.

DangerJS is triggered with each push event to a Pull Request and modify the contents of this comment.

Please consider the following:
- Danger mainly focuses on the PR structure and formatting and can't understand the meaning behind your code or changes.
- Danger is not a substitute for human code reviews; it's still important to request a code review from your colleagues.
- To manually retry these Danger checks, please navigate to the Actions tab and re-run last Danger workflow.

Review and merge process you can expect ...


We do welcome contributions in the form of bug reports, feature requests and pull requests.

1. An internal issue has been created for the PR, we assign it to the relevant engineer.
2. They review the PR and either approve it or ask you for changes or clarifications.
3. Once the GitHub PR is approved we do the final review, collect approvals from core owners and make sure all the automated tests are passing.
- At this point we may do some adjustments to the proposed change, or extend it by adding tests or documentation.
4. If the change is approved and passes the tests it is merged into the default branch.

Generated by 🚫 dangerJS against 877d497

Copy link
Contributor

github-actions bot commented Nov 11, 2024

Test Results

 56 files   56 suites   4m 14s ⏱️
 21 tests  21 ✅ 0 💤 0 ❌
134 runs  134 ✅ 0 💤 0 ❌

Results for commit 877d497.

♻️ This comment has been updated with latest results.

@SuGlider SuGlider added the Status: Review needed Issue or PR is awaiting review label Nov 11, 2024
@@ -215,7 +215,7 @@ bool WiFiSTAClass::bandwidth(wifi_bandwidth_t bandwidth) {
* @return true if STA is connected to an AP
*/
bool WiFiSTAClass::isConnected() {
return STA.connected();
return STA.connected() && STA.hasIP();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just STA.hasIP() is enough here. You can not have IP if you are not connected.

Copy link
Collaborator Author

@SuGlider SuGlider Nov 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if it is configured as static IP?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are correct. hasIP() checks if either IP has been assigned or that it has static. Since even when static GOT_IP event is received, maybe worth changing there too. Not sure what is more correct for gotIP(), but we can discuss that later.

@me-no-dev me-no-dev added Status: Pending Merge Pull Request is ready to be merged and removed Status: Review needed Issue or PR is awaiting review labels Nov 11, 2024
@me-no-dev me-no-dev merged commit e99f1fd into master Nov 11, 2024
80 of 85 checks passed
@me-no-dev me-no-dev deleted the wifi_is_connected branch November 11, 2024 23:00
UnexpectedMaker added a commit to UnexpectedMaker/arduino-esp32 that referenced this pull request Nov 18, 2024
@beta-tester
Copy link

i have a question.
how is or was the logic for WiFi.status() ?

if (WiFi.status() == WL_CONNECTED) {
}

does WL_CONNECTED mean connected and got an IP as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: WiFi Issue related to WiFi Status: Pending Merge Pull Request is ready to be merged
Projects
Development

Successfully merging this pull request may close these issues.

WiFi.localIP() reports 0.0.0.0 after succesfull connect - Arduino Core 3.0.7
4 participants