setWill() cause mqtt could not connect with SSL enable
Closed this issue · 22 comments
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.
I am also having this problem. I can connect over SSL perfectly but when using the SetWill command it will not connect with an disconnect with reason 0
I'm working without SSL but can't connect after setWill
. After commenting out, it works just fine!
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
).
@bertmelis
Could you post your code? I still seem to have the problem
This is my code https://pastebin.com/T4e9Ezc8
I'm getting : [ WARN ] Disconnected from MQTT. Reason: 0
You're using mosquitto? What does the log of your broker say?
FYI, my code is in https://github.com/bertmelis/TreeLight
I don't use SSL though.
1536078725: Socket error on client , disconnecting.
1536078725: New connection from 192.168.0.107 on port 8883.
It is kind of weird how it tries to connect twice just after each other
Without SSL it is working? It sure seems like some buffer got overwritten.
It is working without SSL and it is working without the mqttClient.setWill
Edit: The log without the setwill
1536083371: New connection from 192.168.0.107 on port 8883.
1536083371: New client connected from 192.168.0.107 as esp8266055ab7 (c1, k20, u'').
1536083371: Sending CONNACK to esp8266055ab7 (0, 0)
1536083371: Received SUBSCRIBE from esp8266055ab7
1536083371: house/office/firealarm/command (QoS 0)
1536083371: esp8266055ab7 0 house/office/firealarm/command
1536083371: Sending SUBACK to esp8266055ab7
1536083385: Received PINGREQ from esp8266055ab7
1536083385: Sending PINGRESP to esp8266055ab7
Same problem, setwill doesn't work with SSL
Sadly ATM I lack time to investigate, but I will try to... When I can
For some reason I now have the same problem when not using SSL. When I remove setwill from code I can connect, with setwill connection will fail, and the mosquitto logging says:
1545571378: New connection from 192.168.2.153 on port 1883.
1545571378: Socket error on client , disconnecting.
Try change the lwIP to v2 Higher Bandwidth
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...
Hi
is there a workaround to get setwill() with SSL working?
I would love to know, what I can do for MQTTClient::setwill() with TLS/SSL..
Is there a chance to get it working?
The solution is here:
https://github.com/256dpi/arduino-mqtt
Set a will message (last testament) that gets registered on the broker after connecting. setWill() has to be called before calling connect():<
The solution is here:
https://github.com/256dpi/arduino-mqtt
Set a will message (last testament) that gets registered on the broker after connecting. setWill() has to be called before calling connect():<
Is this really non-blocking asynchronous and for esp8266?
The problem is that the _onconnect function calls _client.add for each piece of data to send to the mqtt server. When setwill is used, there is to much data to be send by the ASyncTCP module because it also add ssl data to each packet, causing it to drop the password.
After changing the code to send less packets setwill works with SSL!
The problem is that the _onconnect function calls _client.add for each piece of data to send to the mqtt server. When setwill is used, there is to much data to be send by the ASyncTCP module because it also add ssl data to each packet, causing it to drop the password.
After changing the code to send less packets setwill works with SSL!
Could you help me, how send less packets?
Our problem is the same - eclipse-mosquitto/mosquitto#1715
Will topic works sometimes, not always.
I believe this is ultimately caused by #193. What I've done to get SSL working is implementing a queue and only allowing the packet in the head to be on the wire at any time.
This requires QoS2 and popping packets once they're acknowledged
I believe this is ultimately caused by #193. What I've done to get SSL working is implementing a queue and only allowing the packet in the head to be on the wire at any time.
This requires QoS2 and popping packets once they're acknowledged
Hello.
Thank you for your answer, but it's for asynchronous code.
We use synchronous version, because packets not so much to send/get.
But the problem is the same. Server got Will topic in mosquitto log file. But it publishes 50/50 times. Also we can't find a way, when it's happed. It's always different. Will topic can go/it may be lost.
Do you know how solve it?
The issue should be gone using the development
branch.