   XBee.begin(9600);
   Serial.begin(9600);
   dht.begin();
+  pinMode(WINDOWPIN, INPUT);
+  pinMode(ACPIN, INPUT);
   pinMode(LED_LIGHT, OUTPUT);
   pinMode(DOOR_LOCK, OUTPUT);
   digitalWrite(DOOR_LOCK, HIGH);

#include <SPI.h>
#include <MFRC522.h>

#define DHTPIN            6
#define DHTTYPE           DHT11
#define LED_LIGHT         8
#define DOOR_LOCK         7

DHT dht(DHTPIN, DHTTYPE);
SoftwareSerial XBee(2, 3); // RX, TX
uint8_t successRead;    // Variable integer to keep if we have Successful Read from Reader
byte readCard[4];   // Stores scanned ID read from RFID Module
int lastId = 0;

// Create MFRC522 instance.
constexpr uint8_t RST_PIN = 9;     // Configurable, see typical pin layout above


void loop() {
  if (XBee.available()) {
    String incomingMsg = XBee.readString();
    Serial.println(incomingMsg);
    if (incomingMsg == "LON\r") {
      digitalWrite(LED_LIGHT, HIGH);
      XBee.print("{\"a\":\"LON\"}\r");
    } else if (incomingMsg == "LOFF\r") {
      digitalWrite(LED_LIGHT, LOW);
      XBee.print("{\"a\":\"LOFF\"}\r");
    }else if (incomingMsg == "DOPEN\r") {
      digitalWrite(DOOR_LOCK, LOW);
      XBee.print("{\"a\":\"DOPEN\"}\r");
    } else if (incomingMsg == "DCLOSE\r") {
      digitalWrite(DOOR_LOCK, HIGH);
      XBee.print("{\"a\":\"DCLOSE\"}\r");
    } else if (incomingMsg == "D\r") {
      syncNode();
    }
  }
  if (getID()) {
    if (!lastId) {
      lastId = 1;
      digitalWrite(DOOR_LOCK, LOW);
      isCardIn = true;
    }    
  } else if (lastId) {
    lastId = 0;
    digitalWrite(DOOR_LOCK, HIGH);
    isCardIn = true;    
  }
}

void syncNode() {
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  int window = digitalRead(WINDOWPIN);
  int ac = digitalRead(ACPIN);
  char syncmsg[100];
  sprintf (syncmsg, "{\"a\":\"DATA\",\"p\":{\"t\":%d,\"h\":%d,\"a\":%d,\"w\":%d,\"d\":%d}}\r", (int) t, (int) h, ac, window, (isCardIn ? 1 : 0));
  XBee.print(syncmsg);
  Serial.println(syncmsg);
}

uint8_t getID() {
