Closed tarzan115 closed 6 years ago
hi @tarzan115
The library doesn't handle the SSL
. It uses provided Arduino
Client
compatible class to send/receive MQTT
messages.
I believe your problem is related to ESP
WiFiClientSecure
implementation. SSL
traffic takes much more resources of the ESP
chip comparing to normal TCP
traffic using ESP
WiFiClient
.
Need to check the amount of the free memory available on reception of the each message.
I don't know the ESP
network buffer size but It could be that the size is not enough to receive and keep all three messages between calls to the MqttClient::yield
to consume data.
Please try to investigate more.
In parallel, I am going to prepare the SSL
setup to try but it will take some time.
okay, thank you. I am waiting for that prepare 😄
Hi @tarzan115 I noticed the code example in esp8266/Arduino#3627.
In callback
method you allocate the new buffer for each new incoming message.
Unfortunately, I don't see what is inside processJsonFromServer
but I believe you free that buffer in this function. My recommendation is to avoid allocations for each message and use a preallocated buffer if you can predict the maximum message size.
In loop
you made the assumption that yield
receives exactly one message on each call.
Potentially the long enough yield
call is able to receive more than one message. But you call yield
with 1 ms
value so probably the timer will expire right after the reception of the single
message. Better to call yield
with 0 ms
value to be sure.
Please add additional debug log to check the amount of the free memory available in ESP
on reception of the each message. Take a look on ESP.getFreeHeap
and similar to investigate available ESP
resources.
Does your ESP
disconnect and successfully reconnect to the broker without restart or it just crashes and reconnect on next boot? Please attach some logs.
hi @monstrenyatko
I'm on testing and I also call yield
with 0 ms
but it still errors
when ESP disconnected, MQTT does not reconnect anymore. I have to add mqtt->disconnect();
before network.stop();
which don't have in your example.
I'm checking to see which one is taking up memory, need more time to find out.
hi @monstrenyatko
I have check ESP.getFreeHeap
, each message has a value about 200 bytes
and the memory free is about 13000 bytes
. but when I turn off SSL the memory free is about 30000 bytes
. much more with SSL.
hi @monstrenyatko
it not about the amount of the free memory. after fix some small bugs. The memory takes back all memory by MQTT and buffer. so I think this error from WiFiClientSecure
library.
hi @tarzan115 Seems like the esp8266/Arduino#3627 is resolved. Could you please let me know If that helps.
I work perfectly 😄 this issue can close for now.
thank you for your remind me.
@tarzan115 Great! Thank you for the confirmation.
hi @monstrenyatko I tested on MQTT use SSL when sent 3 messages in once. The device just receives the first message and then disconnected. I also tried in MQTT not have SSL, it works fine. My message has the length about 100 bytes for each.
NET_MIN_TM_MS
I set default is10
My device isESP8266
thank you and have a good day.