Connection issues with MKR1000

Hi All,
I’ve had a lot of fun with my blynk project so far, but I’m having a lot of connectivity issues lately. Basically everything works fine for a short while but then the board loses the connection to the network. You’ll see in the code that I included a line to reset the board every once in a while in order to fix this but alas.
I’m using an Arduino MKR1000, connected to my local home network. I’ve tried to place the board next to the wifi router to determine whether it has trouble to connecting to the network but that didn’t solve it.
Does this sound familiar to someone and is there a fix? Below the code I’ve been working with.
I’ve built the code from bits I’ve found online, I’m not a pro so be gentle :wink:

Thanks for the help!

#define BLYNK_PRINT SerialUSB
#include <SPI.h>
#include <WiFi101.h>
#include <BlynkSimpleWiFiShield101.h>
char auth[] = "#####";
char ssid[] = "#####";
char pass[] = "#####";
float x1 = 270; //min value sensor empty
float x2 = 340; //max value sensor full tank 1 
float x3 = 450; //max value sensor full tank 2
float x4 = 350; //max value sensor full tank 3

const int numReadings = 30;

float readings1[numReadings];      // the readings from the analog input
float readings2[numReadings];      // the readings from the analog input
float readings3[numReadings];      // the readings from the analog input
int readIndex = 0;              // the index of the current reading
float total1 = 0;                  // the running total       
float total2 = 0;                  // the running total
float total3 = 0;                  // the running total
float average1 = 0;                // the average
float average2 = 0;                // the average
float average3 = 0;                // the average
int alarm = 0;
int sproeien = 1;
int sproeiervalue=0;

BlynkTimer timer;

BLYNK_WRITE(V3)
{
  sproeien = param.asInt();
}
void myTimerEvent()
{
 // subtract the last reading:
  total1 = total1 - readings1[readIndex];
  total2 = total2 - readings2[readIndex];
  total3 = total3 - readings3[readIndex];
  // read from the sensor:
  readings1[readIndex] = analogRead(A1);
   Serial.print(readings1[readIndex]);
   Serial.print(" ");
  readings2[readIndex] = analogRead(A2);
  Serial.print(readings2[readIndex]);
    Serial.print(" ");
  readings3[readIndex] = analogRead(A3);
  Serial.println(readings3[readIndex]);

  
  // add the reading to the total:
  total1 = total1 + readings1[readIndex];
  total2 = total2 + readings2[readIndex];
  total3 = total3 + readings3[readIndex];
  // advance to the next position in the array:
  readIndex = readIndex + 1;

  // if we're at the end of the array...
  if (readIndex >= numReadings) {
    // ...wrap around to the beginning:
    readIndex = 0;
  }

  // calculate the average:
  average1 = total1 / numReadings;
  average2 = total2 / numReadings;
  average3 = total3 / numReadings;
  Serial.print(average1);

  
  float sensorData1 = average1; //groundwater
  float perc1 = (100/(x2-x1))*(sensorData1 - x1);
  
  float sensorData2 = average2; //buffertank
  float perc2 = (100/(x4-x1))*(sensorData2 - x1);

  float sensorData3 = average3; //rainwater
  float perc3 = (100/(x3-x1))*(sensorData3 - x1);

  

  if (perc2 < 50 && perc1 > 20){
   digitalWrite(1, HIGH);    
 }
  else if (digitalRead(1) == HIGH && perc2 < 100 && perc1 > 10){
    digitalWrite(1, HIGH);
  }
  else {
    digitalWrite(1, LOW);
  }

if (alarm==1||sproeien==1){
  digitalWrite(2, HIGH); 
  sproeiervalue=1;
}
else{
  digitalWrite(2,LOW);
  sproeiervalue=0;
}
 
  Blynk.virtualWrite(V1, digitalRead(1));
  Blynk.virtualWrite(V2, digitalRead(2));
  Blynk.virtualWrite(V5, String(perc1, 0)); //waterput
  Blynk.virtualWrite(V6, String(perc2, 0)); //buffertank
  Blynk.virtualWrite(V7, String(perc3, 0)); //regenwater
  Blynk.virtualWrite(V8, sproeiervalue);
  Blynk.virtualWrite(V9,alarm);
  
    while (WiFi.status() != WL_CONNECTED) {
    WiFi.end();
    Serial.print("Attempting to connect to Network named: ");
    Serial.println(ssid);                   
    WiFi.begin(ssid, pass);

    delay(2000);
}}


void setup() {
  SerialUSB.begin(9600);
  Blynk.begin(auth, ssid, pass);
  pinMode(1, OUTPUT);
  pinMode(2, OUTPUT);
  timer.setInterval(1000L, myTimerEvent);
    for (int thisReading = 0; thisReading < numReadings; thisReading++) {
    readings1[thisReading] = 0;
    readings2[thisReading] = 0;
  }
}
void(* resetFunc) (void) = 0;
void loop() {
   Blynk.run();
  timer.run(); 

if ( millis()  >= 1800000) resetFunc(); //call reset every 30 mins


}
  

I run a test of my project with Blynk on MKR1000 these days and it is stable.
But I use a WiFi101 library with my fixes.
https://github.com/jandrassy/WiFi101/tree/all_fixes