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
- Solved setWill() cause mqtt could not connect with SSL enable #107 https://github.com/marvinroger/async-mqtt-client/issues/107 — committed to jeroenst/async-mqtt-client by deleted user 5 years ago
- Solved setWill() cause mqtt could not connect with SSL enable #107 https://github.com/marvinroger/async-mqtt-client/issues/107 — committed to jeroenst/async-mqtt-client by deleted user 5 years ago
- Solved setWill() cause mqtt could not connect with SSL enable #107 https://github.com/marvinroger/async-mqtt-client/issues/107 — committed to jeroenst/async-mqtt-client by deleted user 5 years ago
- Solved setWill() cause mqtt could not connect with SSL enable #107 (#1) https://github.com/marvinroger/async-mqtt-client/issues/107 Co-authored-by: Jeroen <jst@dse.nl> — committed to OttoWinter/async-mqtt-client by moritzj29 5 years ago
- Fix #130, #147, #160 and #166 (#165) * Solved setWill() cause mqtt could not connect with SSL enable #107 https://github.com/marvinroger/async-mqtt-client/issues/107 * Fixed https://github.com/ma... — committed to marvinroger/async-mqtt-client by jeroenst 5 years ago
- Fix #130, #147, #160 and #166 (#165) * Solved setWill() cause mqtt could not connect with SSL enable #107 https://github.com/marvinroger/async-mqtt-client/issues/107 * Fixed https://github.com/marvi... — committed to kostko/async-mqtt-client by jeroenst 5 years ago
I figured out my problem. AsyncMqttClient doesn’t copy the last will topic or value but only saves a pointer. And after
setWillis called, topic and value might get out of scope.I’ve marked topic and payload
staticto keep them available for when the mqtt connection is established (which is async and not in the same scope assetWill).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…