fixed aliot connection check interval issue
This commit is contained in:
@@ -211,9 +211,10 @@ int AliyunIoTSDK::begin(PubSubClient &mqtt_client,
|
||||
int AliyunIoTSDK::loop() {
|
||||
int mqttStatus = 0;
|
||||
client->loop();
|
||||
if (millis() - lastMs >= CHECK_INTERVAL) {
|
||||
lastMs = millis();
|
||||
unsigned long thisMs = millis();
|
||||
if (thisMs - lastMs >= CHECK_INTERVAL) {
|
||||
mqttStatus = mqttCheckConnect();
|
||||
lastMs = thisMs;
|
||||
}
|
||||
|
||||
if (0 == mqttStatus) {
|
||||
|
||||
@@ -58,7 +58,7 @@ 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());
|
||||
if (0 == res) {
|
||||
if (0 == res && mqtt_client.connected()) {
|
||||
INFOF("Aliyun IoT connected\n");
|
||||
} else {
|
||||
ERRORF("Failed to connect to Aliyun IoT\n");
|
||||
|
||||
@@ -142,6 +142,7 @@ void keepAliveIot() {
|
||||
g_mqtt_client.unsubscribe(g_downstream_topic.c_str());
|
||||
g_subscribed = false;
|
||||
connectIot();
|
||||
last_check_time = current_time;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user