fixed emqx HA issue when aliyun connecting fails
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user