From 467e4d997bd85d36d301f617883dce662f386a4f Mon Sep 17 00:00:00 2001 From: David Cermak Date: Mon, 21 Sep 2020 15:12:22 +0200 Subject: [PATCH 1/2] MQTT: Update submodule reference: config, error handle, minor fixes Updates esp-mqtt reference to include fixes below related mainly to: * configuration update (disable keepalive, network timeout) * minor fixes (size_t for all sizes, unbalanced lock, api for outbox-size) * extended error handle to include socket's errno Closes https://github.com/espressif/esp-idf/issues/5906 Config: Added config value to disable keepalive mechanism esp-mqtt commit: https://github.com/espressif/esp-mqtt/commit/8562437c8a50754998f7b5484773851fd1c42388 Related https://github.com/espressif/esp-mqtt/issues/179 Added esp_mqtt_client_get_outbox_size API esp-mqtt commit: https://github.com/espressif/esp-mqtt/commit/0a1d9d0300335ca98dd1fed8d2ec2411145877b0 Related https://github.com/espressif/esp-mqtt/pull/178 mqtt_outbox: Removed unused retry_count field from outbox_item_t esp-mqtt commit: https://github.com/espressif/esp-mqtt/commit/673086e13a7ff141929ddc9739da3d197f8a5720 config: Fixed typo for configuring OUTBOX_EXPIRED_TIMEOUT_MS esp-mqtt commit: https://github.com/espressif/esp-mqtt/commit/259baaec9671ea3c32afa3c27a1196fce5646974 Fixed missing MQTT_API_UNLOCK in esp_mqtt_client_stop error path esp-mqtt commit: https://github.com/espressif/esp-mqtt/commit/845c2a3a1e112af5dbe5f3a9ee8f6adb92a03757 Related https://github.com/espressif/esp-mqtt/issues/173 Related https://github.com/espressif/esp-mqtt/pull/174 Extended mqtt error handle to capture transport's socket errno (IDF v4.3+) esp-mqtt commit: https://github.com/espressif/esp-mqtt/commit/23c8e1ecf5681d60032f8405990116a589290b57 Config: Added configuration value to set network timeout esp-mqtt commit: https://github.com/espressif/esp-mqtt/commit/a03228ac4639eeb324af99dcded44a1f4113d3c3 Related https://github.com/espressif/esp-mqtt/pull/166 Used size_t for all lengths to allow for other architectures esp-mqtt commit: https://github.com/espressif/esp-mqtt/commit/b9db8d90204c7f9a23165630fd74ad621516c0c7 --- components/mqtt/esp-mqtt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/mqtt/esp-mqtt b/components/mqtt/esp-mqtt index b9db8d9020..da850b0add 160000 --- a/components/mqtt/esp-mqtt +++ b/components/mqtt/esp-mqtt @@ -1 +1 @@ -Subproject commit b9db8d90204c7f9a23165630fd74ad621516c0c7 +Subproject commit da850b0add1e71b3659bfac5d797cc834dc3e89b From c31cd77d43e488778012dee3b3af0af39f9e8199 Mon Sep 17 00:00:00 2001 From: David Cermak Date: Tue, 3 Nov 2020 08:23:51 +0100 Subject: [PATCH 2/2] examples: make mqtt tcp example to report tcp-transport errno --- examples/protocols/mqtt/ssl/main/app_main.c | 4 +++- examples/protocols/mqtt/tcp/main/app_main.c | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/examples/protocols/mqtt/ssl/main/app_main.c b/examples/protocols/mqtt/ssl/main/app_main.c index 1afb9c0b7e..1c15a29c39 100644 --- a/examples/protocols/mqtt/ssl/main/app_main.c +++ b/examples/protocols/mqtt/ssl/main/app_main.c @@ -89,9 +89,11 @@ static esp_err_t mqtt_event_handler_cb(esp_mqtt_event_handle_t event) break; case MQTT_EVENT_ERROR: ESP_LOGI(TAG, "MQTT_EVENT_ERROR"); - if (event->error_handle->error_type == MQTT_ERROR_TYPE_ESP_TLS) { + if (event->error_handle->error_type == MQTT_ERROR_TYPE_TCP_TRANSPORT) { ESP_LOGI(TAG, "Last error code reported from esp-tls: 0x%x", event->error_handle->esp_tls_last_esp_err); ESP_LOGI(TAG, "Last tls stack error number: 0x%x", event->error_handle->esp_tls_stack_err); + ESP_LOGI(TAG, "Last captured errno : %d (%s)", event->error_handle->esp_transport_sock_errno, + strerror(event->error_handle->esp_transport_sock_errno)); } else if (event->error_handle->error_type == MQTT_ERROR_TYPE_CONNECTION_REFUSED) { ESP_LOGI(TAG, "Connection refused error: 0x%x", event->error_handle->connect_return_code); } else { diff --git a/examples/protocols/mqtt/tcp/main/app_main.c b/examples/protocols/mqtt/tcp/main/app_main.c index 2c2abbe6f1..f23e7746e0 100644 --- a/examples/protocols/mqtt/tcp/main/app_main.c +++ b/examples/protocols/mqtt/tcp/main/app_main.c @@ -33,6 +33,13 @@ static const char *TAG = "MQTT_EXAMPLE"; +static void log_error_if_nonzero(const char * message, int error_code) +{ + if (error_code != 0) { + ESP_LOGE(TAG, "Last error %s: 0x%x", message, error_code); + } +} + static esp_err_t mqtt_event_handler_cb(esp_mqtt_event_handle_t event) { esp_mqtt_client_handle_t client = event->client; @@ -75,6 +82,13 @@ static esp_err_t mqtt_event_handler_cb(esp_mqtt_event_handle_t event) break; case MQTT_EVENT_ERROR: ESP_LOGI(TAG, "MQTT_EVENT_ERROR"); + if (event->error_handle->error_type == MQTT_ERROR_TYPE_TCP_TRANSPORT) { + log_error_if_nonzero("reported from esp-tls", event->error_handle->esp_tls_last_esp_err); + log_error_if_nonzero("reported from tls stack", event->error_handle->esp_tls_stack_err); + log_error_if_nonzero("captured as transport's socket errno", event->error_handle->esp_transport_sock_errno); + ESP_LOGI(TAG, "Last errno string (%s)", strerror(event->error_handle->esp_transport_sock_errno)); + + } break; default: ESP_LOGI(TAG, "Other event id:%d", event->event_id);