ESP8266 Developer Zone The Official ESP8266 Forum 2015-01-22T22:11:47+08:00 https://bbs.espressif.com:443/feed.php?f=7&t=147 2015-01-22T22:11:47+08:00 2015-01-22T22:11:47+08:00 https://bbs.espressif.com:443/viewtopic.php?t=147&p=541#p541 <![CDATA[Re: Waiting sent callback]]>
It works!!!

Thanks friend ;)

Statistics: Posted by ivanroberto — Thu Jan 22, 2015 10:11 pm


]]>
2015-01-22T20:13:32+08:00 2015-01-22T20:13:32+08:00 https://bbs.espressif.com:443/viewtopic.php?t=147&p=537#p537 <![CDATA[Re: Waiting sent callback]]>
Thanks for your help! I'll try this approach hight now.

Thanks

Statistics: Posted by ivanroberto — Thu Jan 22, 2015 8:13 pm


]]>
2015-01-22T06:03:24+08:00 2015-01-22T06:03:24+08:00 https://bbs.espressif.com:443/viewtopic.php?t=147&p=534#p534 <![CDATA[Re: Waiting sent callback]]> 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

Statistics: Posted by Peter — Thu Jan 22, 2015 6:03 am


]]>
2015-01-22T03:59:24+08:00 2015-01-22T03:59:24+08:00 https://bbs.espressif.com:443/viewtopic.php?t=147&p=532#p532 <![CDATA[Waiting sent callback]]>
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:

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
}

Statistics: Posted by ivanroberto — Thu Jan 22, 2015 3:59 am


]]>