diff --git a/code/espurna/config/general.h b/code/espurna/config/general.h index a755f660..e6c77eba 100644 --- a/code/espurna/config/general.h +++ b/code/espurna/config/general.h @@ -334,6 +334,8 @@ PROGMEM const char* const custom_reset_string[] = { #define MQTT_SSL_FINGERPRINT "" #define MQTT_ENABLED 0 // Do not enable MQTT connection by default +#define MQTT_AUTOCONNECT 1 // If enabled and MDNS_SUPPORT=1 will perform an autodiscover and + // autoconnect to the first MQTT broker found if none defined #define MQTT_SERVER "" // Default MQTT broker address #define MQTT_PORT 1883 // MQTT broker port #define MQTT_TOPIC "/test/switch/{identifier}" // Default MQTT base topic @@ -342,7 +344,7 @@ PROGMEM const char* const custom_reset_string[] = { #define MQTT_KEEPALIVE 30 // MQTT keepalive value #define MQTT_RECONNECT_DELAY 10000 // Try to reconnect after 10s #define MQTT_TRY_INTERVAL 30000 // Timeframe for disconnect retries -#define MQTT_MAX_TRIES 10 // After these many retries during the previous MQTT_TRY_INTERVAL the board will reset +#define MQTT_MAX_TRIES 5 // After these many retries during the previous MQTT_TRY_INTERVAL the board will reset #define MQTT_SKIP_RETAINED 1 // Skip retained messages on connection #define MQTT_SKIP_TIME 1000 // Skip messages for 1 second anter connection diff --git a/code/espurna/mqtt.ino b/code/espurna/mqtt.ino index 37cb976a..da91b051 100644 --- a/code/espurna/mqtt.ino +++ b/code/espurna/mqtt.ino @@ -7,6 +7,7 @@ Copyright (C) 2016-2017 by Xose PĂ©rez */ #include +#include #include #include #include @@ -448,6 +449,27 @@ void mqttConfigure() { } +#ifdef MDNS_SUPPORT +boolean mqttDiscover() { + + int count = MDNS.queryService("mqtt", "tcp"); + DEBUG_MSG_P("[MQTT] MQTT brokers found: %d\n", count); + + for (int i=0; i