Closed lhtrevisan closed 2 years ago
Hello @lhtrevisan, I did a heapcheck on my MQTT program:
Bibliotheken
Serial output 16:10:02.172 -> Connected to wifi. My address:192.168.1.20 16:10:02.205 -> Wednesday, January 19 2022 16:10:02 16:10:02.205 -> Connectie met de MQTT broker: 192.168.1.25 16:10:02.205 -> Verbonden met de MQTT broker ! 16:10:02.205 -> 16:10:02.238 -> sensor is a BME280 16:10:04.659 -> Wednesday, January 19 2022 16:10:04 16:10:04.758 -> Druk :1022.37 16:10:04.791 -> Druk64 :1022.38 16:10:04.791 -> Temperatuur:20.52 16:10:04.791 -> Vochtigheid:43.66 16:10:04.791 -> HEAP_Check: 250640
16:14:10.660 -> Wednesday, January 19 2022 16:14:10 16:14:10.759 -> Druk :1022.45 16:14:10.759 -> Druk64 :1022.41 16:14:10.792 -> Temperatuur:20.53 16:14:10.792 -> Vochtigheid:43.44 16:14:10.792 -> HEAP_Check: 250456
Arduino compile log Meerdere bibliotheken gevonden voor "WiFi.h" Gebruikt: /home/marc/.arduino15/packages/esp32/hardware/esp32/1.0.6/libraries/WiFi Niet gebruikt: /home/marc/Documenten/bin/arduino-1.8.18-linux64/arduino-1.8.18/libraries/WiFi Niet gebruikt: /home/marc/Arduino/libraries/WiFiEspAT Niet gebruikt: /home/marc/Arduino/libraries/WiFiNINA Bibliotheek Wire op versie 1.0.1 in map: /home/marc/.arduino15/packages/esp32/hardware/esp32/1.0.6/libraries/Wire wordt gebruikt Bibliotheek WiFi op versie 1.0 in map: /home/marc/.arduino15/packages/esp32/hardware/esp32/1.0.6/libraries/WiFi wordt gebruikt Bibliotheek Adafruit_LiquidCrystal op versie 1.1.0 in map: /home/marc/Arduino/libraries/Adafruit_LiquidCrystal wordt gebruikt Bibliotheek BMx280MI op versie 1.2.1 in map: /home/marc/Arduino/libraries/BMx280MI wordt gebruikt Bibliotheek ArduinoMqttClient op versie 0.1.5 in map: /home/marc/Arduino/libraries/ArduinoMqttClient wordt gebruikt Bibliotheek SPI op versie 1.0 in map: /home/marc/.arduino15/packages/esp32/hardware/esp32/1.0.6/libraries/SPI wordt gebruikt /home/marc/.arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/1.22.0-97-gc752ad5-5.2.0/bin/xtensa-esp32-elf-size -A /tmp/arduino_build_49053/BMx280_I2C-20220119-libarduinomqttclient.ino.elf De schets gebruikt 767846 bytes (58%) programma-opslagruimte. Maximum is 1310720 bytes. Globale variabelen gebruiken 41132 bytes (12%) van het dynamisch geheugen. Resteren 286548 bytes voor lokale variabelen. Maximum is 327680 bytes. python /home/marc/.arduino15/packages/esp32/tools/esptool_py/3.0.0/esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 115200 --before default_reset --after hard_res
Garc964, thank you for your reply, but you are using a different mqtt library(ArduinoMqttClient.h), instead of PubSubClient.
Also, you don't have WiFiClientSecure defined in your code... The code I posted does not use certificates, but for deployment I'll use them, as I intend to use AWS IoT instead of HiveMQ.
In answer to my own question, YES, this memory consumption is absolutely normal, as certificates demand about 5-6kb and pubsub needs another 17-18k.
I'm going for solution number 1 and hoping it does not crash on the long run by lack of memory.
Hello my fellow friends!
I'm experiencing crashes when the ESP tries to connect to the broker using pubsubclient. After some tinkering I realized it could be a problem of lack of memory. I then proceeded to test a code containing only the wifi connection and MQTT connection, without the rest of the libraries and functions, while monitoring the free HEAP. That is the simplified code I used on the test:
Code
``` //---------------------------------------------------------- Bibliotecas #includeThat is what is printed to the serial:
Serial
``` ******** Wi-Fi Conectado. IP: 192.168.1.142 HEAP_Check: 44040 Conectando com o broker MQTT... Connectado Setup finalizado. HEAP: 22840 ```As you can see, the connection is using about 21kb of HEAP... My full code has, right before the connection, about 25k of free HEAP that is, obviously, fragmented, thus not being enough to stablish a successful connection.
There are 2 ways of solving my problem: 1 - Freeing or defragmenting some HEAP, so that it is enough to connect, but could fail after some time, as it would be running with low memory from the beginning. 2 - Reducing the HEAP memory consumed while connecting to the broker.
So I ask you about this memory consumption. Is it normal for this library to consume that much of the HEAP memory, or maybe I'm experiencing some weird interaction between my ESP board libraries and pubsub?
I'm coding on Arduino IDE. PubsubClient library is up to date(downloaded it again yesterday, to make sure it was not the problem).