 }
 
 boolean reconnect() {
-  if (client.connect((char*) clientName.c_str(), willTopic, 0, true, willMessage)) {
-    client.publish(willTopic, "1", true);
-    client.publish(hellotopic, "hello again 1 from ESP8266 s07");
-    if (DEBUG_PRINT) {
-      Serial.println("---------------> connected");
-    }
-  } else {
-    if (DEBUG_PRINT) {
-      Serial.print("----------------> failed, rc=");
-      Serial.println(client.state());
+  if (!client.connected()) {
+    if (client.connect((char*) clientName.c_str(), willTopic, 0, true, willMessage)) {
+      client.publish(willTopic, "1", true);
+      client.publish(hellotopic, "hello again 1 from ESP8266 s07");
+      if (DEBUG_PRINT) {
+        Serial.println("---------------> connected");
+      }
+    } else {
+      if (DEBUG_PRINT) {
+        Serial.print("----------------> failed, rc=");
+        Serial.println(client.state());
+      }
     }
   }
   //timemillis = millis();

          lastReconnectAttempt = 0;
        }
      }
    } /* else {
      client.loop();
    } */
  } else {
    wifi_connect();
  }

  attachInterrupt(4, IRCHECKING_START, RISING);
  attachInterrupt(5, DOORCHECKING, CHANGE);

  emon1.current(A0, 75);
  oldirStatus = LOW ;

}
