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!