add option to switch mDNS off/on

This commit is contained in:
MichaelDvP
2022-05-04 14:14:17 +02:00
parent d344924a3c
commit e00da5a721
5 changed files with 33 additions and 12 deletions

View File

@@ -38,6 +38,7 @@
- Added Shower Alert trigger time and cold shot time [#436](https://github.com/emsesp/EMS-ESP32/issues/436) - Added Shower Alert trigger time and cold shot time [#436](https://github.com/emsesp/EMS-ESP32/issues/436)
- Improved Table layout in Web UI (searching, filtering, sorting, exporting to CSV) - Improved Table layout in Web UI (searching, filtering, sorting, exporting to CSV)
- API fetch individual attributes from an entity [#462](https://github.com/emsesp/EMS-ESP32/issues/462) - API fetch individual attributes from an entity [#462](https://github.com/emsesp/EMS-ESP32/issues/462)
- Option to disable mDNS
### Fixed ### Fixed

View File

@@ -56,7 +56,8 @@ const WiFiSettingsForm: FC = () => {
enableIPv6: false, enableIPv6: false,
bandwidth20: false, bandwidth20: false,
tx_power: 20, tx_power: 20,
nosleep: false nosleep: false,
enableMDNS: true
}); });
} }
setInitialized(true); setInitialized(true);
@@ -153,6 +154,11 @@ const WiFiSettingsForm: FC = () => {
label="Use Lower WiFi Bandwidth" label="Use Lower WiFi Bandwidth"
/> />
<BlockFormControlLabel
control={<Checkbox name="enableMDNS" checked={data.enableMDNS} onChange={updateFormValue} />}
label="Enable mDNS Service"
/>
<Typography sx={{ pt: 2 }} variant="h6" color="primary"> <Typography sx={{ pt: 2 }} variant="h6" color="primary">
General General
</Typography> </Typography>

View File

@@ -47,6 +47,7 @@ export interface NetworkSettings {
subnet_mask?: string; subnet_mask?: string;
dns_ip_1?: string; dns_ip_1?: string;
dns_ip_2?: string; dns_ip_2?: string;
enableMDNS: boolean;
} }
export interface WiFiNetworkList { export interface WiFiNetworkList {

View File

@@ -38,6 +38,7 @@ class NetworkSettings {
bool bandwidth20; bool bandwidth20;
int8_t tx_power; int8_t tx_power;
bool nosleep; bool nosleep;
bool enableMDNS;
// optional configuration for static IP address // optional configuration for static IP address
IPAddress localIP; IPAddress localIP;
@@ -56,6 +57,7 @@ class NetworkSettings {
root["bandwidth20"] = settings.bandwidth20; root["bandwidth20"] = settings.bandwidth20;
root["tx_power"] = settings.tx_power; root["tx_power"] = settings.tx_power;
root["nosleep"] = settings.nosleep; root["nosleep"] = settings.nosleep;
root["enableMDNS"] = settings.enableMDNS;
// extended settings // extended settings
JsonUtils::writeIP(root, "local_ip", settings.localIP); JsonUtils::writeIP(root, "local_ip", settings.localIP);
@@ -74,6 +76,7 @@ class NetworkSettings {
settings.bandwidth20 = root["bandwidth20"] | false; settings.bandwidth20 = root["bandwidth20"] | false;
settings.tx_power = root["tx_power"] | 20; settings.tx_power = root["tx_power"] | 20;
settings.nosleep = root["nosleep"] | false; settings.nosleep = root["nosleep"] | false;
settings.enableMDNS = root["enableMDNS"] | true;
// extended settings // extended settings
JsonUtils::readIP(root, "local_ip", settings.localIP); JsonUtils::readIP(root, "local_ip", settings.localIP);

View File

@@ -189,6 +189,8 @@ void WebStatusService::webStatusService(AsyncWebServerRequest * request) {
void WebStatusService::mDNS_start() const { void WebStatusService::mDNS_start() const {
#ifndef EMSESP_STANDALONE #ifndef EMSESP_STANDALONE
MDNS.end(); MDNS.end();
EMSESP::esp8266React.getNetworkSettingsService()->read([&](NetworkSettings & networkSettings) {
if (networkSettings.enableMDNS) {
if (!MDNS.begin(EMSESP::system_.hostname().c_str())) { if (!MDNS.begin(EMSESP::system_.hostname().c_str())) {
EMSESP::logger().warning(F("Failed to start mDNS responder service")); EMSESP::logger().warning(F("Failed to start mDNS responder service"));
return; return;
@@ -201,9 +203,17 @@ void WebStatusService::mDNS_start() const {
MDNS.addServiceTxt("http", "tcp", "version", EMSESP_APP_VERSION); MDNS.addServiceTxt("http", "tcp", "version", EMSESP_APP_VERSION);
MDNS.addServiceTxt("http", "tcp", "address", address_s.c_str()); MDNS.addServiceTxt("http", "tcp", "address", address_s.c_str());
#endif
EMSESP::logger().info(F("mDNS responder service started")); EMSESP::logger().info(F("mDNS responder service started"));
}
});
#else
EMSESP::esp8266React.getNetworkSettingsService()->read([&](NetworkSettings & networkSettings) {
if (networkSettings.enableMDNS) {
EMSESP::logger().info(F("mDNS responder service started"));
}
});
#endif
} }
} // namespace emsesp } // namespace emsesp