Browse Source

mdns: set hostname early and run update()

Don't depend on the ArduinoOTA to do this.
Also fixes addService using nullptr as a name, since the hostname was never set.
pull/2439/head
Maxim Prokhorov 3 years ago
parent
commit
aeabbb389c
2 changed files with 31 additions and 20 deletions
  1. +27
    -15
      code/espurna/mdns.cpp
  2. +4
    -5
      code/espurna/ota_arduinoota.cpp

+ 27
- 15
code/espurna/mdns.cpp View File

@ -32,8 +32,12 @@ void _mdnsFindMQTT() {
#endif
String _mdnsHostname() {
return getSetting("hostname", getIdentifier());
}
void _mdnsServerStart() {
if (MDNS.begin(getSetting("hostname", getIdentifier()))) {
if (MDNS.begin(_mdnsHostname())) {
DEBUG_MSG_P(PSTR("[MDNS] OK\n"));
} else {
DEBUG_MSG_P(PSTR("[MDNS] FAIL\n"));
@ -45,6 +49,8 @@ void _mdnsServerStart() {
void mdnsServerSetup() {
bool done { false };
MDNS.setHostname(_mdnsHostname());
#if WEB_SUPPORT
{
MDNS.addService("http", "tcp", getSetting("webPort", static_cast<uint16_t>(WEB_PORT)));
@ -54,26 +60,28 @@ void mdnsServerSetup() {
#if TELNET_SUPPORT
{
MDNS.addService("telnet", "tcp", TELNET_PORT);
MDNS.addService("telnet", "tcp", static_cast<uint16_t>(TELNET_PORT));
done = true;
}
#endif
#if OTA_ARDUINOOTA_SUPPORT
{
MDNS.addServiceTxt("arduino", "tcp", "app_name", getAppName());
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<int>(ESP.getFlashChipRealSize() / 1024), 10));
MDNS.addServiceTxt("arduino", "tcp", "sdk_size",
String(static_cast<int>(ESP.getFlashChipSize() / 1024), 10));
MDNS.addServiceTxt("arduino", "tcp", "free_space",
String(static_cast<int>(ESP.getFreeSketchSpace() / 1024), 10));
done = true;
if (MDNS.enableArduino(OTA_PORT, getAdminPass().length() > 0)) {
MDNS.addServiceTxt("arduino", "tcp", "app_name", getAppName());
MDNS.addServiceTxt("arduino", "tcp", "app_version", getVersion());
MDNS.addServiceTxt("arduino", "tcp", "build_date", buildTime());
MDNS.addServiceTxt("arduino", "tcp", "mac", getFullChipId());
MDNS.addServiceTxt("arduino", "tcp", "target_board", getBoardName());
MDNS.addServiceTxt("arduino", "tcp", "mem_size",
String(static_cast<int>(ESP.getFlashChipRealSize() / 1024), 10));
MDNS.addServiceTxt("arduino", "tcp", "sdk_size",
String(static_cast<int>(ESP.getFlashChipSize() / 1024), 10));
MDNS.addServiceTxt("arduino", "tcp", "free_space",
String(static_cast<int>(ESP.getFreeSketchSpace() / 1024), 10));
done = true;
}
}
#endif
@ -81,6 +89,10 @@ void mdnsServerSetup() {
return;
}
espurnaRegisterLoop([]() {
MDNS.update();
});
// 2.7.x and older require MDNS.begin() when interface is UP
// 3.0.0 and newer only need to do MDNS.begin() once at setup()
// (XXX: this is techically a constexpr, but not in 2.7.4 :/)


+ 4
- 5
code/espurna/ota_arduinoota.cpp View File

@ -20,11 +20,10 @@ Copyright (C) 2016-2019 by Xose Pérez <xose dot perez at gmail dot com>
void _arduinoOtaConfigure() {
ArduinoOTA.setPort(OTA_PORT);
ArduinoOTA.setHostname(getSetting("hostname").c_str());
#if USE_PASSWORD
ArduinoOTA.setPassword(getAdminPass().c_str());
#endif
ArduinoOTA.begin();
#if USE_PASSWORD
ArduinoOTA.setPassword(getAdminPass().c_str());
#endif
ArduinoOTA.begin(false);
}


Loading…
Cancel
Save