async-mqtt-client: setWill() cause mqtt could not connect with SSL enable

I am switch from PubSubClient becasue it block cpu. But i have a problem. I enable SSL by change ASYNC_TCP_SSL_ENABLED to 1. Then i set this line:

mqttClient.setWill(MQTT_LIGHT_AVAILABILITY_TOPIC, 0, true, MQTT_LIGHT_AVAILABILITY_LWTMESSAGE);

after

mqttClient.setServer(MQTT_HOST, MQTT_PORT);

But it will not connect to my server, remove the line it connected.

I have try to setWill() in onMqttConnect() but it not work.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 22 (4 by maintainers)

Commits related to this issue

Most upvoted comments

I figured out my problem. AsyncMqttClient doesn’t copy the last will topic or value but only saves a pointer. And after setWill is called, topic and value might get out of scope.

I’ve marked topic and payload static to keep them available for when the mqtt connection is established (which is async and not in the same scope as setWill).

My error was caused because the setwill function doesn’t copy the *topic data but just stores the pointer. Because I called this from a separate mqttinit function, the topic was lost because the variable containing the topic was not static. But SSL is still not working though…