ESP8266 Developer Zone The Official ESP8266 Forum 2021-04-22T17:10:33+08:00 https://bbs.espressif.com:443/feed.php?f=66&t=74713 2021-04-22T17:10:33+08:00 2021-04-22T17:10:33+08:00 https://bbs.espressif.com:443/viewtopic.php?t=74713&p=99685#p99685 <![CDATA[Re: Repeatedly connecting and disconnecting to AP breaks httpd_server]]> Statistics: Posted by Her Mary — Thu Apr 22, 2021 5:10 pm


]]>
2021-03-05T05:28:43+08:00 2021-03-05T05:28:43+08:00 https://bbs.espressif.com:443/viewtopic.php?t=74713&p=99413#p99413 <![CDATA[Repeatedly connecting and disconnecting to AP breaks httpd_server]]>
Effectively, I want the httpd server to start up when a device connects to the esp8266's access point. Then I want to remove that web server when that device disconnects to the esp8266's access point. I find that when a device repeatedly connects and disconnects to the esp8266's access point, the httpd server stops responding to requests and outputs these errors instead:

```
httpd: httpd_accept_conn: error in accept (23)
httpd: httpd_server: error accepting new connection.
```

I have the server starting up in a wifi_event_handler like so:

```
esp_err_t wifi_event_handler(void *ctx, system_event_t *event)
{
httpd_handle_t *server = (httpd_handle_t *) ctx;
/* For accessing reason codes in case of disconnection */
// system_event_info_t *info = &event->event_info;

ESP_LOGI(TAG, "Handle incoming wifi event");

switch(event->event_id) {
case SYSTEM_EVENT_AP_STACONNECTED:
// Start webserver once client joins
if (*server == NULL) {
*server = start_webserver();
}
break;
case SYSTEM_EVENT_AP_STADISCONNECTED:
// Stop webserver once client leaves
/* Stop the web server */
if (*server) {
stop_webserver(*server);
*server = NULL;
}
break;
default:
break;
}
return ESP_OK;
}
```

I'm wondering if anyone has also experienced this, or if I am just missing something

Statistics: Posted by GreenLoofa — Fri Mar 05, 2021 5:28 am


]]>