me-no-dev / AsyncTCP

Async TCP Library for ESP32
GNU Lesser General Public License v3.0
757 stars 439 forks source link

ESPAsync stops working after AsyncTCP.cpp warning (timeout) #78

Closed ViniP8 closed 4 years ago

ViniP8 commented 5 years ago

Hi!

From time to time, the ESPAsync server slows down, freezes for a few seconds, or completely stops working until reboot (or until the user disconnects and reconnects to the AP).

Enabling verbose mode at serial monitor, some warnings show up before the problem happens (not all of them at the same time, sometimes only one of these happens):

[W][AsyncTCP.cpp:893] _poll(): pcb is NULL [W][AsyncTCP.cpp:913] _poll(): rx timeout 4 [W][AsyncTCP.cpp:906] _poll(): ack timeout 4

Is there any way to check if this problems has happened, so that I can restart the server?

This error usually happens when loading more than one file at time (>10KB) with the ESP on AP mode.

Tested with Chrome, Firefox, running on Linux (ubuntu) and Windows.

zhivko commented 5 years ago

Try in your client:

if (ws.hasClient(lastWsClient)) { if (ws.availableForWrite(lastWsClient)) ws.text(lastWsClient, txtToSend); }

I know sometimes network/browser results in browser unable to receive data, that data then piles up inside asynctcp....

Also heap grows in server if this happens.

Also add call to this function in separate task every 10seconds: It helped me with stucked tcpip stack of esp-idf...

void forceARP() { char netif = netif_list; while(netif) { netif = ((char **) netif); } }

Report if you had succes with this.

After this modifications, my project based on asynwebserver that uses we sockets, runs now for:

106.12 hours

And is stil responsive.

On Wed, 18 Dec 2019, 00:58 ViniP8, notifications@github.com wrote:

Hi!

From time to time, the ESPAsync server slows down, freezes for a few seconds, or completely stops working until reboot (or until the user disconnects and reconnects to the AP).

Enabling verbose mode at serial monitor, some warnings show up before the problem happens (not all of them at the same time, sometimes only one of these happens):

[W][AsyncTCP.cpp:893] _poll(): pcb is NULL [W][AsyncTCP.cpp:913] _poll(): rx timeout 4 [W][AsyncTCP.cpp:906] _poll(): ack timeout 4

Is there any way to check if this problems has happened, so that I can restart the server?

This error usually happens when loading more than one file at time (>10KB) with the ESP on AP mode.

Tested with Chrome, Firefox, running on Linux (ubuntu) and Windows.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/me-no-dev/AsyncTCP/issues/78?email_source=notifications&email_token=AA4EUBV3DQC2PJUAKAE7JTDQZFRTJA5CNFSM4J4DGOQKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4IBGGVNQ, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA4EUBUFM2OXENLVEV2BZPTQZFRTJANCNFSM4J4DGOQA .

ViniP8 commented 5 years ago

Thank you very much!!

I've never used the WebSocket plugin, so i'll try to use it and report if the solutoin works!!

Just one question: The variable "netif_list" from the forceARP() function comes from where? (I'm using arduino IDE and didn't found it)

Edit: I searched about using websockets, but I think it won't be viable, because I'm using the ESP as a server to be accessed via browser, not via a WS client(correct me if i'm wrong). Do you know if there any way to implement those solutions on a webserver that only uses a AsyncWebServer object to work? (E.g. the simple_server example)

zhivko commented 5 years ago

WS client should be part of javacript code, that "resides" in your html, that you serve from your esp32 http server. This html is then returned to browser(client), and js code is executed. In that moment websocket client is created that sends or/and retrieves data from esp32 asyncwebserver.

Regarding netif_list - I use esp-idf and not arduino so ... this function is still to be ported to arduino esp32. Possibly the guy that maintain arduino esp32 should find it needed / usefull before they do that. However without that function in place every 10 seconds, espasyncwebserver was also locking on my side.... Maybe TCP/IP stack on esp32 is locked - and that function somehow unlocks it.

ViniP8 commented 5 years ago

Got the idea!!

The problem is that, sometimes, while going from one page to another, the server stops (before fully loading the HTML/JS)

For now, I'm using a ping library to ping the gateway, because apparently when the server stops, the esp can't even ping the router. When this happens, I'm disconnecting and reconnecting from the network.

Of course that pinging the gateway and disconnecting from the network isn't a good solution, and only works on STA mode

I'll study the ESP libraries for arduino to see if there is any way to clear the TCP/IP stack, and a way to check if the server is responsive and report here

ViniP8 commented 5 years ago

Using the following code, i'm able to compile the code using the forceARP() function, but the problem continues happening (server freezing after ack timeout):

extern "C" {
   char *netif_list;
   uint8_t etharp_request(char *, char *);
 }

void forceARP(){
    char *netif = netif_list;
    while(netif){
        netif = *((char **) netif);
    }
}

I tried removing the uint8_t etharp_request(char *, char *);, but the problem continues.

Then I searched on internet about the etharp_request, but using etharp_request((netif), (netif+4)); (used in a few solutions for ESP8266) results in:

assertion "netif->hwaddr_len must be the same as ETH_HWADDR_LEN for etharp!" failed: file "/Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/lwip/netif/etharp.c"

(maybe because i'm using ESP32?)

Any other ideas?

From now and on thank you very much!

stale[bot] commented 5 years ago

[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

stale[bot] commented 4 years ago

[STALE_DEL] This stale issue has been automatically closed. Thank you for your contributions.

GeorgeFlorian commented 4 years ago

Any updates on this ? It's still happening.