WiFi Interface Stop

pratik.yadav.455
Posts: 21
Joined: Thu Oct 26, 2017 7:34 am

WiFi Interface Stop

Postby pratik.yadav.455 » Mon Dec 11, 2017 7:04 am

Hello,

I created HTTP server using lwip netcon library.

Also i applied changes as suggested by :
https://github.com/espressif/esp-idf/issues/784.

I have following scenario:

1) When i Create simple http server it works fine.(Tested it with more than 140000 requested).

2) But when used spiffs to store my data in file transition stop at random time and when i try to connect
to http server , i can’t. I have to reboot Board.

3)To Check that is there any issue with spiffs i run standalone test in which i did same functionality of my
http server, without any socket(netcon) API. Which is works fine.

But when I merge Spiffs with simple http My server stop responding after some request(around 1500), And can’t reconnect with it.

My spiffs 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
My Wifi configuration is as following:

Code: Select all

static esp_err_t event_handler(void *ctx, system_event_t *event)
{
    switch(event->event_id) {
    case SYSTEM_EVENT_STA_START:
        esp_wifi_connect();
        break;
    case SYSTEM_EVENT_STA_GOT_IP:
        xEventGroupSetBits(wifi_event_group, CONNECTED_BIT);
        printf("got ip\n");
        printf("ip: " IPSTR "\n", IP2STR(&event->event_info.got_ip.ip_info.ip));
        printf("netmask: " IPSTR "\n", IP2STR(&event->event_info.got_ip.ip_info.netmask));
        printf("gw: " IPSTR "\n", IP2STR(&event->event_info.got_ip.ip_info.gw));
        printf("\n");
        fflush(stdout);
        break;
    case SYSTEM_EVENT_STA_DISCONNECTED:
        /* This is a workaround as ESP32 WiFi libs don't currently
           auto-reassociate. */
           doReconnect=true;
        esp_wifi_connect();
        xEventGroupClearBits(wifi_event_group, CONNECTED_BIT);
        break;
    default:
        break;
    }
    return ESP_OK;
}

static void initialise_wifi(void)
{
    tcpip_adapter_init();
    wifi_event_group = xEventGroupCreate();
    ESP_ERROR_CHECK( esp_event_loop_init(event_handler, NULL) );
    wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
    ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
    ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) );
    ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_AP) );
    wifi_config_t ap_config = {
        .ap = {
            .ssid = "REST_SERVER",
            .password = "9876543210",
            .authmode=WIFI_AUTH_WPA_WPA2_PSK,
            .max_connection=4,
            
        }
    };

    ESP_ERROR_CHECK( esp_wifi_set_config(ESP_IF_WIFI_AP, &ap_config) );
    ESP_ERROR_CHECK( esp_wifi_start() );
}

My server Code is As following:

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());
      
      
     }
     
   vTaskDelete(http_server_netconn_serve_Task);
   
   task_delete=1;
   
   ESP_LOGI(TAG,"http_server_netconn_serve Task deleted");
  
}


Where my parser Function Check which kind of requests (POST, GET,DELETE,PUT) is requested from client, and send html formatted string in respond.

When POST is requested so file which is sent in POST request , I stored it in SPIFFS in http_parser's Body callback using fopen and fwrite.

After More than 1000 Requests Server stop responding , And has following log:

Code: Select all

I (525892) wifi: station: 00:13:ef:d4:02:09 leave, AID = 1
I (525902) wifi: n:1 0, o:1 0, ap:1 1, sta:255 255, prof:1
I (529002) wifi: n:1 0, o:1 0, ap:1 1, sta:255 255, prof:1
I (529002) wifi: station: 00:13:ef:d4:02:09 join, AID=1, g, 20
I (580092) wifi: station: 00:13:ef:d4:02:09 leave, AID = 1
I (580092) wifi: n:1 0, o:1 0, ap:1 1, sta:255 255, prof:1
I (582152) wifi: n:1 0, o:1 0, ap:1 1, sta:255 255, prof:1
I (582152) wifi: station: 00:13:ef:d4:02:09 join, AID=1, g, 20
I (592152) wifi: station: 00:13:ef:d4:02:09 leave, AID = 1
I (592152) wifi: n:1 0, o:1 0, ap:1 1, sta:255 255, prof:1
I (595362) wifi: n:1 0, o:1 0, ap:1 1, sta:255 255, prof:1

