 
 void loop() {
   if (XBee.available()) {
-    String msg = XBee.readString();
-    Serial.println(msg);
-    if (msg == "LON\r") {
+    String incomingMsg = XBee.readString();
+    Serial.println(incomingMsg);
+    if (incomingMsg == "LON\r") {
       digitalWrite(LED_LIGHT, HIGH);
-      XBee.print("{\"a\":\"LON\",\"p\":\"OK\"}\r");
-    } else if (msg == "LOFF\r") {
+      XBee.print("{\"a\":\"LON\"}\r");
+    } else if (incomingMsg == "LOFF\r") {
       digitalWrite(LED_LIGHT, LOW);
-      XBee.print("{\"a\":\"LOFF\",\"p\":\"OK\"}\r");
-    }else if (msg == "DOPEN\r") {
+      XBee.print("{\"a\":\"LOFF\"}\r");
+    }else if (incomingMsg == "DOPEN\r") {
       digitalWrite(DOOR_LOCK, LOW);
-      XBee.print("{\"a\":\"DOPEN\",\"p\":\"OK\"}\r");
-    } else if (msg == "DCLOSE\r") {
+      XBee.print("{\"a\":\"DOPEN\"}\r");
+    } else if (incomingMsg == "DCLOSE\r") {
       digitalWrite(DOOR_LOCK, HIGH);
-      XBee.print("{\"a\":\"DCLOSE\",\"p\":\"OK\"}\r");
-    } else if (msg == "D\r") {
+      XBee.print("{\"a\":\"DCLOSE\"}\r");
+    } else if (incomingMsg == "D\r") {
       syncNode();
     }
   }
   if (getID()) {
     if (!lastId) {
       lastId = 1;
-      char msg[100];
-      sprintf (msg, "{\"a\":\"CI\",\"p\":\"%02x%02x%02x%02x\"}\r", readCard[0], readCard[1], readCard[2], readCard[3]);
-      XBee.print(msg);
-      Serial.println(msg);
+      digitalWrite(DOOR_LOCK, LOW);
+      isCardIn = true;
     }    
   } else if (lastId) {
     lastId = 0;
-    XBee.print("{\"a\":\"CO\"}\r");
-    Serial.println("CARDOUT");    
+    digitalWrite(DOOR_LOCK, HIGH);
+    isCardIn = true;    
   }
 }
 
 void syncNode() {
   float h = dht.readHumidity();
   float t = dht.readTemperature();
-  char msg[100];
-  sprintf (msg, "{\"a\":\"TEMP\",\"p\":{\"t\":%d,\"h\":%d}}\r", (int) t, (int) h);
-  XBee.print(msg);
-  Serial.println(msg);
+  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() {

#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

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