-->
Page 2 of 4

Re: in desperate need for RAM to run mqtt over TLS

PostPosted: Sun May 26, 2019 6:28 pm
by davydnorris
If you get a detailed memory map from the build, you'll at least be able to see where your RAM is going, and then you can start looking at moving functions and data to flash. I found using -DUSE_OPTIMIZE_PRINTF made a big difference as it moved all printf strings into flash. I also found I had a couple of functions that I had left the ICACHE_FLASH_ATTR directive off - I now only have a couple of interrupt service routines that are in RAM.

The other thing I found was that there are several problems with the default esp_mqtt code, and one that may be affecting you is that it allocates a 2kB data array on the heap during publish routines, but this is only used when there is a publish buffer overrun to clear the oldest message from the buffer. I changed this to a malloc inside the error handling if statement instead. This made a big difference to the amount of free heap I had at crucial moments
https://github.com/tuanpmt/esp_mqtt/issues/160

I also found I could set the SSL size to 4096 for MQTT and still publish everything I needed to, however I needed 5120 for HTTPS calls to a different server, so it's highly dependent on where you're connecting - have a play reducing the value for your site and you may find you can get away with less.

Re: in desperate need for RAM to run mqtt over TLS

PostPosted: Tue May 28, 2019 11:49 am
by Solomon Candy
I got 70k free DRAM on my latest - RTOS-3.1 - build !! On NONOS-2 I got about 48k I think.
That is after running LWIP with mdns and a TCP connection and a couple of my own libs.

BTW porting from NONOS to RTOS is really easy, except the espconn part. There is nothing to port otherwise really except changing the header files, and the create process calls if you used processes in NONOS in the first place. I was really clinging to NONOS for a long time but when I was forced to make the change, it was eeasy-peasy.

Re: in desperate need for RAM to run mqtt over TLS

PostPosted: Thu May 30, 2019 9:55 am
by maverickchongo
@davydnorris

Thanks a lot for your input on this, it has helped me greatly to identify where I could save some memory, combined with the use of -DUSE_OPTIMIZE_PRINTF I was able to get enough ram to run mqtt over TLS.

Thanks a bunch

Re: in desperate need for RAM to run mqtt over TLS

PostPosted: Thu May 30, 2019 11:49 pm
by davydnorris
That's great news! :-)