Heap strange decreasing

If you are asking a question, please follow this template:

Hi everybody!
I have the problem with MQTT using on my ESP32 - after about 2 minutes of my device working I recieve the messages about Heap decreasing. And after 20 minutes of working app is crashing.

The part of my code:

Timer.set(1000, Timer.REPEAT, function() {
MQTT.sub(topic, function(conn, topic, msg) {
print('Topic:', topic, 'message:', msg);
msg = JSON.parse(msg);
if(msg.devId==='host' && msg.cmd==='setTemp')  setTemp = msg.temp;
}, null);
}, null);

The part of log:
[Jun 6 21:12:44.398] mgos_mqtt.c:125 Subscribing to ‘devices’ (QoS 1)
[Jun 6 21:12:44.640] mgos_mqtt.c:135 MQTT event: 209
[Jun 6 21:12:44.645] mgos_mongoose.c:66 New heap free LWM: 163044
[Jun 6 21:12:45.383] mgos_mqtt.c:125 Subscribing to ‘devices’ (QoS 1)
[Jun 6 21:12:45.627] mgos_mqtt.c:135 MQTT event: 209
[Jun 6 21:12:45.631] mgos_mongoose.c:66 New heap free LWM: 162668
[Jun 6 21:12:46.387] mgos_mqtt.c:125 Subscribing to ‘devices’ (QoS 1)
[Jun 6 21:12:46.625] mgos_mqtt.c:135 MQTT event: 209
[Jun 6 21:12:46.630] mgos_mongoose.c:66 New heap free LWM: 162556
[Jun 6 21:12:47.387] mgos_mqtt.c:125 Subscribing to ‘devices’ (QoS 1)
[Jun 6 21:12:47.623] mgos_mqtt.c:135 MQTT event: 209
[Jun 6 21:12:47.627] mgos_mongoose.c:66 New heap free LWM: 162212
[Jun 6 21:12:48.391] mgos_mqtt.c:125 Subscribing to ‘devices’ (QoS 1)
[Jun 6 21:12:48.629] mgos_mqtt.c:135 MQTT event: 209
[Jun 6 21:12:49.398] mgos_mqtt.c:125 Subscribing to ‘devices’ (QoS 1)
[Jun 6 21:12:49.636] mgos_mqtt.c:135 MQTT event: 209
[Jun 6 21:12:50.398] mgos_mqtt.c:125 Subscribing to ‘devices’ (QoS 1)
[Jun 6 21:12:50.635] mgos_mqtt.c:135 MQTT event: 209
[Jun 6 21:12:50.640] mgos_mongoose.c:66 New heap free LWM: 161856
[Jun 6 21:12:51.393] mgos_mqtt.c:125 Subscribing to ‘devices’ (QoS 1)
[Jun 6 21:12:51.630] mgos_mqtt.c:135 MQTT event: 209
[Jun 6 21:12:51.635] mgos_mongoose.c:66 New heap free LWM: 161748
[Jun 6 21:12:52.395] mgos_mqtt.c:125 Subscribing to ‘devices’ (QoS 1)
[Jun 6 21:12:52.636] mgos_mqtt.c:135 MQTT event: 209
[Jun 6 21:12:52.640] mgos_mongoose.c:66 New heap free LWM: 161640
[Jun 6 21:12:53.398] mgos_mqtt.c:125 Subscribing to ‘devices’ (QoS 1)
[Jun 6 21:12:53.656] mgos_mqtt.c:135 MQTT event: 209
[Jun 6 21:12:53.660] mgos_mongoose.c:66 New heap free LWM: 161532

You call MQTT.sub every second. That’s the reason of heap decrease.

You have to call MQTT.sub only once.

1 Like