JAndrassy / WiFiEspAT

Arduino networking library. Standard Arduino WiFi networking API over ESP8266 or ESP32 AT commands.
GNU Lesser General Public License v2.1
271 stars 44 forks source link

WifiClient has no setConnectionTimeout #111

Closed lomithrani closed 10 months ago

lomithrani commented 10 months ago

Hello,

First and foremost thanks for your amazing library !

Just a small issue (I solved doing an ugly fix for now) when trying to connect to a server that doesn't exist or isn't responding connect hangs. It would be nice to have an option to setConnectionTimeout.

JAndrassy commented 10 months ago

there is no AT command or parameter to set a connect timeout and the library must always wait until the AT firmware finishes the command with OK or ERROR.

lomithrani commented 10 months ago

@JAndrassy thanks for the answer ! Could you elaborate why this should be a requirement ? For instance I'm using WifiClient with HttpClient arduino and every 10 seconds I post some data. If for some reason the server is down I can't have my connect function holding my program for 30 (?) seconds

JAndrassy commented 10 months ago

because until the AT firmware didn't finish the execution of an AT command, it will not accept any other command. there is no way to abort execution of the current command.
it would require additional state and logic to recover from unknown state of then communication with the AT firmware. the next function of the library would still have to wait or fail.

JAndrassy commented 10 months ago

you could use WiFi.ping to check if the IP is up

lomithrani commented 9 months ago

@JAndrassy Doesnt't the Maintain() in Wifi.ping which calls EspAtDrvClass::readRX result in the exact same issue ? I've added a simple :

    currentMillis = millis();

    if (timeoutOn && (currentMillis - startMillis >= 1000)) // TODO REMOVE THIS ATROCITY
    {
      return false;
    }

In the while loop of EspAtDrvClass::readRX for now. If I find time to do it properly with recovery I'll hit you up with a PR !

JAndrassy commented 9 months ago

I would expect ping to return faster than connect if the server is not reachable.

readRX is where it waits. there is a timeout, but if that timeout happens, next library function calls may fail too.