Arduino MQTT last will

Hello

I try to create a last will with the Arduino MQTT Library (ArduinoMqttClient).

This is the code where i define the last will. It works. But only for one Topic. Does anyone know how to create a last will for more then one Topic?

String willPayload = "err"; bool willRetain = true; int willQos = 1;

mqttClient.beginWill("OG/Küche/Temperatur", willPayload.length(), willRetain, willQos); mqttClient.print(willPayload); mqttClient.endWill();

Thanks for your Help

Did you try doing this again for a different topic? LWT is specific to topic.

String willPayload = "err";
bool willRetain = true;
int willQos = 1;

mqttClient.beginWill("OG/Küche/Temperatur", willPayload.length(), willRetain, willQos);
mqttClient.print(willPayload);
mqttClient.endWill();

willPayload = "different message";
mqttClient.beginWill("OG/Küche/secondTopic", willPayload.length(), willRetain, willQos);
mqttClient.print(willPayload);
mqttClient.endWill();

a last will should be fairly short, singular in topic, (for most, the topic is "will" or "lastWill" etc.) and universal. You can't predict beforehand the way in which you will disconnect unexpectedly, so there's really not any reason to put a whole lot of thought into it.

I can't find definitive documentation on this. Mostly it seems to be as blh64 says, but I did see one place suggesting that providing a topic in a LWT message was optional. Also I wonder whether the topic wildcard would work.

See Arduino Client for MQTT API Documentation: https://pubsubclient.knolleary.net/api.html