Closed verybadsoldier closed 5 years ago
I guess the following is happening:
Serial.println(system_get_free_heap_size());
mqtt.publish("main/frameworks/sming", "Hello friends, from Internet of things :)");
The queue gets slowly filled with messages to be sent. All of them are waiting for a connection and thus requiring memory. At some point the memory just is not enough to hold all of them and thus your ESP12-F runs out of memory.
There are multiple ways how to solve this. One of them can be that we put a limit on the number of messages, or the total size in bytes of the messages, that can wait in the queue when the client is not connected. This way the client can accept, for example, max 3 messages and discard the rest. mqtt.publish
will return true for the accepted and false for the discarded. This is something that we can add in the framework.
Another thing that can be done in the application code is to push message in the queue only when the client is connected.
If we go for the items size or items memory limit in a queue then we should apply this also to the SmtpClient, HttpClient and others that queue items before sending them.
Thanks for looking into it but as statetd in the post I removed the call to publishMessage
. So in my opinion there is no publishing taking place anymore.
And sorry for the screwed up indetation in the code which really didn't improve readbility :(
So in my opinion there is no publishing taking place anymore.
That code should be compilable and runnable also in the Host Emulator. That means that you can yourself analyze the memory usage using valgrind. The latter will catch easily any memory issues. Or wait for me but that can take quite some time...
So in my opinion there is no publishing taking place anymore.
Every connection sends a MQTT connect message. Those messages start piling up in the queue. @mikee47 Provided a simplified fix in PR #1742. Give it a try and tell us if it works for you.
It seems that that trying to connect with
MqttClient
causes a memory leak. When the MQTT broker is not reachable and then retrying regularly then at some point you run out of heap.Should be easily reproducible with the sample
MqttClient_Hello
. While I used this exact code (basically only publish removed):Output is this:
Done on Sming 3.8.0 on an ESP12-F.