Page 1 of 1

Light sleep after sending a UDP packet using the sendto() function on ESP32-S3

Posted: Sun Feb 09, 2025 2:37 pm
by Honzik321
Dear ESP programmers,

I am working on a power-saving project where I need to periodically send UDP packets (1500 bytes each) every 10 ms to 50 ms. How can I ensure that ESP immediately enters light sleep after sending each packet?

So far, it only works reliably when I insert a 50 ms delay between sending a packet and entering the light sleep mode. When the delay is shorter, it occasionally returns these errors:

Code: Select all

Error occurred during sending: errno 12
Error occurred during sending: errno -1
Error occurred during sending: errno 118
For example, with a 10 ms delay, it can run for several minutes without any issues, and then suddenly start generating errors, after which it resumes sending correctly again...

Function for send UDP packet:

Code: Select all

// Sending data through the open socket
void udp_send_data(const char *data, size_t len) {
    if (udp_socket < 0) {
        ESP_LOGE(TAG_UDP, "Socket is not initialized");
        return;
    }

    int err = sendto(udp_socket, data, len, 0, (struct sockaddr *)&dest_addr, sizeof(dest_addr));
    if (err < 0) {
        ESP_LOGE(TAG_UDP, "Error occurred during sending: errno %d", errno);
    } else {
        // ESP_LOGI(TAG_UDP, "Data sent successfully");
    }
}
Main:

Code: Select all

...
udp_send_data((char *)(buffer_ptr), BUFFER_SIZE);
// Inserted delay
// vTaskDelay(10 / portTICK_PERIOD_MS); // 10 ms
esp_rom_delay_us(1000);  // 1000 µs
esp_light_sleep_start();
...
Thank you!

Re: Light sleep after sending a UDP packet using the sendto() function on ESP32-S3

Posted: Tue Feb 11, 2025 8:10 am
by nopnop2002
sendto somehow passes information to the tiT task and infers that the tiT task will do the actual sending.

I think it will be an error if you sleep before the tiT task is finished sending.

The user probably has no way of knowing when the tiT task has finished sending.

Re: Light sleep after sending a UDP packet using the sendto() function on ESP32-S3

Posted: Tue Feb 11, 2025 6:42 pm
by Honzik321
What is the best approach for the fastest transition to light sleep after sending a UDP packet? Is it better to use automatic light sleep without manually triggering the light sleep function? Would it be more efficient to send, for example, 10 UDP packets and then sleep for a longer period? What delay between two UDP packets makes sense? For example, could light sleep work properly only if the delay between sending packets is greater than 1 second?