   }
   //timemillis = millis();
   return client.connected();
+}
+
+void callback(char* intopic, byte* inpayload, unsigned int length)
+{
+  String receivedtopic = intopic;
+  String receivedpayload ;
+
+  for (int i = 0; i < length; i++) {
+    receivedpayload += (char)inpayload[i];
+  }
+
+  if (EVENT_PRINT) {
+    Serial.print(intopic);
+    Serial.print(" => ");
+    Serial.println(receivedpayload);
+  }
+
+  if ( receivedpayload == "{\"DOOR\":\"CHECKING\"}") {
+
+    String check_doorpayload = "{\"DOOR\":";
+    if ( doorStatus == 0 ) {
+      check_doorpayload += "\"CHECK_CLOSED\"";
+    }
+    else {
+      check_doorpayload += "\"CHECK_OPEN\"";
+    }
+    check_doorpayload += "}";
+    sendmqttMsg(doortopic, check_doorpayload);
+  }
+
 }
 
 void setup() {

char* willTopic = "clients/power";
char* willMessage = "0";

IPAddress server(192, 168, 10, 10);

// pin : using line tracker

int average = 0;

WiFiClient wifiClient;
PubSubClient client(server, 1883, callback, wifiClient);

long lastReconnectAttempt = 0;

