ESP-Azure: tlsio_esp_tls_send_async without a prior successful open error
Posted: Thu May 16, 2019 6:30 pm
Hi!
I have a problem to maintain a stable connection to the Azure IoT Hub with the esp-azure sdk. I would like to upload the data from a queue to the hub continuously but the connection fails after 1 or 2 hours and the esp could not reconnect. This is the error message I get:
IoTHubClient_LL_SendEventAsync accepted message [1741] for transmission to IoT Hub.
Error: Time:Sat May 4 08:31:18 2019 File:/home/dev/esp/esp-azure/port/src/tlsio_esp_tls.c Func:tlsio_esp_tls_send_async Line:543 tlsio_esp_tls_send_async without a prior successful open
Error: Time:Sat May 4 08:31:18 2019 File:/home/dev/esp/esp-azure/azure-iot-sdk-c/umqtt/src/mqtt_client.c Func:sendPacketItem Line:371 542: Failure sending control packet data
Error: Time:Sat May 4 08:31:18 2019 File:/home/dev/esp/esp-azure/azure-iot-sdk-c/umqtt/src/mqtt_client.c Func:mqtt_client_publish Line:1059 Error: mqtt_client_publish send failed
Error: Time:Sat May 4 08:31:18 2019 File:/home/dev/esp/esp-azure/azure-iot-sdk-c/iothub_client/src/iothubtransport_mqtt_common.c Func:publish_mqtt_telemetry_msg Line:865 Failed attempting to publish mqtt message
Here is my code for the task:
Thank you for your help in advance!
Gary
I have a problem to maintain a stable connection to the Azure IoT Hub with the esp-azure sdk. I would like to upload the data from a queue to the hub continuously but the connection fails after 1 or 2 hours and the esp could not reconnect. This is the error message I get:
IoTHubClient_LL_SendEventAsync accepted message [1741] for transmission to IoT Hub.
Error: Time:Sat May 4 08:31:18 2019 File:/home/dev/esp/esp-azure/port/src/tlsio_esp_tls.c Func:tlsio_esp_tls_send_async Line:543 tlsio_esp_tls_send_async without a prior successful open
Error: Time:Sat May 4 08:31:18 2019 File:/home/dev/esp/esp-azure/azure-iot-sdk-c/umqtt/src/mqtt_client.c Func:sendPacketItem Line:371 542: Failure sending control packet data
Error: Time:Sat May 4 08:31:18 2019 File:/home/dev/esp/esp-azure/azure-iot-sdk-c/umqtt/src/mqtt_client.c Func:mqtt_client_publish Line:1059 Error: mqtt_client_publish send failed
Error: Time:Sat May 4 08:31:18 2019 File:/home/dev/esp/esp-azure/azure-iot-sdk-c/iothub_client/src/iothubtransport_mqtt_common.c Func:publish_mqtt_telemetry_msg Line:865 Failed attempting to publish mqtt message
Here is my code for the task:
Code: Select all
void azure_task(void *pvParameter)
{
xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT,
false, true, portMAX_DELAY);
ESP_LOGI(TAG, "Connected to AP success!");
(void)IoTHub_Init();
int result;
esp_err_t err;
IOTHUB_SECURITY_TYPE security_type;
//security_type = IOTHUB_SECURITY_TYPE_SAS;
security_type = IOTHUB_SECURITY_TYPE_X509;
(void)iothub_security_init(security_type);
IOTHUB_DEVICE_CLIENT_LL_HANDLE device_ll_handle;
if ((device_ll_handle = IoTHubDeviceClient_LL_CreateFromConnectionString(conn_string, MQTT_Protocol)) == NULL)
{
(void)printf("Failure creating device Auth!\r\n");
result = __LINE__;
}
else
{
size_t msg_count = 0;
IOTHUB_CLIENT_SAMPLE_INFO iothub_info;
iothub_info.stop_running = 0;
(void)IoTHubDeviceClient_LL_SetMessageCallback(device_ll_handle, receive_msg_callback, &iothub_info);
(void)IoTHubDeviceClient_LL_SetConnectionStatusCallback(device_ll_handle, connection_status_callback, &iothub_info);
while(1)
{
while (xQueueReceive(azure_queue, &dataToAzure, portMAX_DELAY) == pdTRUE)
{
static char msgText[1024];
sprintf_s(msgText, sizeof(msgText), "%s", dataToAzure);
IOTHUB_MESSAGE_HANDLE msg_handle = IoTHubMessage_CreateFromByteArray((const unsigned char*)msgText, strlen(msgText));
if (msg_handle == NULL)
{
(void)printf("ERROR: iotHubMessageHandle is NULL!\r\n");
}
else
{
IoTHubDeviceClient_LL_SendEventAsync(device_ll_handle, msg_handle, NULL, NULL);
(void)printf("IoTHubClient_LL_SendEventAsync accepted message [%zu] for transmission to IoT Hub.\r\n", msg_count);
msg_count++;
IOTHUB_CLIENT_STATUS status;
while ((IoTHubClient_LL_GetSendStatus(device_ll_handle, &status) == IOTHUB_CLIENT_OK) && (status == IOTHUB_CLIENT_SEND_STATUS_BUSY))
{
IoTHubClient_LL_DoWork(device_ll_handle);
vTaskDelay(100);
}
IoTHubMessage_Destroy(msg_handle);
}
}
}
}
// Clean up the iothub sdk handle
IoTHubDeviceClient_LL_Destroy(device_ll_handle);
// Free all the sdk subsystem
(void)IoTHub_Deinit();
vTaskDelete(NULL);
}
Gary