Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions HeishaMon/HeishaMon.ino
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ static uint8_t cmdnrel = 0;
// mqtt
#ifdef TLS_SUPPORT
#include <WiFiClientSecure.h>
WiFiClientSecure mqtt_tls_client;
WiFiClientSecure *mqtt_tls_client = nullptr;
WiFiClient mqtt_wifi_client;
bool loadTlsCaFromFS(WiFiClientSecure &client);
bool loadTlsCaFromFS(WiFiClientSecure *client);
static bool last_tls_enabled = false;
static bool new_ca_stored = false;
static std::unique_ptr<char[]> persistent_ca_pem;
Expand Down Expand Up @@ -394,7 +394,7 @@ void check_wifi() {
#endif

#ifdef TLS_SUPPORT
bool loadTlsCaFromFS(WiFiClientSecure &client) {
bool loadTlsCaFromFS(WiFiClientSecure *client) {
if (!LittleFS.exists("/ca.pem")) {
log_message(_F("[TLS] /ca.pem not found"));
return false;
Expand All @@ -414,7 +414,7 @@ bool loadTlsCaFromFS(WiFiClientSecure &client) {
size_t n = certFile.readBytes(persistent_ca_pem.get(), certSize);
persistent_ca_pem[n] = '\0';
certFile.close();
client.setCACert(persistent_ca_pem.get());
client->setCACert(persistent_ca_pem.get());
log_message(_F("[TLS] CA loaded into client"));
return true;
}
Expand All @@ -437,7 +437,7 @@ void mqtt_reconnect()
if (heishamonSettings.mqtt_tls_enabled != last_tls_enabled) {
mqtt_client.disconnect();
if (last_tls_enabled) {
mqtt_tls_client.stop();
mqtt_tls_client->stop();
} else {
mqtt_wifi_client.stop();
if (!loadTlsCaFromFS(mqtt_tls_client)) {
Expand All @@ -455,7 +455,7 @@ void mqtt_reconnect()
new_ca_stored = false;
}
if (heishamonSettings.mqtt_tls_enabled) {
mqtt_client.setClient(mqtt_tls_client);
mqtt_client.setClient(*mqtt_tls_client);
} else {
mqtt_client.setClient(mqtt_wifi_client);
}
Expand Down Expand Up @@ -1585,10 +1585,13 @@ void setupMqtt() {
#ifdef TLS_SUPPORT
mqtt_client.setSocketTimeout(8); mqtt_client.setKeepAlive(30); //fast timeout, any slower than 10s will block the main loop too long (8s might be even safer to avoid reboots on bad wifi); short keepalive may lead to problems with TLS
if (heishamonSettings.mqtt_tls_enabled) {
if (mqtt_tls_client == nullptr) {
mqtt_tls_client = new WiFiClientSecure();
}
if (!loadTlsCaFromFS(mqtt_tls_client)) {
log_message(_F("[TLS] Proceeding without valid CA (expect failure)"));
}
mqtt_client.setClient(mqtt_tls_client);
mqtt_client.setClient(*mqtt_tls_client );
} else {
mqtt_client.setClient(mqtt_wifi_client);
}
Expand Down
2 changes: 1 addition & 1 deletion HeishaMon/version.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#define HEISHAMON_VERSION "4.0"
#define HEISHAMON_VERSION "Local build"
static const char* heishamon_version = HEISHAMON_VERSION;

Loading