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;
|
static bool mqttConnecting = false;
|
||||||
|
|
||||||
int AliyunIoTSDK::mqttCheckConnect() {
|
int AliyunIoTSDK::mqttCheckConnect() {
|
||||||
int mqttStatus = 0;
|
int mqttStatus = 0;
|
||||||
int connectRetry = 0;
|
int connectRetry = 0;
|
||||||
@@ -146,11 +147,11 @@ int AliyunIoTSDK::mqttCheckConnect() {
|
|||||||
Serial.println(client->state());
|
Serial.println(client->state());
|
||||||
delay(MQTT_WAIT_GENERIC);
|
delay(MQTT_WAIT_GENERIC);
|
||||||
connectRetry++;
|
connectRetry++;
|
||||||
Serial.print("INFO:\tretry: ");
|
Serial.print("INFO:\tAliot connection retry: ");
|
||||||
Serial.println(connectRetry);
|
Serial.println(connectRetry);
|
||||||
mqttStatus = -1;
|
mqttStatus = -1;
|
||||||
if (connectRetry > MQTT_CONNECT_RETRY_MAX) {
|
if (connectRetry > MQTT_CONNECT_RETRY_MAX) {
|
||||||
Serial.println("ERROR:\t max connect retry times reached");
|
Serial.println("ERROR:\tMax connect retry times reached");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -204,7 +205,7 @@ int AliyunIoTSDK::begin(PubSubClient &mqtt_client,
|
|||||||
#if defined USE_STANDARD_THING_MODEL_TOPIC
|
#if defined USE_STANDARD_THING_MODEL_TOPIC
|
||||||
client.setCallback(callback);
|
client.setCallback(callback);
|
||||||
#endif
|
#endif
|
||||||
Serial.print("INFO\tconnection check in begin\n");
|
Serial.print("INFO\tConnection check in begin\n");
|
||||||
return mqttCheckConnect();
|
return mqttCheckConnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -55,13 +55,15 @@ static AliyunIoTSDK iot;
|
|||||||
|
|
||||||
// public function definitions
|
// public function definitions
|
||||||
int connectToAliot(PubSubClient& mqtt_client) {
|
int connectToAliot(PubSubClient& mqtt_client) {
|
||||||
String aliot_client_id = g_product_key + "." + g_device_name;
|
int res = 0;
|
||||||
|
String aliot_client_id;
|
||||||
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());
|
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()) {
|
if (0 == res && mqtt_client.connected()) {
|
||||||
INFOF("Aliyun IoT connected\n");
|
INFOF("Aliyun IoT connected\n");
|
||||||
} else {
|
} else {
|
||||||
ERRORF("Failed to connect to Aliyun IoT\n");
|
ERRORF("Failed to connect to Aliyun IoT\n");
|
||||||
|
res = -1;
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ int connectIot() {
|
|||||||
conn_ret = connectToAliot(g_mqtt_client);
|
conn_ret = connectToAliot(g_mqtt_client);
|
||||||
|
|
||||||
if (0 != conn_ret) {
|
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_server.c_str(), g_mqtt_port,
|
||||||
g_mqtt_client_id.c_str(), g_mqtt_user_name.c_str(), g_mqtt_password.length());
|
g_mqtt_client_id.c_str(), g_mqtt_user_name.c_str(), g_mqtt_password.length());
|
||||||
conn_ret = connectToEMQXBroker(g_mqtt_client);
|
conn_ret = connectToEMQXBroker(g_mqtt_client);
|
||||||
|
|||||||
Reference in New Issue
Block a user