JiriBilek / WiFiSpi

SPI library for Arduino AVR and STM32F1 to connect to ESP8266
GNU Lesser General Public License v3.0
62 stars 13 forks source link

WiFiClient - fast with available caching #12

Closed JAndrassy closed 3 years ago

JAndrassy commented 5 years ago

I test sketch upload to SAMD and nRF5 with different libraries and WiFiSpi couldn't make it. Was too slow. This PR makes WiFiSpiClient much faster in typical use with available() checking.

Additionally read(buffer, size) method should return count of bytes put into buffer, to be useful. Firmware doesn't change the input value of the parameter. I patched it with cached available count.

JiriBilek commented 5 years ago

Thank you, I will look at it ASAP.

JAndrassy commented 5 years ago

Arduino in WiFiNINA library uses a buffer layer https://github.com/arduino-libraries/WiFiNINA/blob/master/src/utility/WiFiSocketBuffer.cpp

JiriBilek commented 5 years ago

Juraj, finally, I examined your PR and IMHO there is a problem. The available bytes change in time as new data come through the wifi. I observed that shortly after sending GET request, the ESP reports some 1000 bytes available and after a while the value rises. I see, you are asking the ESP for new available bytes every time availData==0 but this might prevent reading bigger chunks of data. I have to consider both the positive and the negative aspects of the feature.

JAndrassy commented 5 years ago

I uploaded 40 kB of application binary over it.

availData is the last know count of available bytes. it is decremented as data are read and refreshed from esp if all of the known count of bytes was read

JiriBilek commented 5 years ago

Sure it works, I said I prefer buffered reading of data. I consider:

Hesitating:

Maybe more, I will post my further ideas here.

Just now I finished a first SSL support and my next goal should be https://github.com/JiriBilek/WiFiSpi/issues/14

JAndrassy commented 5 years ago

it has no advantage to refresh availData with every read. read(buff, size) should return count of bytes filled into buffer. (parameter size is the size of the buffer)

JiriBilek commented 5 years ago

Refreshing availData has sense when you are reading chunks of data into buffer held on client. I agree that the return value from read(buff, size) is bad, I copied the prototype from arduino library as I wanted my library to be 1:1 replacement.

JAndrassy commented 5 years ago

in my PR the return data size from read is the same as getAvailable called before read.

it can happen that the read return less then buffer size and it is not the end of all data. but it can always happen that the next chunk of data didn't arrive yet

JAndrassy commented 3 years ago

I close this because it doesn't sync for WiFClient copies