how to test ESP32 SSL connection with a mqtt broker?

AngelAD91
Posts: 2
Joined: Fri Jul 03, 2020 5:57 pm

how to test ESP32 SSL connection with a mqtt broker?

Postby AngelAD91 » Wed Jul 06, 2022 1:20 pm

Hi,

I have been searching the internet for how to make a secure connection with a mqtt broker like mosquitto or aws IoT. It seems that for aws I would only need to download the three certificates needed and use them as my cert_pem, client_cert_pem and client_key_pem constants.

The questions are:

How do I get this certificates to use mosquitto or another free mqtt broker?
The mbed ssl and wss examples seem to only use the cert_pem certificate, can I just define the other two certificates client_cert_pem and client_key_pem and both mbed and wss examples would work?

Something like this would work in the app_main.c?

Code: Select all

static void mqtt_app_start(void)
{
    const esp_mqtt_client_config_t mqtt_cfg = {
        .uri = CONFIG_BROKER_URI,
        .cert_pem = (const char *)mqtt_cert_pem_start,
        .client_cert_pem = (const char *)mqtt_client_cert_pem_start,
        .client_key_pem = (const char *)mqtt_client_key_pem_start,
    };

    ESP_LOGI(TAG, "[APP] Free memory: %d bytes", esp_get_free_heap_size());
    esp_mqtt_client_handle_t client = esp_mqtt_client_init(&mqtt_cfg);
    /* The last argument may be used to pass data to the event handler, in this example mqtt_event_handler */
    esp_mqtt_client_register_event(client, ESP_EVENT_ANY_ID, mqtt_event_handler, NULL);
    esp_mqtt_client_start(client);
}
-Angel

vbshightime
Posts: 1
Joined: Tue Nov 08, 2022 9:18 am

Re: how to test ESP32 SSL connection with a mqtt broker?

Postby vbshightime » Tue Nov 08, 2022 9:41 am

Hi,
So for you MQTT connection you need to have a private certificates. You can create private self signed certificate using Open ssl. There are some here are some discussions http://www.steves-internet-guide.com/mosquitto-tls/. it might solve you problem.
But i will suggest to use an integrated solution i was mingling up with different mqtt brokers, timeseries databasses and dashboarding tool and all. It would take my most of the time.
But I found one solution which provide everything bundeled. and provide you a whole iot cloud infrastructure. kindly check the blog post

https://medium.com/@vbsmandi/one-click- ... 913008ee69

Cheers!

Who is online

Users browsing this forum: No registered users and 125 guests