TLS support is available for ESP32 targets only
- H4AsyncTCP, follow its own instructions to activate TLS.
- H4 Library
- H4Tools
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.
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);
I am always grateful for any $upport on Patreon :)
(C) 2020 Phil Bowles