Skip to content

Latest commit

 

History

History
58 lines (39 loc) · 1.71 KB

tls.md

File metadata and controls

58 lines (39 loc) · 1.71 KB

plainhdr

Using TLS

TLS support is available for ESP32 targets only

Prerequisites

For a complete homogeneous environment with activated TLS, checkout the PlatformIO project H4Plugins_Env, which includes all H4 Libraries with appropriate version, and activates TLS further to the project.

Add certificates

in your project, add these lines under h4setup():

H4AsyncMQTT mqttClient;
std::string rootCA = R"(-----BEGIN CERTIFICATE-----
....
....
-----END CERTIFICATE-----
)";


void h4setup() {
    auto testRootCA = reinterpret_cast<const uint8_t*>(const_cast<char*>(rootCA.c_str()));
    mqttClient.secureTLS(testRootCA, rootCA.length() + 1); // +1 for PEM-based certificates (DER doesn't need it)
}

Ensure https:// part is explicitly added in the URL:

#define MQTT_SERVER "https://192.168.1.34:8883"

...
mqttClient.connect(MQTT_SERVER);

Find me daily in these FB groups

I am always grateful for any $upport on Patreon :)

(C) 2020 Phil Bowles