Add MQTT TLS Support for WIFI-Enabled Devices (#2410)

* Testing TLS MQTT Support

* Working TLS connections

* Testing TLS MQTT Support

* Working TLS connections

* Added protobuf support for mqtt.tls_enabled

* fix 'em up good

* don't commit this stuff, jeeez

* there i fixed it

---------

Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
Co-authored-by: Thomas Göttgens <tgoettgens@gmail.com>
This commit is contained in:
ghostop14
2023-04-04 09:14:47 -04:00
committed by GitHub
parent fc8d16bb08
commit 990d418dc8
2 changed files with 28 additions and 3 deletions

View File

@@ -192,6 +192,26 @@ void MQTT::reconnect()
mqttPassword = moduleConfig.mqtt.password;
}
#if HAS_WIFI && !defined(ARCH_PORTDUINO)
if (moduleConfig.mqtt.tls_enabled) {
// change default for encrypted to 8883
try {
serverPort = 8883;
wifiSecureClient.setInsecure();
pubSub.setClient(wifiSecureClient);
LOG_INFO("Using TLS-encrypted session\n");
} catch (const std::exception &e) {
LOG_ERROR("MQTT ERROR: %s\n", e.what());
}
} else {
LOG_INFO("Using non-TLS-encrypted session\n");
pubSub.setClient(mqttClient);
}
#else
pubSub.setClient(mqttClient);
#endif
String server = String(serverAddr);
int delimIndex = server.indexOf(':');
if (delimIndex > 0) {
@@ -528,4 +548,4 @@ std::string MQTT::downstreamPacketToJson(meshtastic_MeshPacket *mp)
delete value;
return jsonStr;
}
}