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
}