PubSubClient MQTT Last Will not registered

Hi,

I'm using the following library to connect a ESP8266 to a MQTT broker. https://pubsubclient.knolleary.net/

Actually it works great, the client connects as it should, can send / receive data but it does not seem to register its last will. I tried with different brokers and clients to see if the broker supports LWT.

My last attempt was a local mosquitto broker to get more feedback of the broker itself.

My code I use to connect to the broker is the following:

if (client.connect(clientId.c_str()), "", "", "theEndTopic", 1, true, "offline") {
  client.publish("theEndTopic", "online", true);

When it connects, I get the following messages in the broker:

1596133014: New client connected from 192.168.0.159 as ESP8266Client-886f (p2, c1, k15).
1596133014: No will message specified.
1596133014: Sending CONNACK to ESP8266Client-886f (0, 0)
1596133014: Received PUBLISH from ESP8266Client-886f (d0, q0, r1, m0, 'theEndTopic', ... (6 bytes))

It clearly connects since it receives the message published

What am I missing here?

Regards

I found the issue, I really don't get why the compiler did not get this one.

One ')' was in the wrong position after clientId.c_str

if (client.connect(clientId.c_str()), "", "", "theEndTopic", 1, true, "offline")

should be

if (client.connect(clientId.c_str(), "", "", "theEndTopic", 1, true, "offline"))

1 Like