   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);

//
long startMills;

void callback(const MQTT::Publish& pub) {
  
  Serial.print(" => ");
  Serial.print(pub.topic());
  Serial.print(" => ");
  Serial.print(pub.payload_string());
  
  String subPayload = pub.payload_string() ;

  if ( subPayload == "{\"LIGHT\":1}") 
  {
       relaystatus = 1 ;
    
  } else if ( subPayload == "{\"LIGHT\":0}") 
  {
       relaystatus = 0 ;
  }
  changelight() ;
  Serial.println("");
  Serial.print(" => relaystatus => ");
  Serial.println(relaystatus);
}

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


void setup() 
{
  Serial.begin(38400);
  Serial.println("DHTxx test!");
  delay(20);
  
  startMills = millis();

  pinMode(pir,INPUT);
  pinMode(RELAYPIN, OUTPUT);
  pinMode(TOPBUTTONPIN, INPUT_PULLUP);

  digitalWrite(RELAYPIN, relaystatus);

  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) {

#include <OneWire.h>
#include "DHT.h"
#include <PubSubClient.h>
#include <ESP8266WiFi.h>
#include <DallasTemperature.h>
#include <WiFiUdp.h>
#include <Time.h>

// wifi
#ifdef __IS_MY_HOME
#include "/usr/local/src/ap_setting.h"
#else
#include "ap_setting.h"
#endif

#define DEBUG_PRINT 1

// pin
#define pir 13
#define DHTPIN 14     // what pin we're connected to
#define RELAYPIN 4
#define TOPBUTTONPIN 5

// DHT22
#define DHTTYPE DHT22   // DHT 22  (AM2302)
