/* MDNS MODULE Copyright (C) 2017-2019 by Xose PĂ©rez */ // ----------------------------------------------------------------------------- // mDNS Server // ----------------------------------------------------------------------------- #include "mdns.h" #include "mqtt.h" #include "utils.h" #if MDNS_SERVER_SUPPORT #include #if MQTT_SUPPORT void _mdnsFindMQTT() { int count = MDNS.queryService("mqtt", "tcp"); DEBUG_MSG_P(PSTR("[MQTT] MQTT brokers found: %d\n"), count); for (int i=0; i(WEB_PORT))); done = true; } #endif #if TELNET_SUPPORT { MDNS.addService("telnet", "tcp", TELNET_PORT); done = true; } #endif #if OTA_ARDUINOOTA_SUPPORT { MDNS.addServiceTxt("arduino", "tcp", "app_name", APP_NAME); MDNS.addServiceTxt("arduino", "tcp", "app_version", getVersion()); MDNS.addServiceTxt("arduino", "tcp", "build_date", buildTime()); MDNS.addServiceTxt("arduino", "tcp", "mac", WiFi.macAddress()); MDNS.addServiceTxt("arduino", "tcp", "target_board", getBoardName()); MDNS.addServiceTxt("arduino", "tcp", "mem_size", String(static_cast(ESP.getFlashChipRealSize() / 1024), 10)); MDNS.addServiceTxt("arduino", "tcp", "sdk_size", String(static_cast(ESP.getFlashChipSize() / 1024), 10)); MDNS.addServiceTxt("arduino", "tcp", "free_space", String(static_cast(ESP.getFreeSketchSpace() / 1024), 10)); done = true; } #endif if (!done) { return; } // 2.7.4 and older require MDNS.begin() when interface is UP // 3.0.0 and newer only need to do MDNS.begin() once at setup() // (TODO: this is techically a constexpr, but not in 2.7.4 :/) const static bool OldCore { esp8266::coreVersionNumeric() <= 20704000 }; wifiRegister([](wifi::Event event) { if (event == wifi::Event::StationConnected) { #if MQTT_SUPPORT _mdnsFindMQTT(); #endif } else if (OldCore && (event == wifi::Event::Mode)) { _mdnsServerStart(); } }); if (!OldCore) { _mdnsServerStart(); } } #endif // MDNS_SERVER_SUPPORT