NONOS: how can I check that a UDP packet was actually sent

eyal
Posts: 12
Joined: Thu Apr 09, 2015 8:52 pm

NONOS: how can I check that a UDP packet was actually sent

Postby eyal » Fri Feb 03, 2017 7:36 pm

I find that entering deep sleep often fails to transmit the last UDP packet sent. I now delay the sleep by 30ms, which is a hack.

I would rather have a way to check that it is OK to sleep, or otherwise be able to register a callback indicating the packet was sent (the radio send buffer is empty).

To make it clear: I need to know that the ESP sent it, not that the destination received it, as is the case with UDP.

TIA

pratik

Re: NONOS: how can I check that a UDP packet was actually sent

Postby pratik » Mon Feb 06, 2017 12:04 pm

Use espconn_sent_callback to know when the data was sent. This callback is valid for both TCP and UDP.
Please do not force deep sleep on the CPU unless you know for sure all network tasks have been completed. Thing like UART printing can also be disrupted if you shut down the system before print buffer is cleared.

eyal
Posts: 12
Joined: Thu Apr 09, 2015 8:52 pm

Re: NONOS: how can I check that a UDP packet was actually sent

Postby eyal » Mon Feb 06, 2017 4:14 pm

Thanks Pratik.

I recall there was an issue where the callback was triggered as soon as the UDP packet was queued and not after it was actually sent.

Here is what I did then (over a year ago) https://github.com/makehackvoid/ESP8266Lib/tree/master/examples/eyal/noos and at that time I needed to add a 30ms delay after the sent callback or the packet was not delivered.

I understand that your experience is that this is not the case, and the callback is issued after the radio completes sending the packet?

cheers

=============== later ================

I now revived my rtos app, using SDK 1.5.0 (from github). I set up an espconn connection and then send a UDP packet.
In the sent callback function I go into deep sleep. The packet never arrives.

1) I tried to do 'xTaskDelay()' before the deep sleep but it does not seem to work (I measured the delay and it lasts only 20us), maybe I am missing something about task management in rtos? How can I do a delay inside the callback?
.
Here is what the (non working) code looks like:

Code: Select all

static void
all_done(void)
{
  vTaskDelay(40 / portTICK_RATE_MS);
  printf("%d sleeping\n", system_get_time());

  system_deep_sleep_set_option(SLEEP_TYPE);
  system_deep_sleep(SLEEP_TIME_US);
}

static void
udp_sent_callback(void *arg)
{
  printf("%d UDP sent\n", system_get_time());
  all_done();
}

printf("%d UDP send\n", system_get_time());
espconn_sendto(&espconn, message, strlen(message));


What the timing shows:

Code: Select all

244599 UDP send
247419 UDP sent
254488 sleeping

Q: Why the Delay does not work (the "sleeping" message is only 7ms later) when called from the callback but does work from the mainline (as below)?

2) If I instead ignore the callback and move the 'all_done()' directly after the send:

Code: Select all

static void
udp_sent_callback(void *arg)
{
  printf("%d UDP sent\n", system_get_time());
}

printf("%d UDP send\n", system_get_time());
espconn_sendto(&espconn, message, strlen(message));
all_done();

I now see the packets arriving, but I do need a 'xTaskDelay()' of longer than 30ms or all packets are lost.
BTW, I see the "UDP sent" within 3ms of sending and the delay shows 36ms:

Code: Select all

255368 UDP send
258405 UDP sent
294967 sleeping


Q: Why do I need a delay?

Who is online

Users browsing this forum: No registered users and 60 guests