 
 #define NB_PROXIM_SAMPLES 20
 #define NB_ANOMALY_COUNTS 15
+
+#define MAX_CLIENT_RETRIES 10
 
 uint16_t proxim_nominal = 2000;
 uint16_t proxim_anomaly = 100;

  }
}

void connectClient() {
  while (!mqttClient.connected()) {
    Serial.print("Attempting MQTT connection...");
    if (mqttClient.connect("MistyDoor")) {
      Serial.println("connected");
    } else {
      Serial.print("failed, rc=");
      Serial.print(mqttClient.state());

  else {
    strcpy(payload, "closed");
  }
  if ( connectClient() ) {
    mqttClient.publish("/catdoor/state", payload);
  }
  else {
