Hi, I have the same problem with the WiFi connection. Sometimes the connection runs for over 10 hours and then suddenly stops.
I was using a WiFi booster via powerline (next to the MKR1010, and sometimes after the wifi connection stopped, I reset the WIFI booster and the connection came back on. (Fortunately my sketch loop keeps running).
Thereafter I connected directly to the WiFiRouter (around -77dBm.
Same problem. Connection is sometimes up for over more then 10 hours and then stops.
I have two counters build in. 1 counts the number of loops and 1 counts the number of resets.
I have tried the Power Down function of the NiNamodule, but this seems not to work, No good effects were noticed.
So now I use the De_INit of the NiNa module. Unfortunately also no stable results.
Mostly it takes 1 loop to have connection with the WiFiRouter.
WiFi FW is 1.3.0 .
If anyone has a solution, it is most welcome.
See my sketch below. (Not all of the sketch is shown)
Note: Sketch does not wait till connection with router is established, because my loop should always run, even if wifi connection is not correct after powerfailure or wificonnection loss. Normally these two conditions are met.
Leds are used to indicate status of the connection process and this normally gives a good and clear indication.
int LOOPS;
int RESETS;
void setup()
{
Serial.begin(9600);
delay (5000);
LOOPS = 0;
RESETS = 0;
}
void loop()
{
Serial.println ("");
Serial.println ("START LOOP =========================================================== TEST 16 v41 ");
Serial.println("");
LOOPS = (LOOPS + 1);
Serial.print("Number of LOOPS is : ");
Serial.println(LOOPS);
Serial.print("Number of RESETS is : ");
Serial.println(RESETS);
Serial.println("");
ConnectWiFiRouter();
ConnectToNTP(); // details in set-up and declarations not shown here in this example
ConnecttoAmazon();
GordijnenOpen(); // following voids are for my project and not further shown
ConnecttoAmazon();
GordijnenDicht();
ConnecttoAmazon();
DelayLoop();
}
void ConnectWiFiRouter()
{
WiFiDrv::analogWrite(red, 1);
Serial.println("CONNECT TO WiFi ROUTER, send SSID and PASSWORD");
WiFi.begin(SSID, PASSWORD);
status = WiFi.begin(SSID, PASSWORD);
delay(100);
Serial.print("1. WiFi Status must be 3 and is : ");
Serial.println(status);
if (status != (3))
{
Serial.println ("No connection with WiFiRouter");
Serial.println ("");
Serial.println ("Disconnect from WiFiRouter via : wifiDriverDeinit ; ");
WiFiDrv::wifiDriverDeinit(); // De-Init
WiFiDrv::analogWrite(red, 16); // LED was set to 0 by De-Init
goto Z;
}
Serial.println ("Connected to WiFiRouter. No De-Init DONE ");
Serial.println("");
goto STATUSOK;
Z:
Serial.print("2. wifiDriverDeInit DONE. New attempt to connect WiFi : Status must be 3 and is : ");
RESETS = (RESETS + 1);
WiFi.begin(SSID, PASSWORD);
status = WiFi.begin(SSID, PASSWORD);
Serial.println(status);
if (status != (3))
{
Serial.println("No good result from De-Init");
Serial.println("");
goto END;
}
STATUSOK:
Serial.println("STATUS OK");
Serial.println("");
WiFiDrv::analogWrite(red, 0);
WiFiDrv::analogWrite(green, 32); // 1 green flash of 2 seconds
delay (2000);
WiFiDrv::analogWrite(green, 0);
END:
PrintWifiStatus();
}
void ConnectToNTP()
{
timeClient.begin();
timeClient.setTimeOffset(3600);
timeClient.update();
Serial.println ("");
epochTime = timeClient.getEpochTime(); // Unsigned Long This time is the number of seconds that have passed since 1 January 1970 00:00 UTC
Serial.print("Epoch Time: "); // 51x365x24x60x60 = 1,608.336.000
Serial.println(epochTime);
currentHour = timeClient.getHours();
Serial.print("Hour: ");
Serial.println(currentHour);
currentMinute = timeClient.getMinutes();
Serial.print("Minutes: ");
Serial.println(currentMinute);
Serial.println ("");
}
void ConnecttoAmazon()
{
Serial.println ("CONNECT TO AMAZON");
if (status != (3))
{
Serial.println ("No Connection with WiFiRouter. Connection to Amazon Server SKIPPED");
goto Z;
}
(client.connect(server, 443));
Serial.print ("Amazon reponse must be 1 and is : ");
Serial.println (client);
if (client != (1))
{
Serial.println ("NOT Connected to Amazon Server");
Serial.println ("");
goto Z;
}
Serial.println ("Amazon Server Connected : 2 green flashes of 0,5 sec");
WiFiDrv::analogWrite(green, 8);
delay (300);
WiFiDrv::analogWrite(green, 0);
delay (100);
WiFiDrv::analogWrite(green, 8);
delay (300);
WiFiDrv::analogWrite(green, 0);
delay (300);
Z:
delay (0);
}