           lastReconnectAttempt = 0;
         }
       }
+    } else {
+
+      if (device_data.button == 1) {
+        if (( subMsgReceived == HIGH ) && ( relayReady == HIGH )) {
+          subMills = (millis() - startMills) - wifiMills ;
+          sendlightcmd();
+        }
+
+        if (( subMsgReceived == HIGH ) && ( relayReady == LOW )) {
+          subMills = (millis() - startMills) - wifiMills ;
+          goingToSleepWithFail();
+        }
+      }
+
+      if (device_data.button == 2 || device_data.button == 3) {
+        sendaccommand();
+      }
+
+      if (device_data.button == 4) {
+        goingToSleepWithFail();
+      }
+
+      if ( topicMsgSent == HIGH ) {
+        goingToSleep();
+      }
+
+      if ((millis() - startMills) > 15000) {
+        goingToSleepWithFail();
+      }
+      
+      client.loop();
     }
-  } else {
-    wifi_connect();
-  }
-
-  if (device_data.button == 1) {
-    if (( subMsgReceived == HIGH ) && ( relayReady == HIGH )) {
-      subMills = (millis() - startMills) - wifiMills ;
-      sendlightcmd();
-    }
-
-    if (( subMsgReceived == HIGH ) && ( relayReady == LOW )) {
-      subMills = (millis() - startMills) - wifiMills ;
-      goingToSleepWithFail();
-    }
-  }
-
-  if (device_data.button == 2 || device_data.button == 3) {
-    sendaccommand();
-  }
-
-  if (device_data.button == 4) {
-    goingToSleepWithFail();
-  }
-
-  if ( topicMsgSent == HIGH ) {
-    goingToSleep();
-  }
-
-  if ((millis() - startMills) > 15000) {
-    goingToSleepWithFail();
-  }
-
-  client.loop();
+  }
 }
 
 void sendaccommand() {


ADC_MODE(ADC_VCC);

#define IPSET_STATIC { 192, 168, 10, 12 }
#define IPSET_GATEWAY { 192, 168, 10, 1 }
#define IPSET_SUBNET { 255, 255, 255, 0 }
#define IPSET_DNS { 192, 168, 10, 10 }

#define I2C_SLAVE_ADDR  8
#define I2C_MATRIX_ADDR 0x70

#define HT16K33_SS            B00100000 // System setup register
#define HT16K33_SS_STANDBY    B00000000 // System setup - oscillator in standby mode
#define HT16K33_SS_NORMAL     B00000001 // System setup - oscillator in normal mode

volatile struct {
  uint32_t hash;

  delay(300);

  sendI2cMsg();
  //delay(200);

  ESP.deepSleep(0);
  delay(50);
