Sming - Open Source framework for high efficiency native ESP8266 development

User avatar
By snowbody
#24701 From within a webpage I use
$.getJSON('ajax/stage', function(data) (as in the example)

This ajax call gets executed often, by means of timer in javascript

The debug puts out : TcpServer onClient 193.191.205.2, activeClients = 77

Each call increases activeClients by 1, till there's is no heap-space left.

--the tcp server code--
CONNECTION DROPPED
if (system_get_free_heap_size() < 6500)
system_get_free_heap_size
---------------------------------

So I'm wondering, is there a way to make ajax-calls without incrementing the activeClients (and eating up the heap space)?
User avatar
By hreintke
#24759 Snowbody,
The error shown here is a wrong displayed number of activeClients. It is not accurate decremented when using a HTTP Server. The actual tcpclients are closed correctly and memory from that is returned (heap is not increasing).
Beware, the heap is sometimes returned with some delay (about 30 seconds) due to the nature of TCP protocol.
I checked with HTTP_AJAX example adding this code :
Code: Select allint savedMemory = USHRT_MAX;
Timer memoryTimer;
void memoryCheck()
{
   int currentMemory = system_get_free_heap_size();
   if (currentMemory != savedMemory)
   {
      debugf("Memory update : Free heap = %d \r\n ",currentMemory);
      savedMemory = currentMemory;
   }
}

and calling in init()
Code: Select all   memoryTimer.initializeMs(250,memoryCheck).start();

I used for my testing only "pure HTTP requests" as I have no experience with AJAX/JSON.
Conclusion from my side : the underlying tcpserver/httpserver framework works correctly excluding the display of a wrong number of active clients, which I will try to solve.

I do have seen a reported issue on json : https://github.com/anakod/Sming/issues/190
Maybe that issue is related to your "memory experience" but someone else has to dig into that
User avatar
By snowbody
#24889 Basically I just make a JSON call every 30 seconds. (instead of a few seconds) which seems to solve my memory issue.

Still, the heap-size fluctuates a lot (5K) inbetween the calls. (So if my program will occupy more space, guess it will run into same problem)

My problem seems indeed very similar to the reported issue on json : https://github.com/anakod/Sming/issues/190

Many thanks for you illuminating answer!