Skip to content

Hi, I'm trying to implement a MQTT broker connection for my ESP32 #9392

Description

@lekshith

Board

ESP32-S3 DevkitC-1

Device Description

DevkitC-1

Hardware Configuration

it has MODBUS connection to fans and some LED connections.

Version

other

IDE Name

Visual Studio

Operating System

Windows 11

Flash frequency

40Mhz

PSRAM enabled

yes

Upload speed

115200

Description

I'm trying to make a simple MQTT broker connection to my project. Initially, I was getting the error as:
"esp-tls-mbedtls: No server verification option set in esp_tls_cfg_t structure. Check esp_tls API reference", for which I used CONFIG_ESP_TLS_INSECURE=y
CONFIG_ESP_TLS_SKIP_SERVER_CERT_VERIFY=y, in the menuconfig. Now I'm faced with the following error to establish a network connection.
E (363948) esp-tls-mbedtls: mbedtls_ssl_setup returned -0x7F00
E (363948) esp-tls: create_ssl_handle failed
E (363948) esp-tls: Failed to open new connection
E (363948) transport_base: Failed to open a new connection

Sketch

Below is the code bit for executing MQTT protocol:
void mqtt_api_init(void)
{
    /* Create message queue */
    mqtt_message_queue = xQueueCreate(MQTT_MESSAGE_QUEUE_SIZE, sizeof(mqtt_message_t));
    if (mqtt_message_queue == NULL)
    {
        ESP_LOGE(TAG, "Create message queue fail");
        return;
    }

    uint8_t mac_addr[6];
    ESP_ERROR_CHECK(esp_read_mac(mac_addr, ESP_MAC_WIFI_STA));
    sprintf(gateway_id, "%02X%02X%02X%02X%02X%02X", mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);

    const esp_mqtt_client_config_t mqtt_cfg = {
        .broker = {
            .address.uri = MQTT_BROKER_URI,
            .address.port = 1883,
        },
        // .credentials = {
        //     .username = MQTT_USERNAME,
        //     .client_id = gateway_id,
        //     .authentication = {
        //         .certificate = (const char *)client_cert_pem_start,
        //         .key = (const char *)client_key_pem_start,
        //         .password = MQTT_PASSWORD,
        //     },
        // },
        .session.disable_clean_session = false,
    };

    /* Start mqtt client */
    mqtt_client = esp_mqtt_client_init(&mqtt_cfg);
    ESP_LOGI(TAG, "MQTT client initialized");

    esp_mqtt_client_register_event(mqtt_client, ESP_EVENT_ANY_ID, mqtt_event_handler, NULL);
    esp_mqtt_client_start(mqtt_client);

    /* Creat mqtt handle message task */
    BaseType_t result = xTaskCreate(mqtt_handle_message_task, MQTT_TASK_NAME, MQTT_TASK_SIZE,
                                    NULL, MQTT_TASK_PRIORITY, &mqttTaskHandle);
    if (result != pdPASS)
    {
        ESP_LOGE(TAG, "Create mqtt task fail %d", result);
    }
    else
    {
        vTaskSuspend(mqttTaskHandle);
    }

    char topic_cmd[MQTT_TOPIC_MAX_LENGTH];
    sprintf(topic_cmd, MQTT_TOPIC_CMD, gateway_id);
    mqtt_register_callback(topic_cmd, mqtt_handle_message_default);
}

Debug Message

E (363948) esp-tls-mbedtls: mbedtls_ssl_setup returned -0x7F00
E (363948) esp-tls: create_ssl_handle failed
E (363948) esp-tls: Failed to open new connection
E (363948) transport_base: Failed to open a new connection

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions