aws / aws-iot-device-sdk-embedded-C

SDK for connecting to AWS IoT from a device using embedded C.
MIT License
978 stars 625 forks source link

AWS disconnects after every 15 minutes since reconnect. #1790

Closed Coffeeye closed 2 years ago

Coffeeye commented 2 years ago

Answer to similar problem didnt help with the issue. Originally posted by @asweeney99 in https://github.com/aws/aws-iot-device-sdk-embedded-C/issues/161#issuecomment-465559185

the problem that arises for me is deceptively similar to the one with which the previous speakers struggle... but the remedy for their problems did not work for me

I tried to change the payloadLen values ​​to different but it ended up the same every time. AWS loses the connection cyclically every 15 minutes after it is established.

Here is the console and errors I'm getting

Just error : https://photos.app.goo.gl/vNFTfFVZVfjoBfpw9 mbedtls debug print : https://photos.app.goo.gl/4LPXuBr2ddrJEq5M7

This is how I handle publish

static inline IoT_Error_t iot_publish_to_topic(const char *topic, char *payload) {

    IoT_Publish_Message_Params msg;
    msg.qos = QOS1;
    msg.payload = (void*)payload;
    msg.isRetained = 0;
    msg.payloadLen = strlen(payload) + 1;

    ESP_LOGD(TAG, "PUBLISH [%s]\r\n%s", topic, payload);

    return aws_iot_mqtt_publish(&(client), topic, strlen(topic), &msg);
}

This is init configuration

static IoT_Error_t aws_init_mqtt() {

    IoT_Error_t rc = FAILURE;
    IoT_Client_Init_Params mqttInitParams = iotClientInitParamsDefault;

    mqttInitParams.enableAutoReconnect = false;
    mqttInitParams.pHostURL = IOT_AWS_MQTT_HOST;
    mqttInitParams.port = IOT_AWS_MQTT_PORT;

    mqttInitParams.pRootCALocation = (const char*)embed_file_pem.start;
    if(!(mqttInitParams.pDeviceCertLocation = db_get_aws_cert_addr(DB_AWS_CERT_PEM_CRT))) {
        ESP_LOGE(TAG, "[%s LINE : %d : %s] %s", __func__, __LINE__, __FILE__, __NULL__);
    }
    if(!(mqttInitParams.pDevicePrivateKeyLocation = db_get_aws_cert_addr(DB_AWS_CERT_PRIV_PEM_KEY))) {
        ESP_LOGE(TAG, "[%s LINE : %d : %s] %s", __func__, __LINE__, __FILE__, __NULL__);
    }

    mqttInitParams.mqttCommandTimeout_ms = 20000;
    mqttInitParams.tlsHandshakeTimeout_ms = 5000;
    mqttInitParams.isSSLHostnameVerify = true;
    mqttInitParams.disconnectHandler = disconnectCallbackHandler;
    mqttInitParams.disconnectHandlerData = NULL;

    if((rc = aws_iot_mqtt_init(&client, &mqttInitParams)) != SUCCESS) {
        ESP_LOGE(TAG, "[%s LINE : %d : %s] %s", __func__, __LINE__, __FILE__, __CRIT__);
    }

    return rc;
}

static IoT_Error_t aws_connect_mqtt() {
    IoT_Error_t rc;
    IoT_Client_Connect_Params connectParams = iotClientConnectParamsDefault;

    connectParams.keepAliveIntervalInSec = 600;
    connectParams.isCleanSession = true;
    connectParams.MQTTVersion = MQTT_3_1_1;
    connectParams.pClientID = clientID;
    connectParams.clientIDLen = (uint16_t)strlen(clientID);
    connectParams.isWillMsgPresent = false;

    ESP_LOGI(TAG, "Connecting to AWS... %s", clientID);
    do {
        rc = aws_iot_mqtt_connect(&client, &connectParams);
        if(SUCCESS != rc) {
            ESP_LOGE(TAG, "Error(%d) connecting to %s:%d", rc, IOT_AWS_MQTT_HOST, IOT_AWS_MQTT_PORT);
            vTaskDelay(1000 / portTICK_RATE_MS);
        }
    } while(SUCCESS != rc);

    return rc;
}
aggarg commented 2 years ago

Which version of SDK are you using? Can you try with the latest version and see if you still face this issue?

Coffeeye commented 2 years ago

Which version of SDK are you using? Can you try with the latest version and see if you still face this issue?

Iam check'd out at d1417908

aggarg commented 2 years ago

Is there a reason for not using the latest version?

Coffeeye commented 2 years ago

Is there a reason for not using the latest version?

Just realised espressif framework using a fork of this project which is year behind with commits at their side. Do you think this might be an issue?


https://github.com/espressif/aws-iot-device-sdk-embedded-C/tree/d1417908038fed0cc68b753a43fca3ea82f97917

aggarg commented 2 years ago

Yes - the commit you mentioned is from a very old version and that is why I asked you to try out the latest version. Depending on what libraries you need, this can be a good starting point - https://github.com/FreeRTOS/Labs-Project-Espressif-Demos

aggarg commented 2 years ago

I am closing this issue. Feel free to re-open or create a new one if you still face any issue.