arduino-libraries / WiFiNINA

140 stars 106 forks source link

client.connect() waits 28,5 seconds if cant connect #144

Open Alexander96f opened 3 years ago

Alexander96f commented 3 years ago

Version: 1.4.2 Device: Arduino Nano 33 IOT

Hello folks, if I use client.connect to connect to a specific device in my Network its takes exactly 28500ms till it returns false when the device is not connected to the network. While this time the program is stuck cause it waits for the method to finish.

For me those 28,5 Seconds are too long I want it to be like 3-4 Seconds so I can quickly give an output that the Device could not be found in the network and that's it.

The problem is I don't really understand the Code of the connect method:

The comment there says it should take like 4 Seconds for the connection to close? The code says to wait 10 seconds?? My Serial says its exactly 28,5 seconds???

If I just change the code in the WiFiNINA library from 10000ms to 1000ms it reduces the time exactly for 9 seconds so it still takes 19,5 Seconds to return false.

I have no idea where those 18500ms get from ?

Does anybody has a clue how I get it to just try to connect for like 4 seconds?

lasselukkari commented 3 years ago

This just an assumption that I have not verified. The nina-fw running on the ESP32 chip (kinda) uses the Arduino framework too. I don't see the timeout value being propagated there at all. At least the CommandHandler.cpp does not seem to have a functionality to change this. Most likely on the nina-fw side the default timeout values is still being used.

I just bought a the MKR WiFi 1010 board recently because user of my library had some problems with it. I have been surprised to see how bad the software quality is considering this an official Arduino board that costs a lot of money. In this state I would not recommend this software/hardware stack to anyone. For many people Arduino is their first touch to embedded systems. It sad to think that so many people are having problems with these sort of things. The whole point of the simplification the Arduino provides is that things should just work. Sorry for the rant...

lasselukkari commented 3 years ago

The ESP32 Arduino core has a version of connect with timeout: https://github.com/espressif/arduino-esp32/blob/master/libraries/WiFi/src/WiFiClient.h#L51-L54

The arduino Ethernet client has a separate function for setting the timeout used in the client.connect and client.stop: https://www.arduino.cc/en/Reference/EthernetClientSetConnectionTimeout https://github.com/arduino-libraries/Ethernet/blob/master/src/Ethernet.h#L241

The version used in nina-fm has neither: https://github.com/arduino/nina-fw/blob/master/arduino/libraries/WiFi/src/WiFiClient.h

So most likely the version used in nina-fm just uses the default value set in the esp-idf.

winner10920 commented 3 years ago

I think it may have to do with the fact that the Samd communicates with the nina module over SPI. There are two hidden delays of 10000 deep in the code that have to do with waiting for the module, so perhaps the nina module locks up from trying to connect and that long delay is from the module not communicating

lawtalker commented 2 years ago

Are there any plans to address this? It would be great if there was a way to give up on a connection more quickly.

Uup115 commented 2 years ago

I've been struggling with this for quite a while. I haven't been able to find a workaround. See here: https://github.com/arduino-libraries/WiFiNINA/issues/207

mba1959 commented 1 year ago

I have the same problem, so hopefully something will happen...

JAndrassy commented 1 year ago

you can make this modification to shorten the timeout to 18 seconds https://github.com/arduino-libraries/WiFiNINA/pull/224/files