ESP32 IDF and AWS MQTT

yiondeivis
Posts: 1
Joined: Wed Mar 27, 2024 8:55 pm

ESP32 IDF and AWS MQTT

Postby yiondeivis » Wed Mar 27, 2024 9:11 pm

Hi!

I am trying to connect to the MQTT service of AWS IoT using the MQTT API of the ESP32 IDF, and I have the following code:

Code: Select all

char complete_uri[60];
    sprintf(complete_uri, "mqtts://%s:%d", url, port);

 
    const esp_mqtt_client_config_t mqtt_cfg = {
    
        .broker = {
            .address ={
                .uri = complete_uri
            },
            .verification.certificate = certificate,
        },
        .credentials = {
            .authentication ={
                .key = private_key
            },
            .client_id = client_id
        }
        
    };

    esp_mqtt_client_handle_t client = esp_mqtt_client_init(&mqtt_cfg);
    esp_mqtt_client_register_event(client, ESP_EVENT_ANY_ID, mqtt_event_handler, NULL);
    esp_err_t conn_validation = esp_mqtt_client_start(client);
In the event handler it receives an TCP_TRANSPORT_ERROR when using the structure of "mqtts://aws_endpoint:8883" there is any other thing I need to configure? or is any parameter not valid here? certificate and private_key are both given by the AWS IoT core certificates being the certificate .pem.crt and the key .pem.key.

Thanks in advance!

chegewara
Posts: 2364
Joined: Wed Jun 14, 2017 9:00 pm

Re: ESP32 IDF and AWS MQTT

Postby chegewara » Thu Mar 28, 2024 4:03 am

It may be broken, so, did you try to populate other values in this struct (instead of uri)?

Code: Select all

        struct address_t {
            const char *uri; /*!< Complete *MQTT* broker URI */
            const char *hostname; /*!< Hostname, to set ipv4 pass it as string) */
            esp_mqtt_transport_t transport; /*!< Selects transport*/
            const char *path;               /*!< Path in the URI*/
            uint32_t port;                  /*!< *MQTT* server port */
        } address;
       
Especially transport, as the error is suggesting it is not correct value. (MQTT_TRANSPORT_OVER_SSL)

Who is online

Users browsing this forum: moeen_sa and 111 guests