fixed aliot connection check interval issue

This commit is contained in:
strawmanbobi
2024-10-28 16:37:07 +08:00
parent fc29ac1494
commit 0b7fc586ef
3 changed files with 5 additions and 3 deletions

View File

@@ -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) {

View File

@@ -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");

View File

@@ -142,6 +142,7 @@ void keepAliveIot() {
g_mqtt_client.unsubscribe(g_downstream_topic.c_str());
g_subscribed = false;
connectIot();
last_check_time = current_time;
}
}
}