   payload += ",\"PIRSTATUS\":";
   payload += pirValue;
   payload += "}";
-    
+
 
   if ( pirSent == HIGH && pirValue == HIGH )
-  {    
+  {
     sendmqttMsg(topic, payload);
     pirSent = LOW ;
     startMills = millis();
   }
-    
+
   if (((millis() - startMills) > REPORT_INTERVAL ) && ( getdalastempstatus == 0))
   {
     getdalastemp();
     getdalastempstatus = 1;
   }
-  
+
   if (((millis() - startMills) > REPORT_INTERVAL ) && ( getdht22tempstatus == 0))
   {
     getdht22temp();
     getdht22tempstatus = 1;
   }
-    
+
   if ((millis() - startMills) > REPORT_INTERVAL )
   {
     sendmqttMsg(topic, payload);

    Serial.println("Failed to read from sensor!");
    return;
  }

}

void loop() 
{

  if (WiFi.status() == WL_CONNECTED) {
    if (!client.connected()) {
      if  (
        client.connect(MQTT::Connect((char*) clientName.c_str()).set_clean_session().set_keepalive(120))) {
        client.subscribe(subtopic);
        client.publish(hellotopic, "hello from ESP8266 s02");
        client.set_callback(callback);
      }
    }

    if (client.connected()) {
      client.loop();
    } else {
      ESP.restart();
    }
  } else {
      Serial.println("Could not connect to WIFI");
      ESP.restart();    
  }


  changelight();
  runTimerDoLightOff();
  
  pirValue = digitalRead(pir);
  
  payload = "{\"Humidity\":";
  payload += h;
  payload += ",\"Temperature\":";

//
long startMills;

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

long lastReconnectAttempt = 0;

void wifi_connect() {
  // WIFI
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);

  int Attempt = 0;
  while (WiFi.status() != WL_CONNECTED) {
