Arduino-esp32: WiFi.h WiFiClient instance cause ESP32 to freeze randomly

Created on 30 Nov 2018  路  10Comments  路  Source: espressif/arduino-esp32

Hardware:

Board: ESP32 Dev Module
Core Installation/update date: ?11/jul/2017?
IDE name: Arduino IDE
Flash Frequency: ?40Mhz?
PSRAM enabled: no
Upload Speed: 115200
Computer OS: Windows 8.1

Description:

I am using the example provided with the ESP32 SDK about WiFiServer to send constantly data to a client.
Anyway in a few hundreds of lops the loop() just freeze for indefinitely long ( usually at least 2 seconds, up to like 11 seconds ), doing nothing, nothing else happens in the main loop during the freeze.
I have put a delay(100);, but still the issue is reprocuting on all ESP32 boards I have.
Every 100-500 loops it freeze for at least 2 seconds up to 11 seconds.

Sketch:

//Change the code below by your sketch
#include <Arduino.h>
#include <WiFi.h>

WiFiServer * wifiServer;

WiFiClient * clientX;

unsigned long rBuffer[ 65 ];

void setup() 
{
       Serial.begin( 115200 );
       wifiServer = new WiFiServer( 20800 );

    WiFi.onEvent( WiFiEvent );

    WiFi.mode( WIFI_AP );

    WiFi.softAP( "lVision" );

    wifiServer->begin();
    serverX = IPAddress( 192, 168, 100, 2 );
    clientX = new WiFiClient();
}

void loop()
 {
        rBuffer[ 64 ] = (unsigned long )'d'; // this is data

    if( clientX->connect( serverX, 20800 ) )
    {
        if( clientX->connected()  )
        {
            Serial.println( millis() );
            clientX->write( ( const uint8_t* )rBuffer, sizeof( rBuffer ) );

            clientX->stop();
            clientX->flush();
        }
    }
}

void WiFiEvent( WiFiEvent_t event )
{
    switch( event )
    {
        case SYSTEM_EVENT_AP_START:
        {
            IPAddress ipA = IPAddress( 192, 168, 100, 1 );
            IPAddress ipS = IPAddress( 255, 255, 255, 0 );
            WiFi.softAPConfig( ipA, ipA, ipS );
        }
        break;

        default:
        break;
    }
}


Debug Messages:


All 10 comments

Also I 've report some esp32 freeze when I check Wifi status or some network operations, udp reply or mysql query

I don't check neither the wifi status, nor i do network operations, nor database stuff.
I got nothing attached to the board.
Actually I do nothing into the mail loop. Just sending some random data, and yet - it stucking randomly.

I also use OTA , random data is sent sometimes

I am not sure I do understand.

me-no-dev has done some work on the WiFi queue since the 1.0.0 release. Can you test with the pre-release version and see if it is better? Also, don't close the session if it is not necessary. There's a fair amount of overhead establishing a TCP session.

It worked !!!!! Now it does not fails the loop() !
The process keeps going without any drop already 30 minutes.
Previously there were 1 significant loop failure each 30-60 seconds or so, now it seems the problem to be gone.
Anyway at some point there is a small performance drop about 1 per a few minutes or so, but it is insignificant.
anyway.

Great work !

O well.. I just have posted this and it failed the main loop for about 8 seconds again. :D
Anyway it is at least very rare now.

Add some delay on loop() is really necessary : ESP32 is powerful, and running at 320Mhz, so without any delay it will do the same operation may hundreds or thousands times per second, and this can cause instabilities

Additionally: what about keep the connection open with server instead open and close every loop() ? this will save you a lot of time and resources and reduce if not solve these instabilities

All done! It just stucking once per reboot seems like so far, and it's current performance is just great! Thanks dev team!

Closed as solved =)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gaurav0190 picture gaurav0190  路  55Comments

Buffalchill picture Buffalchill  路  60Comments

adamwilt picture adamwilt  路  63Comments

muktillc picture muktillc  路  57Comments

jh83 picture jh83  路  124Comments