Problem sending large data buffer with W5500 and ioLibrary

I’ve got the following code to send buffered data to a server with the W5500. It uses the standard ioLibrary socket functions.

// runs every 1 second
send_data(void) {
    // data payload
    uint8_t payload[32];
    sprintf(payload, "%.2f,%.2f,%.2f,%u", env_t, env_p, env_h, env_l);

    // open socket number 1
    socket(1, Sn_MR_TCP, NULL, NULL);
    // connect to the server
    connect(1, dest_ip, dest_port);
    // send payload
    send(1, payload, strlen(payload));
}

Variables env_t, env_h, etc. are sensor values measured elsewhere in the code. The dest_ip and dest_port variables are the destination server details.

As it is shown above, the program works. However, if I increase the payload buffer size higher (e.g. to 64) in order to make the payload larger, the program no longer works (no serial output, no network activity). I know that ioLibrary checks the size of the provided buffer against its TX buffer size, but that is set to 2048 bytes, so it shouldn’t be a problem.

In my initialisation code I set the TX buffer size to 2kB:

uint8_t wiznet_buf_size[] = {2, 2, 2, 2, 2, 2, 2, 2};
wizchip_init(wiznet_buf_size, wiznet_buf_size);

Have I done something silly here?

What strlen(payload) returns exactly?

Hi Seands,

You might want to check if wizchip_init returns 0?

That question got me thinking a bit more about memory. I moved the definition of payload into the global scope and it now works. I am not sure why it didn’t work before though, because shouldn’t send() be able to see the variables in the scope of send_data if I pass a pointer to it?

This bug seems really bizarre - why did it work for a 32 byte buffer and not much higher?