0

I'm using the Arduino Wifi Nina Library to connect an Arduino Uno Wifi Rev2 to wifi and then using the Arduino HTTP Client library to make HTTP post calls to the internet.

To connect the Arduino to my home Wifi Network (WPA2 Personal), I use the WiFi.begin() method. This method takes an excruciatingly long 4 seconds to connect to the Wifi. This seems to be a known issue. Since this methods is synchronous/blocking, my sketch is completely unresponsive during this time to any user input such as button-presses etc. I'm trying to create a proof-of-concept for a commercial-grade product. So having it go unresponsive to user-input for several seconds is unacceptable.

Is there any workaround to this? Is there a asynchronous library to achieve the same goal? Is there some other workaround? How do other people deal with this situation?

6
  • wow! four seconds is an excruciatingly long time? ... i think that maybe the problem that needs correcting is not with the arduino ... spend the four seconds looking out the window or at your better half
    – jsotola
    Commented Jun 8, 2020 at 7:49
  • 1
    use WiFi.setTimeout()
    – Juraj
    Commented Jun 13, 2020 at 9:30
  • I don't think WiFi.begin takes four seconds, does it? Sounds to me like you have a loop that is waiting around for WiFi.status==WL_CONNECTED which is taking four seconds. I just tested on my NodeMCU and WiFi.begin() typically completes in just 5 milliseconds.
    – S. Imp
    Commented Jun 16, 2020 at 20:41
  • @S.Imp, yes 5 ms because it is already connected as 'persistent connection'
    – Juraj
    Commented Jun 17, 2020 at 8:11
  • 1
    @S.Imp, but that is on the esp8266 or esp32, not on the Uno WiFi Rev.2 with WiFiNINA library.
    – Juraj
    Commented Jun 17, 2020 at 16:47

3 Answers 3

2
+100

4 even 5 seconds is normal for connecting to WiFi. How long takes your phone or other devices to connect?

You can connect a little faster with static IP address.

EDIT: With WiFiNINA library for Uno WiFi Rev.2, you can change the connection timeout with WiFi.setTimeout(). The default is 5 seconds. WiFi.begin() can end with WL_CONNECT_FAILED but if you later check the status of the connection it will eventually be connected.


With esp8266 or esp32 you can make the connection persistent and it is build up immediately after boot and asynchronously. WiFiNINA library doesn't make this possible yet. Some future version will offer WiFi provisioning.

2
  • So if I switch from WifiNINA to esp8266, then I can connect to the wifi asynchronously?
    – Saqib Ali
    Commented Jun 8, 2020 at 11:05
  • @SaqibAli, yes. but usually setup() runs much faster then the connection is build-up so even then the sketch usually waits some seconds if having network at the end of setup() is needed. you can connect a little faster with static IP address
    – Juraj
    Commented Jun 8, 2020 at 11:37
1

For a proof-of-concept, use two Arduinos, one for WiFi and one for everything else. The everything-else Arduino can keep your system responsive (minus the WiFi, of course, during connection time) and poll the WiFi Arduino periodically (without blocking) to find out when WiFi becomes available.

0

I think better solution is to use ESP8266 WiFi module and Connect if needed another Arduino through GPIO pins of ESP8266.

This video will be helpful, https://www.youtube.com/watch?v=dWM4p_KaTHY

4
  • better then what?
    – Juraj
    Commented Jun 18, 2020 at 16:27
  • Without using In Built Wifi Module.
    – VinRocka
    Commented Jun 19, 2020 at 6:07
  • so you say it is better to use an external esp8266 module then the on-board esp32? what is the difference?
    – Juraj
    Commented Jun 19, 2020 at 7:53
  • Actually ESP 32 is a improvement o ESP 8266, but I was able to use ESP 8266 with Arduino easily than ESP32 and ESP 8266 ha lot of community threads.
    – VinRocka
    Commented Jun 19, 2020 at 11:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.