Black Lives Matter - Action and Equality. ... Adafruit joins the Stop Hate for Profit campaign.

MQTT Last Will
Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Please be positive and constructive with your questions and comments.

MQTT Last Will

by Epircus on Sat Jun 01, 2019 12:18 pm

I bought a Huzzah ESP8266 which I'm using to control an LED strip through a web client.

I implemented a rabbitmq mqtt server on a raspberry pi.

I started out using the PubSubClient library for mqtt. Everything was going pretty smoothly until I tried sending a Last will message that would be retained.
Code: Select all | TOGGLE FULL SIZE
byte willQoS = 0;
const char* willTopic = "tv/pixel/status";
const char* willMessage = "turn off";
boolean willRetain = true;

client.connect("Pixel", "username", "password", willTopic, willQoS, willRetain, willMessage);

But no matter what I do the message will not be set to retain. I suspect its a bug but I don't know enough C++ or about mqtt to fix it.

Now my question is if nothing screams out about what I'm doing incorrectly with Pubsubclient library, then can the adafruit mqtt library retain last will messages? If so can I see some proper documentation on it?

I looked through a few examples which was all I could find and nothing showed the option to retain.

Posts: 1
Joined: Thu May 23, 2019 9:32 pm

Re: MQTT Last Will

by brubell on Mon Jun 03, 2019 10:35 am

We have a forum topic about this here: viewtopic.php?f=56&t=97813#p494821

and a blog post:

If you're still having issues, please post your code and the libraries you're using in your code.

Posts: 937
Joined: Fri Jul 17, 2015 10:33 pm

Please be positive and constructive with your questions and comments.