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

Add Non-blocking Version of localIP Function for WiFiS3 library and fix FifoBuffer.h #408

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

MYusufY
Copy link

@MYusufY MYusufY commented Nov 30, 2024

This PR introduces a non-blocking version of the localIP function, named localIPNonBlocking, to the WiFi.cpp file. The new function addresses situations where the current localIP implementation, which uses a blocking delay(100) call, can cause issues such as triggering a watchdog timer (WDT).

This PR also solves:

New Function: localIPNonBlocking

Added to libraries/WiFiS3/src/WiFi.cpp at line 357 (after the existing localIP implementation).
Utilizes a timeout mechanism with millis() to avoid blocking delays.
Returns the device's local IP address or a default address (0.0.0.0) if the timeout expires.

Example Usage:

unsigned long timeout = 5000; // 5-second timeout
IPAddress ip = WiFi.localIPNonBlocking(timeout);

if (ip) {
    Serial.println(ip); // Print the IP if successfully retrieved
} else {
    Serial.println("Failed to get IP within the timeout period");
}

@CLAassistant
Copy link

CLAassistant commented Nov 30, 2024

CLA assistant check
All committers have signed the CLA.

@JAndrassy
Copy link
Contributor

the localIP() function just gets the IP from the esp32 over UART. it should be quick

this platform has more networking libraries so please add to the title that this is about WiFiS3 library

@MYusufY MYusufY changed the title Add Non-blocking Version of localIP Function Add Non-blocking Version of localIP Function for WiFiS3 library Nov 30, 2024
@per1234 per1234 added type: enhancement Proposed improvement topic: code Related to content of the project itself labels Nov 30, 2024
@per1234 per1234 linked an issue Nov 30, 2024 that may be closed by this pull request
@MYusufY MYusufY changed the title Add Non-blocking Version of localIP Function for WiFiS3 library Add Non-blocking Version of localIP Function for WiFiS3 library and fix FifoBuffer.h Dec 1, 2024
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you have any good reasons to make changes to this file? If not I would recommend you to drop them and open a new PR with these changes instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is better to override the functionality of localIP() instead of writing a new one. I think you had a good Idea to specify in the function signature the timeout, so I would keep it, but with the addition of making it default to _timeout value. Could you also modify the comment above accordingly?

Copy link
Contributor

Choose a reason for hiding this comment

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

As described in WiFi.h file I would integrate these changes in localIP() function.

Copy link
Contributor

@andreagilardoni andreagilardoni left a comment

Choose a reason for hiding this comment

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

Hi @MYusufY, thanks for your contribution! Your work is very much appreciated! I am suggesting you some changes in order for your PR to properly address some issues we are facing.

@andreagilardoni
Copy link
Contributor

I would also change the PR name, since we are changing the behavior from an attempt based approach to a timeout based one. The function is still blocking, but now the user may set the timeout to 0 to make it non blocking and deal with the logic of retrial on his own.

@MYusufY
Copy link
Author

MYusufY commented Feb 12, 2025

Thanks for your interest! I will try to make these changes and create a new PR soon. Also, i think i accidentaly edited that file :) (the one i put a space below)

@andreagilardoni
Copy link
Contributor

Don't worry, I can guide you through this and fix this PR, you don't need to open a new one for this feature.

The usual method to contribute on github is to create a branch on your personal fork of the repo you are contributing to. That way you can always go back to the public repo status with git checkout. Please tell me if you need any help on that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: enhancement Proposed improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Non-blocking version of WiFi::localIP()
5 participants