Waiting sent callback

ivanroberto
Posts: 14
Joined: Sat Nov 29, 2014 5:03 am

Waiting sent callback

Postby ivanroberto » Thu Jan 22, 2015 3:59 am

hello,

I am using a single socket client to receive data from a host and also to spontaneously send data to the host. I mean I do not have a pooling system to capture keyboard information by energetic consumer issues.

My problem is that I do not know how to wait for the callback when I'm ready to send new data.
In my code below I wait for 2 seconds to receive, however I notice that this loop is preventing the callback to occur.

Would you like to help me implement a procedure to wait this callback.

Thank U

Code: Select all

static bool _waitSentCB = false;

BOOL socketClientTX(uint8_t *Ptr, uint16_t len) {
   BOOL retorno = false;
   uint32_t timeOut;
   struct espconn *pespconn = &Conn;

   timeOut = system_get_time() + 2000000;
   do{
      if ((socketConnState >= TCP_CONNECTED) && !_waitSentCB) {
         sint8 espsent_status = espconn_sent(pespconn, Ptr, len);
         if (espsent_status == ESPCONN_OK) {
            _waitSentCB = true;            //Indica que o socket está ocupado enviando dados
            socketConnState = TCP_SENT_DATA;
            retorno = true;
            #ifdef PLATFORM_DEBUG
            ets_uart_printf("C > Data sent OK: %d bytes\r\n", len);
            #endif
         } else {
            socketConnState = TCP_SENDING_DATA_ERROR;
            #ifdef PLATFORM_DEBUG
            ets_uart_printf("C > ### Error while sending data.\r\n");
            #endif
         }
         break;
      }
      #ifdef PLATFORM_DEBUG
      ets_uart_printf("C > Aguarda SentCB\r\n");
      #endif
   }while(timeOut > system_get_time());
   return retorno;
}

static void ICACHE_FLASH_ATTR tcpclient_sent_cb(void *arg)
{
   struct espconn *pespconn = arg;

   _waitSentCB = false;            //Indica que o socket foi liberado
   #ifdef PLATFORM_DEBUG
   ets_uart_printf("tcpclient_sent_cb\r\n");
   #endif
}

Peter
Posts: 10
Joined: Fri Jan 09, 2015 3:00 pm

Re: Waiting sent callback

Postby Peter » Thu Jan 22, 2015 6:03 am

Hi, you must use a buffer and a bool 'ReadyToSend' init with true.
see end of post 5 in viewtopic.php?f=7&t=142

So you have 3 subs:
public (call it instead of espconn_sent)
1. socketClientTXBuffer
write in Buffer
if ReadyToSend=true call SendTxBuffer


private
2. SendTxBuffer
if (BufferLength>0) {
Send all in Buffer with espconn_sent
ReadyToSend =False
}

3. SentCallback
ReadyToSend =True
call SendTxBuffer

ivanroberto
Posts: 14
Joined: Sat Nov 29, 2014 5:03 am

Re: Waiting sent callback

Postby ivanroberto » Thu Jan 22, 2015 8:13 pm

Hi Peter,

Thanks for your help! I'll try this approach hight now.

Thanks

ivanroberto
Posts: 14
Joined: Sat Nov 29, 2014 5:03 am

Re: Waiting sent callback

Postby ivanroberto » Thu Jan 22, 2015 10:11 pm

Hi Peter,

It works!!!

Thanks friend ;)

Who is online

Users browsing this forum: No registered users and 202 guests