ioLibrary recv only returns Zeros

Hello Wiznet Community,

I want to use a w5500 connected via spi in a project to realize a Ethernet interface.
For this I created a small board and ported the ioLibrary for my setup.
The port works well except of the recv function. I can open a socket, start listening and
establish a connection. If I send data via the TCP connection recv returns the number of bytes correctly
but fills the buffer with only zeros.

This is a short code example. All functions (socket, listen) do return SOCK_OK.

wiz_NetInfo netInfo = { .mac = { 0x00, 0x08, 0xdc, 0xab, 0xcd, 0xef },
.ip = { 192, 168, 1, 222 },
.sn = { 255, 255, 255, 0 },
.gw = { 192, 168, 1, 1 },
.dns = { 0, 0, 0, 0 },

int main(){
//Board specific init code
wizchip_setnetinfo( &netInfo );
socket( 0, Sn_MR_TCP, 22000, 0 );
while( getSn_SR(0) != 0x17 ); //Wait for connection

uint8_t buffer[128];
    tmp = recv(0, buffer, 12 );
    buffer[tmp] = 0;
    printf( "%s\n", buffer );

return 0;

If you send for example “Hello” then tmp is 6 which is correct.
For printf with %s there is no output. If I print every byte as int you can see that every byte is 0.

Does anybody have an idea where this bug could come from?

Data “Hello” is having 5 bytes it in?

%s outputs till null char. If first char appears to be null nothing is displayed. I propose you making a data dump in hex.

Sorry the value of tmp for “Hello” is 7 and the hex value of the buffer after a read out
is [0,0,0,0,0,0,0]

??? :rofl: I think you can count letters - H E L L O is 5 letters, thus size returned must be 5, not 6 and not 7. Use wireshark to see what is actually going on the network. Send another phrase “Hello Friends” to see how many bytes recv will return.

No thats okay. If you use putty as ascii to tcp terminal, putty adds two characters for newline at the end of the payload.

Try declaring uint8_t buffer[128]; outside of the main() function (in the netInfo declaration location).

Okay I did declare the buffer outside of the main. Still only zeros in the return

I think there’s some issue with pointers. Before performing recv(), initialize buffer with some values, for example 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 to see if it will have these values after recv() execution or recv will really reload the array with zeros.

Okay I did work on the buffer stuff and found the error. The printing of the buffer was the original error.
The connection now works but from time to time the receive method receives way more bits than I sent.

Thanks alot for the help:)

1 Like