|
2 | 2 | #include "esphome/core/defines.h"
|
3 | 3 | #include "esphome/core/application.h"
|
4 | 4 | #include "esphome/core/version.h"
|
| 5 | +#include "esphome/core/log.h" |
5 | 6 |
|
6 | 7 | #ifdef USE_WIFI
|
7 | 8 | #include "esphome/components/wifi/wifi_component.h"
|
@@ -38,40 +39,56 @@ bool network_is_connected() {
|
38 | 39 | return false;
|
39 | 40 | }
|
40 | 41 |
|
41 |
| -void network_setup_mdns() { |
42 |
| - MDNS.begin(App.get_name().c_str()); |
| 42 | +#ifdef ARDUINO_ARCH_ESP8266 |
| 43 | +bool mdns_setup; |
| 44 | +#endif |
| 45 | + |
| 46 | +#ifdef ARDUINO_ARCH_ESP8266 |
| 47 | +void network_setup_mdns(IPAddress address, int interface) { |
| 48 | + // Latest arduino framework breaks mDNS for AP interface |
| 49 | + // see https://github.com/esp8266/Arduino/issues/6114 |
| 50 | + if (interface == 1) |
| 51 | + return; |
| 52 | + MDNS.begin(App.get_name().c_str(), address); |
| 53 | + mdns_setup = true; |
| 54 | +#endif |
| 55 | +#ifdef ARDUINO_ARCH_ESP32 |
| 56 | + void network_setup_mdns() { |
| 57 | + MDNS.begin(App.get_name().c_str()); |
| 58 | +#endif |
43 | 59 | #ifdef USE_API
|
44 |
| - if (api::global_api_server != nullptr) { |
45 |
| - MDNS.addService("esphomelib", "tcp", api::global_api_server->get_port()); |
46 |
| - // DNS-SD (!=mDNS !) requires at least one TXT record for service discovery - let's add version |
47 |
| - MDNS.addServiceTxt("esphomelib", "tcp", "version", ESPHOME_VERSION); |
48 |
| - MDNS.addServiceTxt("esphomelib", "tcp", "address", network_get_address().c_str()); |
49 |
| - } else { |
| 60 | + if (api::global_api_server != nullptr) { |
| 61 | + MDNS.addService("esphomelib", "tcp", api::global_api_server->get_port()); |
| 62 | + // DNS-SD (!=mDNS !) requires at least one TXT record for service discovery - let's add version |
| 63 | + MDNS.addServiceTxt("esphomelib", "tcp", "version", ESPHOME_VERSION); |
| 64 | + MDNS.addServiceTxt("esphomelib", "tcp", "address", network_get_address().c_str()); |
| 65 | + } else { |
50 | 66 | #endif
|
51 |
| - // Publish "http" service if not using native API. |
52 |
| - // This is just to have *some* mDNS service so that .local resolution works |
53 |
| - MDNS.addService("http", "tcp", 80); |
54 |
| - MDNS.addServiceTxt("http", "tcp", "version", ESPHOME_VERSION); |
| 67 | + // Publish "http" service if not using native API. |
| 68 | + // This is just to have *some* mDNS service so that .local resolution works |
| 69 | + MDNS.addService("http", "tcp", 80); |
| 70 | + MDNS.addServiceTxt("http", "tcp", "version", ESPHOME_VERSION); |
55 | 71 | #ifdef USE_API
|
56 |
| - } |
| 72 | + } |
57 | 73 | #endif
|
58 |
| -} |
59 |
| -void network_tick_mdns() { |
| 74 | + } |
| 75 | + void network_tick_mdns() { |
60 | 76 | #ifdef ARDUINO_ARCH_ESP8266
|
61 |
| - MDNS.update(); |
| 77 | + if (mdns_setup) |
| 78 | + MDNS.update(); |
62 | 79 | #endif
|
63 |
| -} |
| 80 | + } |
64 | 81 |
|
65 |
| -std::string network_get_address() { |
| 82 | + std::string network_get_address() { |
66 | 83 | #ifdef USE_ETHERNET
|
67 |
| - if (ethernet::global_eth_component != nullptr) |
68 |
| - return ethernet::global_eth_component->get_use_address(); |
| 84 | + if (ethernet::global_eth_component != nullptr) |
| 85 | + return ethernet::global_eth_component->get_use_address(); |
69 | 86 | #endif
|
70 | 87 | #ifdef USE_WIFI
|
71 |
| - if (wifi::global_wifi_component != nullptr) |
72 |
| - return wifi::global_wifi_component->get_use_address(); |
| 88 | + if (wifi::global_wifi_component != nullptr) |
| 89 | + return wifi::global_wifi_component->get_use_address(); |
73 | 90 | #endif
|
74 |
| - return ""; |
75 |
| -} |
| 91 | + return ""; |
| 92 | + } |
76 | 93 |
|
77 | 94 | } // namespace esphome
|
0 commit comments