[code]

Am I missing  something?

pratik.yadav.455
Posts: 21
Joined: Thu Oct 26, 2017 7:34 am

Re: WiFi Interface Stop

Postby pratik.yadav.455 » Tue Dec 12, 2017 6:21 am

Is it WiFi Configuration or WiFi related issue or other?
Anyone can help me to suggest where to look specifically?

Rajkumar181
Posts: 9
Joined: Fri Dec 08, 2017 3:44 pm

Re: WiFi Interface Stop

Postby Rajkumar181 » Fri Dec 15, 2017 5:50 am

Update your component library than try.

pratik.yadav.455
Posts: 21
Joined: Thu Oct 26, 2017 7:34 am

Re: WiFi Interface Stop

Postby pratik.yadav.455 » Tue Dec 26, 2017 7:19 am

hello @ESP_Angus @ESP_Sprite

Can you please suggest me where to look ?

pratik.yadav.455
Posts: 21
Joined: Thu Oct 26, 2017 7:34 am

Re: WiFi Interface Stop

Postby pratik.yadav.455 » Wed Jan 03, 2018 5:48 am

Hello @ESP_Angus @ESP_Sprite

I created Simple Rest Server using netcon library.
Simple Rest Server Works Fine.
But When I introduce Flash Write Operation.
I am Writing to flash from 0x300000 location.
Size of Data Written into flash is 900KB.
My AP disappear After 3 Hour.

My partition file detail is As following:

Name, Type, SubType, Offset, Size, Flags
nvs, data, nvs, 0x9000, 0x4000,
otadata, data, ota, 0xd000, 0x2000,
phy_init, data, phy, 0xf000, 0x1000,
factory, app, factory, 0x10000, 0x100000,
ota_0, app, 0x10, 0x110000, 0x100000,
storage, data, 0x82, 0x210000, 0xC0000,

When I Replaced Flash Write Operation with 100 ms Delay, Which works fine more than 12 hours. And AP Not Disappear.

Is there Anything I missed.?

Let me Know If you requires More Detail about it.

WiFive
Posts: 2081
Joined: Tue Dec 01, 2015 7:35 am

Re: WiFi Interface Stop

Postby WiFive » Wed Jan 03, 2018 7:03 am

What esp-idf version and commit are you using?

pratik.yadav.455
Posts: 21
Joined: Thu Oct 26, 2017 7:34 am

Re: WiFi Interface Stop

Postby pratik.yadav.455 » Fri Jan 05, 2018 4:40 am

WiFive wrote:What esp-idf version and commit are you using?
I am using Idf-2.1 and commit's deatail is as following:
commit:27574a31e7c41f6e22e10e9b9d7713c6d49f795d
Merge: efdbc63 8134140
Author: Ivan Grokhotkov <ivan@espressif.com>
Date: Mon Jul 24 19:42:36 2017 +0800

pratik.yadav.455
Posts: 21
Joined: Thu Oct 26, 2017 7:34 am

Re: WiFi Interface Stop

Postby pratik.yadav.455 » Tue Jan 09, 2018 4:47 am

hello @ WiFive

Let me know if you need more detail about it, or any suggestion about it.

pratik.yadav.455
Posts: 21
Joined: Thu Oct 26, 2017 7:34 am

Re: WiFi Interface Stop

Postby pratik.yadav.455 » Wed Jan 17, 2018 4:29 am

Hello,

I tested same code with idf 3.0rc1 which is running perfectly without any issue.

I also Tested it with 2.1 and 2.1.1 but, facing same AP disappear issue.

So i want to know that is there any issue with WiFi stack or Flash SPI in previous release(2.0,2.1,2.1.1)?

Is Anyone know about this kind of issue?

If anyone need more detail about it please let me know.

Return to “ESP32 IDF”

Who is online

Users browsing this forum: Google [Bot] and 15 guests