           "... ");
     if (kMqttUsername && kMqttPassword)
       connected = mqtt_client.connect(mqtt_clientid.c_str(), kMqttUsername,
-                                      kMqttPassword);
+                                      kMqttPassword, MQTTstatus, QOS, true,
+                                      LWT_OFFLINE);
     else
-      connected = mqtt_client.connect(mqtt_clientid.c_str());
+      connected = mqtt_client.connect(mqtt_clientid.c_str(), MQTTstatus, QOS,
+                                      true, LWT_OFFLINE);
     if (connected) {
     // Once connected, publish an announcement...
-      mqtt_client.publish(MQTTack, "Connected");
-      debug("connected.");
+      mqtt_client.publish(MQTTlog, "(Re)Connected");
+      debug("reconnected.");
+
+      // Update Last Will & Testament to say we are back online.
+      mqtt_client.publish(MQTTstatus, LWT_ONLINE, true);
+
       // Subscribing to topic(s)
       subscribing(MQTTcommand);
       for (uint8_t i = 0; i < kSendTableSize; i++) {

// NOTE: Make sure you set your Serial Monitor to the same speed.
#define BAUD_RATE 115200  // Serial port Baud rate.

// ADVANCED USAGE ONLY

// Change if you need multiple independent send gpio/topics.
const uint8_t gpioTable[] = {

 * This server will send (back) what ever IR message it just transmitted to
 * the MQTT topic 'ir_server/sent' to confirm it has been performed. This works
 * for messages requested via MQTT or via HTTP.
 *
 *   Unix command line usage example:
 *     # Listen to MQTT acknowledgements.
 *     $ mosquitto_sub -h 10.0.0.4 -t ir_server/sent
