ESP32 - TLS - MQTT - ESPIDF

scg9813333123
Posts: 1
Joined: Thu May 16, 2024 12:34 pm

ESP32 - TLS - MQTT - ESPIDF

Postby scg9813333123 » Thu May 16, 2024 12:41 pm

Hey guys...
I am using ESP32 S2 and I am trying to connect to an MQTT broker which runs in my local inside a Docker in the port 8883 in TLS i can able to connect the ESP with the broker when the broker is modified to run in the 1883 but when it comes to TLS it is giving me some issues .

getting the error :
E (84613) esp-tls-mbedtls: mbedtls_x509_crt_parse of CA cert returned -0x2180
E (84613) esp-tls-mbedtls: Failed to set client configurations, returned [0x8015] (ESP_ERR_MBEDTLS_X509_CRT_PARSE_FAILED)
E (84623) esp-tls: create_ssl_handle failed
E (84623) esp-tls: Failed to open new connection
E (84633) transport_base: Failed to open a new connection
E (84643) mqtt_client: Error transport connect

I am wondering how to fix this error
The cert files are uploaded most of the formats and still i couldn't run it properly
but when i try it with the MQTT explorer as a client even in different devices with the same CA it is working properly

the mosquitto cnf i am using is
const esp_mqtt_client_config_t mqtt_cfg = {
.broker = {
.address = {
.uri = brokerAddress //"mqtts://192.168.1XX.XX:8883",
//.port = mqttPort,

},
.verification = {
.certificate = ca_cert_file,
.certificate_len = strlen(ca_cert_file),
.skip_cert_common_name_check = false, // Change to true if needed
.common_name = NULL
//.common_name = "MyCA"
},
},
.credentials = {
.username = "yyyyy", // Set your MQTT broker username
.client_id = "client_1001001",
.authentication = {
.password = "XXXXX",
}
}




and my mosquitto cnf file is
# listener for MQTT

listener 8883

# MQTT over TLS

cafile /mosquitto/config/ca.crt

certfile /mosquitto/config/server.crt

keyfile /mosquitto/config/server.key

require_certificate false

#use_identity_as_username true

# Use basic authentication with the password file

allow_anonymous false

password_file /mosquitto/config/mosquitto_passwd

# Log settings

#log_dest file /mosquitto/log/mosquitto.log

log_type all

log_timestamp true

log_timestamp_format %Y-%m-%d %H:%M:%S

# Persistence settings

persistence true

persistence_location /mosquitto/data/

# Other settings

autosave_interval 1800

# Enable protocol version 3.1.1

protocol mqtt

Who is online

Users browsing this forum: No registered users and 94 guests