mirror of
https://github.com/meshtastic/firmware.git
synced 2025-06-09 14:42:05 +00:00
Consider the MQTT TLS remote IP when enabled. (#6058)
This commit is contained in:
parent
9b46cb4ef0
commit
c83ffd4911
@ -412,36 +412,28 @@ void MQTT::reconnect()
|
|||||||
const char *serverAddr = default_mqtt_address;
|
const char *serverAddr = default_mqtt_address;
|
||||||
const char *mqttUsername = default_mqtt_username;
|
const char *mqttUsername = default_mqtt_username;
|
||||||
const char *mqttPassword = default_mqtt_password;
|
const char *mqttPassword = default_mqtt_password;
|
||||||
|
MQTTClient *clientConnection = mqttClient.get();
|
||||||
|
|
||||||
if (*moduleConfig.mqtt.address) {
|
if (*moduleConfig.mqtt.address) {
|
||||||
serverAddr = moduleConfig.mqtt.address;
|
serverAddr = moduleConfig.mqtt.address;
|
||||||
mqttUsername = moduleConfig.mqtt.username;
|
mqttUsername = moduleConfig.mqtt.username;
|
||||||
mqttPassword = moduleConfig.mqtt.password;
|
mqttPassword = moduleConfig.mqtt.password;
|
||||||
}
|
}
|
||||||
#if HAS_WIFI && !defined(ARCH_PORTDUINO)
|
#if HAS_WIFI && !defined(ARCH_PORTDUINO) && !defined(CONFIG_IDF_TARGET_ESP32C6)
|
||||||
#if !defined(CONFIG_IDF_TARGET_ESP32C6)
|
|
||||||
if (moduleConfig.mqtt.tls_enabled) {
|
if (moduleConfig.mqtt.tls_enabled) {
|
||||||
// change default for encrypted to 8883
|
// change default for encrypted to 8883
|
||||||
try {
|
try {
|
||||||
serverPort = 8883;
|
serverPort = 8883;
|
||||||
wifiSecureClient.setInsecure();
|
wifiSecureClient.setInsecure();
|
||||||
|
|
||||||
pubSub.setClient(wifiSecureClient);
|
|
||||||
LOG_INFO("Use TLS-encrypted session");
|
LOG_INFO("Use TLS-encrypted session");
|
||||||
|
clientConnection = &wifiSecureClient;
|
||||||
} catch (const std::exception &e) {
|
} catch (const std::exception &e) {
|
||||||
LOG_ERROR("MQTT ERROR: %s", e.what());
|
LOG_ERROR("MQTT ERROR: %s", e.what());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LOG_INFO("Use non-TLS-encrypted session");
|
LOG_INFO("Use non-TLS-encrypted session");
|
||||||
pubSub.setClient(*mqttClient);
|
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
pubSub.setClient(*mqttClient);
|
|
||||||
#endif
|
#endif
|
||||||
#elif HAS_NETWORKING
|
|
||||||
pubSub.setClient(*mqttClient);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
std::pair<String, uint16_t> hostAndPort = parseHostAndPort(serverAddr, serverPort);
|
std::pair<String, uint16_t> hostAndPort = parseHostAndPort(serverAddr, serverPort);
|
||||||
serverAddr = hostAndPort.first.c_str();
|
serverAddr = hostAndPort.first.c_str();
|
||||||
serverPort = hostAndPort.second;
|
serverPort = hostAndPort.second;
|
||||||
@ -451,13 +443,14 @@ void MQTT::reconnect()
|
|||||||
LOG_INFO("Connect directly to MQTT server %s, port: %d, username: %s, password: %s", serverAddr, serverPort, mqttUsername,
|
LOG_INFO("Connect directly to MQTT server %s, port: %d, username: %s, password: %s", serverAddr, serverPort, mqttUsername,
|
||||||
mqttPassword);
|
mqttPassword);
|
||||||
|
|
||||||
|
pubSub.setClient(*clientConnection);
|
||||||
bool connected = pubSub.connect(owner.id, mqttUsername, mqttPassword);
|
bool connected = pubSub.connect(owner.id, mqttUsername, mqttPassword);
|
||||||
if (connected) {
|
if (connected) {
|
||||||
LOG_INFO("MQTT connected");
|
LOG_INFO("MQTT connected");
|
||||||
enabled = true; // Start running background process again
|
enabled = true; // Start running background process again
|
||||||
runASAP = true;
|
runASAP = true;
|
||||||
reconnectCount = 0;
|
reconnectCount = 0;
|
||||||
isMqttServerAddressPrivate = isPrivateIpAddress(mqttClient->remoteIP());
|
isMqttServerAddressPrivate = isPrivateIpAddress(clientConnection->remoteIP());
|
||||||
|
|
||||||
publishNodeInfo();
|
publishNodeInfo();
|
||||||
sendSubscriptions();
|
sendSubscriptions();
|
||||||
|
Loading…
Reference in New Issue
Block a user