 uint8_t buttonState = LOW;
 uint8_t alertLevel  = 30;
 uint8_t humLevel = 80;
+uint8_t wifiCheckCntr = 0;
 boolean hatchOpen = false;
 
 //state handling

  delay(10);
  tempLimitPotValue = analogRead(tempPotPin); // Read the pot value
  tempLimitPotValue = map(tempLimitPotValue, 0, 1023, 20, 40); // Map the values from 20 to 40 degrees
  Serial.print("tp:");
  Serial.println(tempLimitPotValue);

  delay(10);
  humLimitPotValue = analogRead(humPotPin); // Read the pot value
  delay(10);
  humLimitPotValue = analogRead(humPotPin); // Read the pot value
  humLimitPotValue = map(humLimitPotValue, 0, 1023, 20, 100); // Map the values from 20 to 100%
  Serial.print("hp:");
  Serial.println(humLimitPotValue);

  buttonState = digitalRead(buttonPin); // Check for button press  
}

    }
  }
  clearBuffer();
  if (!(++wifiCheckCntr)){
    espSerial.println("AT+GMR\r");
    if(espSerial.find("OK")){
      Serial.println("Wifi OK");
    }else{
      Serial.println("Wifi NOK, restart WIfi");
      setupWifi();
    }
  }
  delay(500); 
}

