Rebuild the platform espressif32 with DTLS for Arduino framework


I’m implementing a project using Arduino. The project is based on encrypted UDP communication (DTLS). By default, DTLS functionality is not available in Arduino. My question is how to proceed step by step to rebuild the framework with this functionality and then compile my project with this new available functionality?

best regards

Configuration options for mbedtls are put in the file esp_config.h. You can either directly enable the mbedtls macros or their surrounding config macros.

So the first thing to try would be to add build_flags = -D CONFIG_MBEDTLS_SSL_PROTO_DTLS to the platformio.ini and see if you can compile a firmware which uses DTLS functions. E.g., activating that CONFIG_ macro should make the function mbedtls_ssl_conf_dtls_anti_replay() available so a simple code like

#include <mbedtls/ssl.h>

void app_main() {
   mbedtls_ssl_conf_dtls_anti_replay(NULL, MBEDTLS_SSL_ANTI_REPLAY_ENABLED);

should be able to sanity-test it; there should be no undefined reference errors if this works.

Be carefull to delete any CONFIG_MBEDTLS_SSL_PROTO_DTLS references from your sdkconfig.h file if you do this, as this seems to duplicated there otherwise (arduino-esp32/sdkconfig at 5f1dff7dad965581b98ae4dc3fdfe21e3b552072 · espressif/arduino-esp32 · GitHub)

1 Like

Ok, I checked it out.
At first the compilation indicated an error: no reference to the indicated method.
Only after rebulid using ESP-IDF tools did the error disappear and the project began to compile.

However, another problem arose after calling the method: mbedtls_ssl_handshake
debug indicates this method’s error (-28928) and interception of communication from mbedtls_ssl_send_t indicates that even Client Hello was not generated.

Ok what exactly did you execute to rebuild it “using ESP-IDF tools”?

This is -0x7100 and indicates bad input data.

What is exactly the test firmware and against which server are you talking about? Note that the CONFIG_MBEDTLS_SSL_PROTO_DTLS will generate a ClientHello which wants a HelloVerifyRequest. If your server sends something else you get that error.

If you do not want that then you musn’t use the CONFIG_ macro but instead the direct collection of mbedtls macros, e.g.



1 Like

Uh, I may be mistaken, but as far as I understand, ESP-IDF framework is precompiled in Arduino framework. To recompile ESP-IDF with new settings, you need to use Arduino as ESP-IDF component. More info can be found in this issue.

The relevant lines in your platformio.ini should read:

platform =
framework = arduino, espidf

I was able to solve the problem, thank you all for your helpful advice.