mirror of
https://github.com/arendst/Tasmota.git
synced 2025-08-01 23:17:43 +00:00
commit
12b3ac0e8d
@ -220,9 +220,19 @@ boolean MqttDiscoverServer(void)
|
|||||||
AddLog(LOG_LEVEL_INFO);
|
AddLog(LOG_LEVEL_INFO);
|
||||||
|
|
||||||
if (n > 0) {
|
if (n > 0) {
|
||||||
// Note: current strategy is to get the first MQTT service (even when many are found)
|
#ifdef MDNS_HOSTNAME
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
if (!strcmp(MDNS.hostname(i).c_str(), MDNS_HOSTNAME)) {
|
||||||
|
snprintf_P(Settings.mqtt_host, sizeof(Settings.mqtt_host), MDNS.IP(i).toString().c_str());
|
||||||
|
Settings.mqtt_port = MDNS.port(i);
|
||||||
|
break; // stop at the first matching record
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
// If the hostname isn't set, use the first record found.
|
||||||
snprintf_P(Settings.mqtt_host, sizeof(Settings.mqtt_host), MDNS.IP(0).toString().c_str());
|
snprintf_P(Settings.mqtt_host, sizeof(Settings.mqtt_host), MDNS.IP(0).toString().c_str());
|
||||||
Settings.mqtt_port = MDNS.port(0);
|
Settings.mqtt_port = MDNS.port(0);
|
||||||
|
#endif // MDNS_HOSTNAME
|
||||||
|
|
||||||
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_MDNS D_MQTT_SERVICE_FOUND " %s, " D_IP_ADDRESS " %s, " D_PORT " %d"),
|
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_MDNS D_MQTT_SERVICE_FOUND " %s, " D_IP_ADDRESS " %s, " D_PORT " %d"),
|
||||||
MDNS.hostname(0).c_str(), Settings.mqtt_host, Settings.mqtt_port);
|
MDNS.hostname(0).c_str(), Settings.mqtt_host, Settings.mqtt_port);
|
||||||
@ -513,13 +523,11 @@ void MqttReconnect(void)
|
|||||||
mqtt_retry_counter = Settings.mqtt_retry;
|
mqtt_retry_counter = Settings.mqtt_retry;
|
||||||
global_state.mqtt_down = 1;
|
global_state.mqtt_down = 1;
|
||||||
|
|
||||||
#ifndef USE_MQTT_TLS
|
|
||||||
#ifdef USE_DISCOVERY
|
#ifdef USE_DISCOVERY
|
||||||
#ifdef MQTT_HOST_DISCOVERY
|
#ifdef MQTT_HOST_DISCOVERY
|
||||||
if (!strlen(Settings.mqtt_host) && !MqttDiscoverServer()) { return; }
|
if (!MqttDiscoverServer() && !strlen(Settings.mqtt_host)) { return; }
|
||||||
#endif // MQTT_HOST_DISCOVERY
|
#endif // MQTT_HOST_DISCOVERY
|
||||||
#endif // USE_DISCOVERY
|
#endif // USE_DISCOVERY
|
||||||
#endif // USE_MQTT_TLS
|
|
||||||
|
|
||||||
char *mqtt_user = NULL;
|
char *mqtt_user = NULL;
|
||||||
char *mqtt_pwd = NULL;
|
char *mqtt_pwd = NULL;
|
||||||
@ -585,13 +593,11 @@ void MqttCheck(void)
|
|||||||
if (!MqttIsConnected()) {
|
if (!MqttIsConnected()) {
|
||||||
global_state.mqtt_down = 1;
|
global_state.mqtt_down = 1;
|
||||||
if (!mqtt_retry_counter) {
|
if (!mqtt_retry_counter) {
|
||||||
#ifndef USE_MQTT_TLS
|
|
||||||
#ifdef USE_DISCOVERY
|
#ifdef USE_DISCOVERY
|
||||||
#ifdef MQTT_HOST_DISCOVERY
|
#ifdef MQTT_HOST_DISCOVERY
|
||||||
if (!strlen(Settings.mqtt_host) && !mdns_begun) { return; }
|
if (!strlen(Settings.mqtt_host) && !mdns_begun) { return; }
|
||||||
#endif // MQTT_HOST_DISCOVERY
|
#endif // MQTT_HOST_DISCOVERY
|
||||||
#endif // USE_DISCOVERY
|
#endif // USE_DISCOVERY
|
||||||
#endif // USE_MQTT_TLS
|
|
||||||
MqttReconnect();
|
MqttReconnect();
|
||||||
} else {
|
} else {
|
||||||
mqtt_retry_counter--;
|
mqtt_retry_counter--;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user