  * Initialization on startup.
  */
 void setup() {
+  debugger.begin(19200);
   if (Debugging) {
-    debugger.begin(19200);
     debugger.println("Initialising...");
   }
   // Init LCD
   pinMode(lcd_bl, OUTPUT);
   digitalWrite(lcd_bl, HIGH);
+  RTC.begin();
   lcd.begin(16,2);
   lcdWrite("Initializing...");
 
   espPort.begin(19200);
-  lcdWrite("Initializing...", "WIFI Connecting");
+  lcdWrite("Initializing...", "WIFI Config");
   esp.enable();
   delay(500);
   esp.reset();
   delay(500);
   while(!esp.ready());
-
+  
   if (Debugging) {
     debugger.println("ARDUINO: Setup MQTT client");
   }
-  lcdWrite("Initializing...", "MQTT Connecting");
-  if (!mqtt.begin("coop_duino", "", "", 20, 1)) { // client_id, username, password, keepalive time, cleansession boolean
+  lcdWrite("Initializing...", "MQTT Config");
+  if (!mqtt.begin(mClientID, mUsername, mPassword, 20, 1)) { // client_id, username, password, keepalive time, cleansession boolean
     if (Debugging) {
       debugger.println("ARDUINO: Failed to setup MQTT");
     }
     lcdWrite("MQTT Connect", "Failure");
     while(1);
   }
+  mqtt.lwt("/lwt", "Offline");
 
   mqtt.connectedCb.attach(&mqttConnected);
   mqtt.disconnectedCb.attach(&mqttDisconnected);

    debugger.println(data);
  }

  if (topic == "coop/remotetrigger") {
    // If door movement is triggered, toggle door state to
    // opening or closing based on current state.
    // If door is currently moving, the trigger is ignored.
    if (data == "door") {
      if (doorState == "open") {
        doorState = "closing";
        lastReading = millis() + remoteOverride;
      }
      else if (doorState == "closed") {
        doorState = "opening";
        lastReading = millis() + remoteOverride;
      }
    }

    // Toggle interior light
    if (data == "light") {
      toggleLamp();
      lastReading = millis() + remoteOverride;
    }

    // Toggle water heater
    if (data == "water heater") {
      toggleHeater();
      lastReading = millis() + remoteOverride;
    }

    // Toggle fan
    if (data == "fan") {
      toggleFan();
      lastReading = millis() + remoteOverride;
    }
  }

  // Sync RTC to time beacon once/day
  if (topic == "time/beacon") {
    if ((unsigned long)(millis() - millisPerDay) >= lastRTCSync) {
      rtc.adjust(atoi(data.c_str()));
      lastRTCSync = millis();
    }
  }
}

          debugger.println("Opening door.");
        }
        doorState = "opening";
        if (wifiConnected) {
          mqtt.publish(pStatus, "door|opening", 2, 0);
        }
      }
    }
    // Otherwise, close door when light level falls to 15% or below.
