Skip to content

MQTT Causing Memory Fragmentation? #119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
PundaVR opened this issue Apr 16, 2025 · 0 comments
Open

MQTT Causing Memory Fragmentation? #119

PundaVR opened this issue Apr 16, 2025 · 0 comments
Labels
type: imperfection Perceived defect in any part of project

Comments

@PundaVR
Copy link

PundaVR commented Apr 16, 2025

This is a "repost" of my arduino forums post.

The Problem

Arduino randomly stops sending data to my server after 12+ hours (anywhere from 12 to 48+ hours)

  • Board is Arduino Mega 2560 w/ Ethernet Shield
  • This Arduino has 6x DHT-22 sensors which gathers temperature and humidity data which are compiled into a JSON which is sent over MQTT (using ethernet) to my nodejs server (stores it to a database, displays it to Grafana, etc)

Full code can be found here

The reason I post here is that I've come to the conclusion that ArduinoMqttClient is one of the main causes of the crashes/disconnects I'm having (read my full reasoning here).

  • My methodology for my "debugging tests" are to send an MQTT messages (containing where in code it is, as one does with print statement debugging 🙂, and also data from stackAvailable() (function returning available memory in heap) - which showed memory was fine all the way until it crashes). However this method would mean the arduino is sending about 10 messages over MQTT a second.

  • Whilst running this modified version of my code - The Arduino would shut off after ~20-30 minutes instead of the usual 12+ hours, which means the extra usage of MQTT is 100% effecting the arduino (for the print-logs over MQTT I do not use JSON, instead I just send raw char[] like client.print("hello world"))

Because the stackAvailable() function showed memory to be fine, I think the problem is Memory Fragmentation (assuming that it isn't detectable via the stackAvailable() function, from what I've read online). The use of MQTT and also the code constantly assigning data to different arrays I assume is what's causing memory issues. Otherwise I have no idea 😦

I'm asking here in hopes anyone has any ideas as to what could be my problem, or if there are any known issues regarding memory with ArduinoMqttClient.

P.S. I don't know if this could be the reason, but I changed the TX_PAYLOAD_BUFFER_SIZE in MqttClient.cpp to 512 instead of 128 so I can send larger payloads over MQTT. Could this be causing a memory leak?

Many thanks to those willing to help 🙏 🙂

@per1234 per1234 added the type: imperfection Perceived defect in any part of project label Apr 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

2 participants