From 96dbe3d50a81c4f6ec7c3caea2e222df8dbd55dc Mon Sep 17 00:00:00 2001 From: Eric Duminil <eric.duminil@gmail.com> Date: Sun, 13 Feb 2022 22:39:45 +0100 Subject: [PATCH] One pointer, two possible objects --- ampel-firmware/mqtt.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ampel-firmware/mqtt.cpp b/ampel-firmware/mqtt.cpp index e300baf..3f1ea47 100644 --- a/ampel-firmware/mqtt.cpp +++ b/ampel-firmware/mqtt.cpp @@ -24,9 +24,7 @@ namespace config { # include <WiFiClientSecure.h> #endif -//TODO: Find better way. Only one of both will be used -WiFiClientSecure secureClient; -WiFiClient espClient; +WiFiClient *espClient; PubSubClient mqttClient; @@ -46,11 +44,13 @@ namespace mqtt { if (config::mqtt_encryption) { // The sensor doesn't check the fingerprint of the MQTT broker, because otherwise this fingerprint should be updated // on the sensor every 3 months. The connection can still be encrypted, though: - secureClient.setInsecure(); // If not available for ESP32, please update Arduino IDE / PlatformIO - mqttClient.setClient(secureClient); + WiFiClientSecure *secureClient = new WiFiClientSecure(); + secureClient->setInsecure(); + espClient = secureClient; } else { - mqttClient.setClient(espClient); + espClient = new WiFiClient(); } + mqttClient.setClient(*espClient); mqttClient.setServer(config::mqtt_server, config::mqtt_port); -- GitLab