🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    MQTT apply for messaging is causing out of memory

    UiFlow 2.0
    3
    6
    145
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • O
      oracle_sod
      last edited by

      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

      475e36f5-5e38-4c5e-a5b9-77e55ccee34b-image.png

      1 Reply Last reply Reply Quote 0
      • O
        oracle_sod
        last edited by oracle_sod

        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

        ajb2k3A 1 Reply Last reply Reply Quote 0
        • ajb2k3A
          ajb2k3 @oracle_sod
          last edited by

          @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.

          UIFlow, so easy an adult can learn it!
          If I don't know it, be patient!
          I've ether not learned it or am too drunk to remember it!
          Author of the WIP UIFlow Handbook!
          M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

          O 1 Reply Last reply Reply Quote 0
          • O
            oracle_sod @ajb2k3
            last edited by

            @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 ?

            lbuqueL 1 Reply Last reply Reply Quote 0
            • lbuqueL
              lbuque
              last edited by

              @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

              1 Reply Last reply Reply Quote 0
              • lbuqueL
                lbuque @oracle_sod
                last edited by

                @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.

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post