EthernetClient::write bug(?)

MrSupe
Sun Jan 10, 2016 12:23 pm
Could someone recheck my investigation…
Function size_t EthernetClient::write(const uint8_t *buf, size_t size) always returns 0. Even in case that it should return size.

mrburnette
Sun Jan 10, 2016 6:29 pm
There were recent issues with Ethernet:
http://www.stm32duino.com/viewtopic.php?t=692

but I had thought the issues were resolved. I have personally not run Ethernet on the STM32 Maple Mini, so maybe someone else will step-up and advise with deeper insight.

Ray


MrSupe
Mon Jan 11, 2016 9:43 am
My st32WebServer is almost done (ported from esp8266WebServer).
But because function size_t EthernetClient::write(const uint8_t *buf, size_t size) always returns 0 I cannot make chunks…
Only I can send bigger package at once. But it is not right solution…

zmemw16
Mon Jan 11, 2016 12:59 pm
<cringe>, tell fibs, put it in a wrapper, return a byte count and add a really big warning comment block/TODO/ #warning message</cringe>

any other way of detecting an incorrect or bad write?

stephen


MrSupe
Mon Jan 11, 2016 2:12 pm
I did this modification for testing only:
while (size_to_send) {
size_t will_send = (size_to_send < unit_size) ? size_to_send : unit_size;
size_t sent = _currentClient.write(send_start, will_send);
// if (sent == 0) {
// break;
// }
// size_to_send -= sent;
// send_start += sent;
size_to_send -= will_send;
send_start += will_send;
}
It works.
Anyway webserver is more slugish than those from ESP8266.

zmemw16: no word undertand :shock:


MrSupe
Mon Jan 11, 2016 2:17 pm
Complete functio:

void stm32WebServer::sendContent(const String& content) {
const size_t unit_size = HTTP_DOWNLOAD_UNIT_SIZE;//HTTP_DOWNLOAD_UNIT_SIZE = 1460, tested with different size
size_t size_to_send = content.length();
const char* send_start = content.c_str();

while (size_to_send) {
size_t will_send = (size_to_send < unit_size) ? size_to_send : unit_size;
size_t sent = _currentClient.write(send_start, will_send);
// if (sent == 0) {
// break;
// }
// size_to_send -= sent;
// send_start += sent;
size_to_send -= will_send;
send_start += will_send;
}
}


zmemw16
Mon Jan 11, 2016 4:40 pm
long description of what you did.
<cringe></cringe> is me waiting for the torrent of ‘that’s naughty’ comments

stephen


martinayotte
Mon Jan 11, 2016 4:54 pm
I think the issue need to be fixed in EthernetClient in first place, but with a quick look, I don’t see where is the bug.
Are you using the W5x00 implementation from Serasidis under F1 ?

MrSupe
Mon Jan 11, 2016 5:04 pm
Yes, I am using w5x00 and F1by Seradisis…

Problem is somewhere deeper:
size_t EthernetClient::write(const uint8_t *buf, size_t size) {
if (_sock == MAX_SOCK_NUM) {
setWriteError();
return 0;
}
if (!send(_sock, buf, size)) {
setWriteError();
return 0;
}
return size;
}

It should be in function send(…). Chunks have been sent but function returns 0.


martinayotte
Mon Jan 11, 2016 5:19 pm
Looking at https://github.com/Serasidis/Ethernet_S … pp#L91-L96, the comment about returning a boolean is wrong since few lines later, we can see that it is returning the length : https://github.com/Serasidis/Ethernet_S … t.cpp#L105
Also looking at the EthernetClient.cpp that you provide code, I don’t think the call to send(), it still handling it as boolean.
if (!send(_sock, buf, size)) {

Vassilis
Mon Jan 11, 2016 7:50 pm
What ethernet chip exactly do you use w5100 or w5500 (to focus on that chip) ?

MrSupe
Mon Jan 11, 2016 10:17 pm
i am using w5500

MrSupe
Mon Jan 11, 2016 10:45 pm
some investigentions:

extern int sudaint,sudaint1;//global variables iniatialiset to -1
void stm32WebServer::sendContent(const String& content) {
const size_t unit_size = HTTP_DOWNLOAD_UNIT_SIZE;
size_t size_to_send = content.length();
const char* send_start = content.c_str();
while (size_to_send) {
size_t will_send = (size_to_send < unit_size) ? size_to_send : unit_size;
sudaint=sudaint>(int)will_send?sudaint:(int)will_send;
size_t sent = _currentClient.write(send_start, will_send);
sudaint1=sudaint1>(int)sent?sudaint1:(int)sent;
if (sent == 0) {
break;
}
size_to_send -= sent;
send_start += sent;
}
}
After one WEB request (in my case it is 7 calls of write function) result:
sudaint = 1980
sudaint1 = 0

The same request with tracking variables in EthernetClient.cpp (hardware\Arduino_STM32\STM32F1\libraries\Ethernet_STM\src\)
extern int sudaint;
size_t EthernetClient::write(const uint8_t *buf, size_t size) {
sudaint=sudaint>(int)size?sudaint:(int)size;
if (_sock == MAX_SOCK_NUM) {
setWriteError();
return 0;
}
if (send(_sock, buf, size) == 0) {//this is already corrected – see communication above!!!!!
setWriteError();
return 0;
}
return size;
}
result:
sudaint = 1

It seems like there exists more EthernetClient sources.
EthernetClient::write(const uint8_t *buf, size_t size) is not the same function like i call in my stm32WebServer::sendContent(const String& content) function…correction with
if (send(_sock, buf, size) == 0) {//this is already corrected – see communication above!!!!!
setWriteError();
return 0;
}
I made only on EthernetClient.cpp (hardware\Arduino_STM32\STM32F1\libraries\Ethernet_STM\src\)


martinayotte
Mon Jan 11, 2016 10:59 pm
MrSupe wrote:
It seems like there exists more EthernetClient sources.

martinayotte
Tue Jan 12, 2016 2:11 am
MrSupe wrote:some investigentions:

extern int sudaint,sudaint1;//global variables iniatialiset to -1


MrSupe
Tue Jan 12, 2016 7:48 am
martinayotte:
:roll: I broke my USB-serial. Fortunately I have SEGGER Jtag with me, so this is hard improvisation debuging.
Content of these sudaint and sudaint1 variables I am reading from ETHERNET already through just developed stm32WebServer :D

martinayotte
Tue Jan 12, 2016 2:28 pm
What do you mean by “broken USB-Serial”, USB-Serial dongle ?
Why are you using those if the STM3 has already a virtual SerialUSB class.

Leave a Reply

Your email address will not be published. Required fields are marked *