I found your script and used it for my own project. So I would like to share the solution with the comunnity.
You have a multiple client.connect into your code.
the line:
if (client.connect(clientId.c_str())) {
has to change to something like:
(client.connect("arduinoClient", willTopic, willQoS, willRetain, willMessage)) {
and remove the other line's from the void setup
client.connect("David_ESP_3", willTopic, willQoS, willRetain, willMessage);
client.publish("tele/esp/LWT/3", "Online");