mqtt Last Will Help, please.

I am trying to set a last will to tell me when a sensor has gone offline. (My hardware is a Wemos D1 Mini).

This code does not compile: if (client.connect(connectName,,,temperatureTopic,1,"Offlne")) {

My understanding is that the client.connect parameters are: clientId, username, password, lastWilltopic, lwt QOS, lwt message, lwt retain, keepalive

The compile error is: expected primary-expression before ',' token

So the compiler doesn't like the nulls for username and password? (My mqtt broker is local and does not have a username and password.)

Any tips would be appreciated.

you have to pass something, most likely the empty string "". You can't simply not pass parameters.

I tried if (client.connect(connectName,"","",temperatureTopic,1,"Offlne")) { and got the same error.

Try using NULL instead of empty string. And double check the order of the parameters.

https://pubsubclient.knolleary.net/api.html#connect5

I found my answer in looking at the function prototypes in the pubsubClient.h file:

boolean connect(const char* id, const char* willTopic, uint8_t willQos, boolean willRetain, const char* willMessage);

So, this compiles:

if (client.connect(connectName,temperatureTopic,1,1,“Offlne”)) {

I don’t know if it works yet, but it compiles without error.

SteveMann:
I found my answer in looking at the function prototypes in the pubsubClient.h file:

boolean connect(const char* id, const char* willTopic, uint8_t willQos, boolean willRetain, const char* willMessage);

So, this compiles:

if (client.connect(connectName,temperatureTopic,1,1,“Offlne”)) {

I don’t know if it works yet, but it compiles without error.

The 4th argument’s type implies that you will call the function with true or false…