Change wifi reconnection attempt interval?

I'm running a Uno R4 Wifi connected to the IoT Cloud. In addition to reporting measured parameters to the cloud, it also does some autonomous tasks that do not require a cloud connection.

The problem that I have is that if the wifi connection is lost, the device goes into a reconnection attempt loop every 500 ms (almost continuously) and while doing so, it neglects its automous functions, or does so very very slowly.

My question is whether there a way to modify how often it attempts to reconnect to wifi? If it attempted to reconnect once every minute or several minutes instead of every 500 ms, it would still be able to perform its measurements and take required autonomous actions between reconnect attempts.

It's using WiFiConnectionHandler with ArduinoIoTPreferredConnection.

Thanks in advance for any suggestions.

Mark

Looks like there are no public way to modify the interval, and it's const. But you can modify the source of the library directly. If you ever update the library, you'll need to reapply the change. The libraries directory is in your sketchbook directory. The file is libraries/Arduino_ConnectionHandler/src/ConnectionHandlerDefinitions.h

static unsigned int const CHECK_INTERVAL_TABLE[] =
{
  /* INIT          */ 100,
#if defined(BOARD_HAS_NOTECARD) || defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
  /* CONNECTING    */ 4000,
#else
  /* CONNECTING    */ 500,  // <-- this one
#endif
  /* CONNECTED     */ 10000,
  /* DISCONNECTING */ 100,
  /* DISCONNECTED  */ 1000,
  /* CLOSED        */ 1000,
  /* ERROR         */ 1000
};

If that's not satisfactory, there's also a third argument to constructor that defaults to true

WiFiConnectionHandler(char const * ssid, char const * pass,
    bool const keep_alive = true);

If you pass false, the WFCH will start in its INIT state and (try to) connect; then if it disconnects, it won't try to re-INIT and will instead go to its CLOSED state. In theory, you could hook some events and manage this manually. However, calling the connect function always then set the protected _keep_alive to true, so that would only work once. Maybe you could subclass WFCH and not do that, or set it right back to false.

Thank you Ken! I think editing the library would be the better solution in my case, so I'll give it a try.