I figured out what was causing the delay. The Espressif releases of these libraries are using synchronous tls commands.
so in the ports folder of mqtt where the interface functions for network transport (network_transport.c) are defined there is this:
esp_tls_cfg_t xEspTlsConfig = {
.cacert_buf = (const unsigned char*) ( pxNetworkContext->pcServerRootCAPem ),
.cacert_bytes = strlen( pxNetworkContext->pcServerRootCAPem ) + 1,
.clientcert_buf = (const unsigned char*) ( pxNetworkContext->pcClientCertPem ),
.clientcert_bytes = strlen( pxNetworkContext->pcClientCertPem ) + 1,
.skip_common_name = pxNetworkContext->disableSni,
.alpn_protos = pxNetworkContext->pAlpnProtos,
#if CONFIG_CORE_MQTT_USE_SECURE_ELEMENT
.use_secure_element = true,
#elif CONFIG_CORE_MQTT_USE_DS_PERIPHERAL
.ds_data = pxNetworkContext->ds_data,
#else
.use_secure_element = false,
.ds_data = NULL,
.clientkey_buf = ( const unsigned char* )( pxNetworkContext->pcClientKeyPem ),
.clientkey_bytes = strlen( pxNetworkContext->pcClientKeyPem ) + 1,
#endif
.timeout_ms = 3000,
};
so when MQTT_ProcessLoop()
is called:
int32_t espTlsTransportRecv(NetworkContext_t* pxNetworkContext,
void* pvData, size_t uxDataLen)
{
if (pvData == NULL || uxDataLen == 0)
{
return -1;
}
int32_t lBytesRead = 0;
if(pxNetworkContext != NULL && pxNetworkContext->pxTls != NULL)
{
xSemaphoreTake(pxNetworkContext->xTlsContextSemaphore, portMAX_DELAY);
lBytesRead = esp_tls_conn_read(pxNetworkContext->pxTls, pvData, uxDataLen);
xSemaphoreGive(pxNetworkContext->xTlsContextSemaphore);
}
else
{
return -1; /* pxNetworkContext or pxTls uninitialised */
}
if (lBytesRead == ESP_TLS_ERR_SSL_WANT_WRITE || lBytesRead == ESP_TLS_ERR_SSL_WANT_READ) {
return 0;
}
if (lBytesRead < 0) {
return lBytesRead;
}
if (lBytesRead == 0) {
/* Connection closed */
return -1;
}
return lBytesRead;
}
esp_tls_conn_read()
will block for 3 seconds due to .timeout_ms = 3000
.
The latest LTS release lowered it down to 1000.
Is there a significant problem in lowering it even more?