Uno Wifi rev2 - after long time it disconnects Given an Arduino Uno Wifi Rev2 with this small U-blox NINA wifi module.

All work great however after a long time (I can't be more exact but we talk here about weeks if not months), it suddenly disconnects.

This board is unattended, and the only way to recover is to reset the Arduino.

Here is my code:

WiFiServer server(PORT);

void setup() {
  connectToWifi();
  server.begin();
}

void connectToWifi() {
  // attempt to connect to Wifi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);
    if (status == WL_CONNECTED) break;

    // wait 10 seconds for connection:
    delay(10000);
  }
}

void loop() {
  // check WiFi status
  if (WL_CONNECTED != WiFi.status()) connectToWifi();

  WiFiClient client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();

        ... (other wifi-unrelated code)

        // close the connection:
        client.stop();
      }
    }
  } 
}


When it disconnects from wifi, the router's dhcp manager console shows it with "waiting" status.

Note: I'm the only client, and only one character is sent to the Arduino at once, then the socket is closed. It is very unlikely, that a client hangs, and the board is stuck in the while loop.

Is this a known problem, or I have to dig myself more into this?

Thank you!
As you have not given the details there are some things to check 


is your Nina-Firmware > 1.2.4
If not update to the latest 1.3.0 via the WiFi101-FirmwareUpdater-Plugin 0.10.10 is included in the ArduinoIDE 1.8.12 or greater
Disconnect before you reconnect (in case of router drop-outs) and
Close any connection before sending/receiving. This will free the socket on the Nina module. Stop the client after doing the stuff needed with   client.stop();
If there is any server connection code in setup this should be run in a reconnect routine (as you did not include setup) just as a hint 
Make sure that after a certain period the while (status != WL_CONNECTED) and while (client.connected()) are broken and error testing takes place e.g. if (status==WL_DISCONNECTED || status==WL_CONNECTION_LOST){.. do something to change that ..}
If all fails implement a routine that checks the signal and restarts the sketch if the router has dropped out (for whatever reason).


Disconnect code:

void connectToWifi() {
    // This new line is required to disconnect the previous connection otherwise
    // it will try to use the old connection and never reconnect if the connection fails
    status = WiFi.disconnect();

    // attempt to connect to Wifi network:
    while (status != WL_CONNECTED) {
    .... REST of your code ...
    }
}


Hint (as you did not show setup) if you have something like

client.connect(server, 80);


move it to the reconnection routine in the form of 

if (client.connect(server, 80)) {
    Serial.println("connecting...");
.... REST of reconnect ...
} 


Restart code if wifi signal is lost

void(* resetFunc) (void) = 0; // Declare reset function at address 0

void loop() {
  if (WiFi.RSSI() == 0) // Checks if Wifi signal lost.
  { resetFunc(); // Calls Reset
  }
// Rest of code goes here.
}


This should altogether ensure a long and stable running client