ESP32 HTTPS: Install SSL Certificate and Retrieve Data

Publicado em: 01 Abril 2024
no canal de: Coding With Brett
1,300
30

Here's how to connect an ESP32 to a website using SSL and download content using https. While trivial on other operating systems and programming environments, it's actually quite complicated to get working on the ESP32. After two frustrating days I managed to get it to work. In this example I'm using the WiFiClientSecure library and code sample. This is a wrapper on top of the widely used WifiClient library, so you should be able to get a wide variety of code samples working with SSL.

00:00 - Introduction
00:32 - Arduino IDE code
01:22 - Replace root certificate
05:10 - Testing the code

Code shown in video: https://github.com/nichelaboratory/ES...
How to generate the CA Certificate required for the Arduino IDE: https://janhendrikewers.uk/how_to-fin...
Open SSL download: https://wiki.openssl.org/index.php/Bi...

Open SSL usually installs to C:\Program Files\OpenSSL-Win64\bin

To generate the certificate open a CMD window, navigate to the OpenSSL's bin folder and type the following:

openssl s_client -showcerts -connect www.brettb.com:443

Obviously change the url to the site you want to connect to and change port 443 if you're using a non-standard HTTPS port. Also be very careful when copying and pasting the certificate as it needs to be in the code exactly as exported from OpenSSL.

If you know of a better way of doing this then do leave a comment. The ESP32 libraries are supposed to have CA root certificates in them but I've no idea how to use them.

Oh and if you're using Let's Encrypt or another certificate authority you might have to update the certificate in your code if the SSL certificate expires/gets renewed.

Incidentally I made a lot of changes to the sketch's code after I recorded this video. It turned out where char array buffers are instantiated in the sketch is extremely important due to the setup loop having a very small memory allocation. I also modified the WiFiClientSecure example because it wasn't working reliably when downloading larger chunks of data. This code now seems to work reliably for JSON downloads from rest API's.


Nesta página do site você pode assistir ao vídeo on-line ESP32 HTTPS: Install SSL Certificate and Retrieve Data duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário Coding With Brett 01 Abril 2024, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 1,300 vezes e gostou 30 espectadores. Boa visualização!