Dig Kleppe wrote:Hi Pratikm
I dont know what kind of server you use, but if its netconn based the additon of netconn_free solves the memoryleak;
My server task:
Code: Select all
while (1) {
void HTTPServerTask(void *pvParameters) {
struct netconn *conn, *newconn;
err_t err = ERR_OK;
while (1) {
while (!gotIP || !isConnected)
vTaskDelay(10);
conn = netconn_new(NETCONN_TCP);
netconn_bind(conn, NULL, 80);
netconn_listen(conn);
do {
err = netconn_accept(conn, &newconn);
if (err == ERR_OK) {
httpServerServe(newconn);
netconn_close(newconn);
netconn_delete(newconn);
netconn_free(newconn);
}
} while (err == ERR_OK);
netconn_close(conn);
netconn_delete(conn);
netconn_free(conn);
}
}
If you have a socket based server you have to dig further into the LWIP code. Probably the sockets also use netconns,
By the way:
Because of lack of memory when in trouble the reconnect did not work, only rebooting ...
Thnaks for quick response,
Yes i have used netcon API to create server, and also socket internally use netconn API.
Code: Select all
static void http_server(void *pvParameters)
{
ESP_LOGI(TAG,"system_get_free_heap_size in starting of server task =%d\n\n\n",system_get_free_heap_size());
struct netconn *conn , *newconn;
err_t err,err_listen,err_accept;
conn = netconn_new(NETCONN_TCP);
uint32_t total=0;
uint32_t used=0;
if(conn!=NULL)
{
err= netconn_bind(conn, NULL, 80);
if (err == ERR_OK)
ESP_LOGI(TAG,"socket bound");
err_listen=netconn_listen(conn);
if(err_listen==ERR_OK)
{
do{
ESP_LOGI(TAG,"system_get_free_heap_size before accept in request number %d =%d",++counter,system_get_free_heap_size());
ESP_LOGI(TAG,"system_get_time before accept in request number %d =%d",++counter,system_get_time());
err_accept = netconn_accept(conn, &newconn);
if (err_accept == ERR_OK)
{
ESP_LOGI(TAG,"connection accept\n");
ESP_LOGI(TAG,"\nsystem_get_free_heap_size after accept =%d\n\n\n",system_get_free_heap_size());
ESP_LOGI(TAG,"\nsystem_get_free_heap_size befor close newconn =%d\n\n\n",system_get_free_heap_size());
newconn->recv_timeout=2000;
xTaskCreate(http_server_netconn_serve,"http_server_netconn_serve",5000,newconn,10,http_server_netconn_serve_Task);
}
} while(err_accept == ERR_OK);
netconn_close(conn);
ESP_LOGI(TAG,"conn is close");
netconn_delete(conn);
} /*err_listen end */
}/*conn end */
vTaskDelete(NULL);
ESP_LOGI(TAG,"http exit");
}
void http_server_netconn_serve(void *pvParameters)
{
struct netbuf *inbuf;
char *buf;
u16_t buflen;
err_t err;
/* Read the data from the port, blocking if nothing yet there.
We assume the request (the part we care about) is in one netbuf */
ESP_LOGI(TAG,"waitting for data");
err = netconn_recv(pvParameters, &inbuf);
if (err == ERR_OK)
{
err_t err1=netbuf_data(inbuf, (void**)&buf, &buflen);
if (err1 != ERR_OK)
ESP_LOGI(TAG,"Data recived from client is not copied to buffer");
ESP_LOGI(TAG,"\nbuflen=%d\n",buflen);
ESP_LOGI(TAG,"system_get_free_heap_size befor paser function call=%d",system_get_free_heap_size());
parser(buf,buflen,pvParameters);
ESP_LOGI(TAG,"system_get_free_heap_size after paser function call=%d",system_get_free_heap_size());
netbuf_delete(inbuf);
err=netconn_close(pvParameters);
if (err != ERR_OK)
ESP_LOGI(TAG,"pvParameters not closed succesfully in parser");
err_t err_newconn_d=netconn_delete(pvParameters);
if (err_newconn_d != ERR_OK)
ESP_LOGI(TAG,"newconn not delete succesfully");
ESP_LOGI(TAG,"system_get_free_heap_size after delete and befor free =%d",system_get_free_heap_size());
//~ netconn_free(pvParameters);
//~ ESP_LOGI(TAG,"system_get_free_heap_size after calling netconn_free =%d",system_get_free_heap_size());
}
task_delete=1;
ESP_LOGI(TAG,"http_server_netconn_serve Task deleted");
}
I also use spiffs my spiifs partition is as following:
Code: Select all
## Label Usage Type ST Offset Length
0 nvs WiFi data 01 02 00009000 00006000
1 phy_init RF data 01 01 0000f000 00001000
2 factory factory app 00 00 00010000 00100000
3 storage Unknown data 01 82 00110000 00200000
when my board stop used spiffs is 19076 bytes.
My free heap size is 200000
here parser() function handles my buffer.
I am using idf v2.0 and modified app_lib.c.(no more require to call netconnfree() externally)
Is there anything i miss?