MQTT and WiFi - problem with last will

Hi, I am working on a project with MQTT and using a WiFi shield to connect Arduino to the broker.
I have been successful in using Knolleary's pubsubclient Arduino Client for MQTT · knolleary having applied the fix that is suggested here Arduino Mqtt Client – DutchTechy.

I am now trying to set a last will message when connecting to the broker, but the connection fails.

Since Knolleary supports last will and nobody raised issues about this before, I believe the root cause is the same that requires the above mentioned fix and that is decribed here mqtt - Mosquitto socket read error Arduino client - Stack Overflow, namely an alledged error in the WiFi library.

Since I don't have the technical knowledge to modify the WiFi library itself or to find another workaround, I'm asking the community if someone else has come across this issue and solved it.

It all boils down to a single line of code:

client.connect(mqttClientId, (char*)mqttUser, (char*)mqttPass, lastWillTopic, 0, true, "Client lost connection");

Many thanks in advance!

Last will does not seem to be working on PubSubClient 2.4. No errors whatsoever, just nothing is submitted after connection timeout.

Using this line of code:

if (mqttclient.connect(_HOSTNAME.c_str(), _MQTT_USERNAME.c_str(), _MQTT_KEY.c_str()), String(_HOSTNAME + "/status/online").c_str(),1,1,"0") {
    Serial.print("mqtt connected, ");
    mqttclient.setCallback(mqttCallback);
}

Does anyone have ideas?

I was trying to use the lastwill feature also with no luck. I have the understanding that it registers the will message with the broker upon connect. If it doesnt receive pings from the client within the keep alive time, it assumes it isnt connected anymore and the broker publishes the will message for the client.

But, I havent been able to get it working, but on Adafruits site and youtube there is a good video of them doing it. I think it is called MQTT and you, or something like that. If i do get it working, I will message ya back with my findings.

Rob