 
   unsigned long time = getTime();
 
+  int buttonStatus = digitalRead(BUTTONPIN);
+  if (buttonStatus != lastButtonStatus) {
+    printTime(time);
+    debug("Button status changed to: ")
+    debugln(buttonStatus);
+
+    sendMeasurement({time, 0, 0, buttonStatus==HIGH, buttonStatus==LOW});
+
+    lastButtonStatus = buttonStatus;
+  }
+  
   // Do a new temperature and humidity measurement for the first time or if interval since last one reached MEASUREMENT_INTERVAL value
   if (time - lastMeasurementTime >= MEASUREMENT_INTERVAL) {
     lastMeasurementTime = time;

    // Make a HTTP request:

    char req[256];
    sprintf(req, "GET /add?apiKey=%s&d=%lu&t=%d&h=%d HTTP/1.1", API_KEY, m.time, m.temperature, m.humidity);
    debugln(req);
    client.println(req);
    client.println("Host: myStatServer.net");

#define DHTTYPE DHT11   // DHT 11
//#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
//#define DHTTYPE DHT21   // DHT 21 (AM2301)


// ************** Doors open/closed button configuration

#define BUTTONPIN                 3


// ************** Ethernet configuration - global
