MQTT apply for messaging is causing out of memory
-
I am have a a Basic Core device and I'm trying to build an integration with HomeAssistant, i have a number of sensors and relays connected to the M5. I have the device reading and publishing all the sensors to HA, however i have two relays i want to be able to trigger from HA, I have created the MQTT subscriptions however the moment i add "MQTT apply for messaging" to Loop, I my code initially works, then i start to see "mqtt_client: Error create mqtt task" errors every 15 seconds (I have nothing set on a 15 sec timer)), and after some time i get "mqtt_client: esp_mqtt_set_config(415): Memory exhausted" and the system panics and needs a power cycle before it will start working again
The moment i remove "MQTT apply for messaging" i no longer have this issue....
Not sure what to do, i even tried to build a safe function that would tear down MQTT and reconnect, but whatever i do, i still run out of memory eventually
-
Ok after some more work, i have decided to modify the project and manually code it rather than using the GUI, so no more nested str concats etc and no more massive list of global variables.
After all that work, im still getting "mqtt_client: Error create mqtt task" errors every 15 seconds
Using gc.mem_free(), i have confirmed i never have less than 60k of memory free, i have also confirmed that no MQTT publish exceeds 400 bytes
I do have quite a few items published (16) however I have grouped them so its only 5 calls to update them all. and i have 2 subscriptions
I have spent 2 days digging at this and I cant find any reason for the "mqtt_client: Error create mqtt task" errors or the eventual "esp_mqtt_set_config(415): Memory exhausted" even though right before this message i had my own logging return that i still have 70k of memory (and i had run a gc.collect()
I'm updating my sensors once every 60 seconds, yet even when these are not updating I still get the "mqtt_client: Error create mqtt task" which means something else is running and using mqtt, none of my code is, im not sure how to troubleshoot this further.
I'm avoiding having to switch to C++ and Arduino as I tried that but had issues with the i2c connectivity and timing so i would really like to get this working in the M5 stack micro python, any assistance would be much appreciated
-
@oracle_sod I think this may be connected to an error I found.
set up a basic "Hello world" example and check the terminal. I was getting MQTT server errors with basic code because M5Stack are using MQTT for pushing programs from the UIFLow server to the cores. -
@ajb2k3 I did notice the device trying to connect out to the uiflow URL using MQTT, is there a way to disable this ? I have a feeling there are memory leaks in the uiflow code and i don't need any of that (happy to connect via usb to update)... Or is there a way to get support from M5stack on this ?
-
@oracle_sod I had planned to add HA to uiflow2, but I didn't have the time to implement it. Here's a library I wrote if you're using MicroPython.https://github.com/lbuque/micropython-home-assistant
-
@oracle_sod I recently discovered this problem too, when the device sends multiple reconnections to the server, a memory leak will occur. This problem has existed for a long time.