ESP32 WiFi non blocking send errors

my_abousamra
Posts: 8
Joined: Mon Feb 06, 2017 9:54 am

ESP32 WiFi non blocking send errors

Postby my_abousamra » Tue Mar 28, 2017 9:53 am

Dears,
I'm trying to send data over ESP32 wifi (600 bytes every 25 msec) in non blocking send mode but after a while I got EWOULDBLOCK and if I disables nagle's algorithm I got ENOMEM

What should I do to make it send data correctly?

Code: Select all

        while (1)
        {
        	for ( i = 3; i > 0; i-- )
        	{
        		for ( len = 0 ; len < TEST_BUF_SIZE ; )
        		{
        			Buffer [len++] = (u32DataIdx >> 24 ) & 0xFF;
        			Buffer [len++] = (u32DataIdx >> 16 ) & 0xFF;
        			Buffer [len++] = (u32DataIdx >>  8 ) & 0xFF;
        			Buffer [len++] = (u32DataIdx       ) & 0xFF;
        			u32DataIdx++;
        		}

        		ret = send( s, Buffer , TEST_BUF_SIZE, MSG_DONTWAIT );
        		if ( ret < 0) {
        			ESP_LOGE(TAG, "... socket send failed %d %d [%s]", ret, errno, strerror (errno));
        		}
        		else if ( ret < TEST_BUF_SIZE )
        		{
        			ESP_LOGE(TAG, "ret %d", ret);
        		}
        	}

        	vTaskDelay( 25 / portTICK_RATE_MS );
        }
Regards,
Last edited by my_abousamra on Wed Apr 26, 2017 10:17 am, edited 1 time in total.

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: ESP32 WiFi non blocking send errors

Postby kolban » Tue Mar 28, 2017 1:53 pm

This is a wild guess ... but maybe its worth considering ... a TCP socket is a streamed entity ... meaning the data appears at the other end in the order you sent it. Instead of sending data in units of 600 bytes every 25 msecs ... accumulate your data in RAM and have a task that runs in the background that checks whether the socket is free to send. If it is, send all the data that has accumulated so far. This way you may be sending fewer but larger units of data and achieve a better through put. Ignoring TCP overheads,

600 bytes at 25msec per record is 24,000 bytes which is 192,000 bits. Thus at a minimum you would need a bandwidth of at least 192kbps. Try sending a very large stream of data from the ESP32 to the back-end server and measure the throughput you are experiencing. If it is less than 192kbps then you have a problem because you are producing more data per second than you are able to transmit per second and things will obviously back-up. On a LAN, you might expect to be able to push mega bits per second ... but if you are communicating over the internet the throughput might be far less.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

my_abousamra
Posts: 8
Joined: Mon Feb 06, 2017 9:54 am

Re: ESP32 WiFi non blocking send errors

Postby my_abousamra » Tue Mar 28, 2017 3:47 pm

Actually, This code is just a test but my original code is 2 tasks, first one is a uart task that receives data from other microcontroller with that rate (I can't change it) and I push that data into a queue to a wifi task that sends that data to a server (local server in that test in the same LAN not Internet). The problem here is send API in some way disables interrupts therefor uart task can't run to acquire new data.

So, as you suggested to accumulate data until socket become free is a good point but when sending that data over wifi it will take some time where uart task miss some data from the other microcontroller

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: ESP32 WiFi non blocking send errors

Postby kolban » Tue Mar 28, 2017 5:47 pm

I would be VERY dissapointed to hear that sending data over WiFi interfered with the timings of reading from a UART. Since UART doesn't have a shared clock, it is vital that it maintain very coherent timings with its partner. I believe that the UART is hardware assisted meaning (to me) that built into the SoC will be dedicated circuits and timings to read into RAM data received irrespective of what other aspects of the chip are doing. There may have to be some design to ensure that the data provided by the UART is consumed as it will have finite capacity to store the received data ... but otherwise I would be very surprised if reading or writing to the network caused data to be lost through the UART.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

my_abousamra
Posts: 8
Joined: Mon Feb 06, 2017 9:54 am

Re: ESP32 WiFi non blocking send errors

Postby my_abousamra » Wed Mar 29, 2017 4:16 pm

Is there any way to speed up sending data over wifi? I don't know very much about lwip but i think i can increase its sending speed by increasing allocating memory or any other optimization

Who is online

Users browsing this forum: No registered users and 67 guests