Closed hmueller01 closed 9 months ago
Do you have access to the broker logs?
I removed the
//.setWill(topic, QOS1, true, "offline")
setWill, which makes a difference:
mqttSetup: MQTT server mqtt:8883
mqttSetup: MQTT client id: RHTS-0015A582
mqttSetup: HomA system id: 15a582-rhts
Alloc (l:46)
state 0 --> 1
mqttConnect: connected using espMqttClient
state 1 --> 2
state 2 --> 3
tx 46/46 (10)
rx len 4
Packet type: 0x20
Remaining length: 2
Packet complete
state 3 --> 4
clearing queue (clear session: 1)
onMqttConnect: connected using espMqttClient
Packet buffer not allocated: low memory
Could not create SUBSCRIBE packet
Packet buffer not allocated: low memory
Could not create SUBSCRIBE packet
Packet buffer not allocated: low memory
Could not create SUBSCRIBE packet
Packet buffer not allocated: low memory
Could not create PUBLISH packet
Packet buffer not allocated: low memory
Could not create PUBLISH packet
Packet buffer not allocated: low memory
Could not create PUBLISH packet
Packet buffer not allocated: low memory
Could not create PUBLISH packet
Packet buffer not allocated: low memory
Could not create PUBLISH packet
Packet buffer not allocated: low memory
...
In the broker log I see
2024-02-03T22:28:07: New connection from 192.168.2.64:62176 on port 8883.
2024-02-03T22:28:08: New client connected from 192.168.2.64:62176 as RHTS-0015A582 (p2, c1, k15, u'xxx').
2024-02-03T22:28:32: Client RHTS-0015A582 has exceeded timeout, disconnecting.
espMqttClient is a tad more memory hungry than pubsubclient. As you can see you are running out of memory so the publish packets cannot be generated. Mind that TLS on esp8266 is already a stretch. With all the features you have in your program (based on the dependencies), it might be too much.
You can try to lower the free memory requirement in the config file or set it via a define in platformio.ini.
Ok, I set -D EMC_MIN_FREE_MEMORY=1024
and now it works with .setWill(topic, QOS1, true, "offline")
as well.
But memory fragmentation is really high:
getFreeHeap: 10608, getHeapFragmentation: 28, getMaxFreeBlockSize: 6944
compared to the PubSubClient variant
getFreeHeap: 11920, getHeapFragmentation: 8, getMaxFreeBlockSize: 10992
getFreeHeap: 12376, getHeapFragmentation: 10, getMaxFreeBlockSize: 11136
getFreeHeap: 12376, getHeapFragmentation: 9, getMaxFreeBlockSize: 11264
@bertmelis Thanks for your quick responses and the help you gave me!
Memory usage and fragmentation are indeed higher. Added features don't come for free...
I'm thinking about a crude memory pool but if you're already running low on memory it might just not work at all anymore. It's not on the top of my priority list.
My major issue about PubSubClient wasn't the features (ok, yes. QOS support needs to be improved). It's just abandoned by @knolleary. No needed PRs are processed any more. I was hoping the guys from thingsboard would take over, but it doesn't look like that. And I was hoping to find a way more light TLS client in your lib. But you are also just using the monster BearSSL ... so I doubt to get happy with the memory consumption using this lib. But thanks again for answering my problems here so fast!
and the new kid https://github.com/theelims/PsychicMqttClient
and the new kid https://github.com/theelims/PsychicMqttClient
Tx, but only ESP32
architectures=esp32
I need something for ESP8266 ... But maybe I'll give https://github.com/256dpi/arduino-mqtt a trail ... (@bertmelis sorry for waisting your issue with these kind of information, I'll stop here)
It's not a problem at all. Memory usage is a topic for this lib. It is for all libs that try to be compliant.
Pre-allocating memory helps for fragmentation but it uses a chunk of memory that isn't available for other processes anymore. Not a problem if you have enough memory left but in that case, fragmentation also isn't a real issue.
and the new kid https://github.com/theelims/PsychicMqttClient
Interesting but not really 'new'. It's a wrapper around the MQTT client from ESP-IDF. The ESP-IDF MQTT client has the same memory issues as my lib: packets are stored in heap memory --> https://github.com/espressif/esp-mqtt/blob/master/lib/mqtt_outbox.c#L44
esp8266, TLS, Platformio, latest Arduino 8266 git version (3.2.0-dev), SDK 3.0.5
MQTT broker: mosquitto 2.0.15
Debugging activated by
-D DEBUG_ESP_PORT=Serial -D DEBUG_ESP_MQTT_CLIENT
PubSubClient works with the same config (broker, user, pass, fingerprint) ...
It never comes to
onMqttConnect
and cycles endless ...Code
What can I do?