Description
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 🙏 🙂