diff --git a/esp8285/lib/AliyunIoTSDK/src/AliyunIoTSDK.cpp b/esp8285/lib/AliyunIoTSDK/src/AliyunIoTSDK.cpp index 35e8f0a..2664e82 100644 --- a/esp8285/lib/AliyunIoTSDK/src/AliyunIoTSDK.cpp +++ b/esp8285/lib/AliyunIoTSDK/src/AliyunIoTSDK.cpp @@ -118,6 +118,7 @@ static void callback(char *topic, byte *payload, unsigned int length) { } static bool mqttConnecting = false; + int AliyunIoTSDK::mqttCheckConnect() { int mqttStatus = 0; int connectRetry = 0; @@ -146,11 +147,11 @@ int AliyunIoTSDK::mqttCheckConnect() { Serial.println(client->state()); delay(MQTT_WAIT_GENERIC); connectRetry++; - Serial.print("INFO:\tretry: "); + Serial.print("INFO:\tAliot connection retry: "); Serial.println(connectRetry); mqttStatus = -1; if (connectRetry > MQTT_CONNECT_RETRY_MAX) { - Serial.println("ERROR:\t max connect retry times reached"); + Serial.println("ERROR:\tMax connect retry times reached"); break; } } @@ -204,7 +205,7 @@ int AliyunIoTSDK::begin(PubSubClient &mqtt_client, #if defined USE_STANDARD_THING_MODEL_TOPIC client.setCallback(callback); #endif - Serial.print("INFO\tconnection check in begin\n"); + Serial.print("INFO\tConnection check in begin\n"); return mqttCheckConnect(); } diff --git a/esp8285/src/aliot_client.cpp b/esp8285/src/aliot_client.cpp index 821bc7f..19080e9 100644 --- a/esp8285/src/aliot_client.cpp +++ b/esp8285/src/aliot_client.cpp @@ -55,13 +55,15 @@ static AliyunIoTSDK iot; // public function definitions int connectToAliot(PubSubClient& mqtt_client) { - String aliot_client_id = g_product_key + "." + g_device_name; - - int res = iot.begin(mqtt_client, g_product_key.c_str(), g_device_name.c_str(), g_device_token.c_str(), g_aliot_region.c_str()); + int res = 0; + String aliot_client_id; + aliot_client_id = g_product_key + "." + g_device_name; + res = iot.begin(mqtt_client, g_product_key.c_str(), g_device_name.c_str(), g_device_token.c_str(), g_aliot_region.c_str()); if (0 == res && mqtt_client.connected()) { INFOF("Aliyun IoT connected\n"); } else { ERRORF("Failed to connect to Aliyun IoT\n"); + res = -1; } return res; } diff --git a/esp8285/src/iot_hub.cpp b/esp8285/src/iot_hub.cpp index f782507..93ed5a8 100644 --- a/esp8285/src/iot_hub.cpp +++ b/esp8285/src/iot_hub.cpp @@ -98,7 +98,7 @@ int connectIot() { conn_ret = connectToAliot(g_mqtt_client); if (0 != conn_ret) { - INFOF("Try connecting to IoT %s:%d, client_id = %s, user_name = %s, password.size = %d\n", + INFOF("Try connecting to EMQX %s:%d, client_id = %s, user_name = %s, password.size = %d\n", g_mqtt_server.c_str(), g_mqtt_port, g_mqtt_client_id.c_str(), g_mqtt_user_name.c_str(), g_mqtt_password.length()); conn_ret = connectToEMQXBroker(g_mqtt_client);