           "... ");
     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++) {

#if MQTT_ENABLE
// MQTT subscribing to topic
void subscribing(const String topic_name) {
  // subscription to topic for receiving data
  if (mqtt_client.subscribe(topic_name.c_str()))
    debug("Subscription OK to " + topic_name);
  else
    debug("Subscription FAILED to " + topic_name);

// 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[] = {
