   while (!client.connected()) {
     Serial.print("Attempting MQTT connection...");
     // Attempt to connect
-    if (client.connect(mqtt_clientId, mqtt_username, mqtt_password)) {
+    if (client.connect(mqtt_clientId, mqtt_username, mqtt_password, availabilityTopic, 0, true, lwtMessage)) {
       Serial.println("Connected!");
+
+      // Publish the birth message on connect/reconnect
+      publish_birth_message();
 
       // Subscribe to the action topics to listen for action messages
       Serial.print("Subscribing to ");

    Serial.print("Publishing on-demand status update for ");
    Serial.print(door2_alias);
    Serial.println("!");
    publish_door2_status();
  }  
  else { Serial.println("Unrecognized action payload... taking no action!");

  }
}

// Function that publishes birthMessage

void publish_birth_message() {
  // Publish the birthMessage
  Serial.print("Publishing birth message ");
  Serial.print(birthMessage);
  Serial.print(" to ");
  Serial.print(availabilityTopic);
  Serial.println("...");
  client.publish(availabilityTopic, birthMessage, true);
}

// Function that toggles the relevant relay-connected output pin

void toggleRelay(int pin) {
