From 0e2678625f24ae7d84448ae8694614d50b4e5324 Mon Sep 17 00:00:00 2001 From: strawmanbobi Date: Wed, 22 Jan 2025 13:50:06 +0800 Subject: [PATCH] added debug information --- esp8285/lib/AliyunIoTSDK/src/AliyunIoTSDK.cpp | 3 ++- esp8285/src/aliot_client.cpp | 2 +- esp8285/src/iot_hub.cpp | 2 ++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/esp8285/lib/AliyunIoTSDK/src/AliyunIoTSDK.cpp b/esp8285/lib/AliyunIoTSDK/src/AliyunIoTSDK.cpp index c13742c..adb67f2 100644 --- a/esp8285/lib/AliyunIoTSDK/src/AliyunIoTSDK.cpp +++ b/esp8285/lib/AliyunIoTSDK/src/AliyunIoTSDK.cpp @@ -132,7 +132,7 @@ int AliyunIoTSDK::mqttCheckConnect() { connectRetry = 0; while (false == client->connected()) { client->disconnect(); - Serial.print("INFO: Connecting to MQTT Server, clientId = "); + Serial.print("INFO: Connecting to Aliyun MQTT Server, clientId = "); Serial.print(clientId); Serial.print(", mqttUserName = "); Serial.print(mqttUsername); @@ -145,6 +145,7 @@ int AliyunIoTSDK::mqttCheckConnect() { } else { Serial.print("ERROR: MQTT Connect err: "); Serial.println(client->state()); + client->disconnect(); delay(MQTT_WAIT_GENERIC); connectRetry++; Serial.print("INFO: Aliot connection retry: "); diff --git a/esp8285/src/aliot_client.cpp b/esp8285/src/aliot_client.cpp index 19080e9..19e7533 100644 --- a/esp8285/src/aliot_client.cpp +++ b/esp8285/src/aliot_client.cpp @@ -62,7 +62,7 @@ int connectToAliot(PubSubClient& mqtt_client) { if (0 == res && mqtt_client.connected()) { INFOF("Aliyun IoT connected\n"); } else { - ERRORF("Failed to connect to Aliyun IoT\n"); + ERRORF("Failed to connect to Aliyun IoT : %d\n", res); res = -1; } return res; diff --git a/esp8285/src/iot_hub.cpp b/esp8285/src/iot_hub.cpp index 93ed5a8..a80bd62 100644 --- a/esp8285/src/iot_hub.cpp +++ b/esp8285/src/iot_hub.cpp @@ -139,6 +139,8 @@ void keepAliveIot() { unsigned long current_time = millis(); if (current_time - last_check_time > 10000) { if (!g_mqtt_client.connected()) { + ERRORF("MQTT client is not connected, force disconnect and retry\n"); + g_mqtt_client.disconnect(); g_mqtt_client.unsubscribe(g_downstream_topic.c_str()); g_subscribed = false; connectIot();