Merge branch 'pr1441' into dev
This commit is contained in:
commit
89b4b8ea85
@ -66,6 +66,8 @@ struct CONFIG_T {
|
||||
char WiFi_Hostname[WIFI_MAX_HOSTNAME_STRLEN + 1];
|
||||
uint32_t WiFi_ApTimeout;
|
||||
|
||||
bool Mdns_Enabled;
|
||||
|
||||
char Ntp_Server[NTP_MAX_SERVER_STRLEN + 1];
|
||||
char Ntp_Timezone[NTP_MAX_TIMEZONE_STRLEN + 1];
|
||||
char Ntp_TimezoneDescr[NTP_MAX_TIMEZONEDESCR_STRLEN + 1];
|
||||
|
||||
@ -59,6 +59,7 @@ public:
|
||||
private:
|
||||
void setHostname();
|
||||
void setStaticIp();
|
||||
void handleMDNS();
|
||||
void setupMode();
|
||||
void NetworkEvent(WiFiEvent_t event);
|
||||
bool adminEnabled = true;
|
||||
@ -76,6 +77,7 @@ private:
|
||||
network_mode _networkMode = network_mode::Undefined;
|
||||
bool _ethConnected = false;
|
||||
std::vector<NetworkEventCbList_t> _cbEventList;
|
||||
bool lastMdnsEnabled = false;
|
||||
};
|
||||
|
||||
extern NetworkSettingsClass NetworkSettings;
|
||||
@ -20,6 +20,8 @@
|
||||
#define WIFI_PASSWORD ""
|
||||
#define WIFI_DHCP true
|
||||
|
||||
#define MDNS_ENABLED false
|
||||
|
||||
#define NTP_SERVER "pool.ntp.org"
|
||||
#define NTP_TIMEZONE "CET-1CEST,M3.5.0,M10.5.0/3"
|
||||
#define NTP_TIMEZONEDESCR "Europe/Berlin"
|
||||
@ -96,4 +98,4 @@
|
||||
#define DISPLAY_CONTRAST 60U
|
||||
#define DISPLAY_LANGUAGE 0U
|
||||
|
||||
#define REACHABLE_THRESHOLD 2U
|
||||
#define REACHABLE_THRESHOLD 2U
|
||||
|
||||
@ -41,6 +41,9 @@ bool ConfigurationClass::write()
|
||||
wifi["hostname"] = config.WiFi_Hostname;
|
||||
wifi["aptimeout"] = config.WiFi_ApTimeout;
|
||||
|
||||
JsonObject mdns = doc.createNestedObject("mdns");
|
||||
mdns["enabled"] = config.Mdns_Enabled;
|
||||
|
||||
JsonObject ntp = doc.createNestedObject("ntp");
|
||||
ntp["server"] = config.Ntp_Server;
|
||||
ntp["timezone"] = config.Ntp_Timezone;
|
||||
@ -191,6 +194,9 @@ bool ConfigurationClass::read()
|
||||
config.WiFi_Dhcp = wifi["dhcp"] | WIFI_DHCP;
|
||||
config.WiFi_ApTimeout = wifi["aptimeout"] | ACCESS_POINT_TIMEOUT;
|
||||
|
||||
JsonObject mdns = doc["mdns"];
|
||||
config.Mdns_Enabled = mdns["enabled"] | MDNS_ENABLED;
|
||||
|
||||
JsonObject ntp = doc["ntp"];
|
||||
strlcpy(config.Ntp_Server, ntp["server"] | NTP_SERVER, sizeof(config.Ntp_Server));
|
||||
strlcpy(config.Ntp_Timezone, ntp["timezone"] | NTP_TIMEZONE, sizeof(config.Ntp_Timezone));
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
#include "PinMapping.h"
|
||||
#include "Utils.h"
|
||||
#include "defaults.h"
|
||||
#include <ESPmDNS.h>
|
||||
#include <ETH.h>
|
||||
|
||||
NetworkSettingsClass::NetworkSettingsClass()
|
||||
@ -110,6 +111,35 @@ void NetworkSettingsClass::raiseEvent(network_event event)
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkSettingsClass::handleMDNS()
|
||||
{
|
||||
bool mdnsEnabled = Configuration.get().Mdns_Enabled;
|
||||
|
||||
if (lastMdnsEnabled == mdnsEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
lastMdnsEnabled = mdnsEnabled;
|
||||
|
||||
MDNS.end();
|
||||
|
||||
if (!mdnsEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (MDNS.begin(getHostname())) {
|
||||
MessageOutput.print("MDNS responder starting...");
|
||||
|
||||
MDNS.addService("http", "tcp", 80);
|
||||
MDNS.addService("opendtu", "tcp", 80);
|
||||
MDNS.addServiceTxt("opendtu", "tcp", "git_hash", AUTO_GIT_HASH);
|
||||
|
||||
MessageOutput.println("done");
|
||||
} else {
|
||||
MessageOutput.println("Error setting up MDNS responder!");
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkSettingsClass::setupMode()
|
||||
{
|
||||
if (adminEnabled) {
|
||||
@ -218,6 +248,8 @@ void NetworkSettingsClass::loop()
|
||||
if (dnsServerStatus) {
|
||||
dnsServer->processNextRequest();
|
||||
}
|
||||
|
||||
handleMDNS();
|
||||
}
|
||||
|
||||
void NetworkSettingsClass::applyConfig()
|
||||
@ -417,4 +449,4 @@ network_mode NetworkSettingsClass::NetworkMode()
|
||||
return _networkMode;
|
||||
}
|
||||
|
||||
NetworkSettingsClass NetworkSettings;
|
||||
NetworkSettingsClass NetworkSettings;
|
||||
|
||||
@ -76,6 +76,7 @@ void WebApiNetworkClass::onNetworkAdminGet(AsyncWebServerRequest* request)
|
||||
root["ssid"] = config.WiFi_Ssid;
|
||||
root["password"] = config.WiFi_Password;
|
||||
root["aptimeout"] = config.WiFi_ApTimeout;
|
||||
root["mdnsenabled"] = config.Mdns_Enabled;
|
||||
|
||||
response->setLength();
|
||||
request->send(response);
|
||||
@ -236,6 +237,7 @@ void WebApiNetworkClass::onNetworkAdminPost(AsyncWebServerRequest* request)
|
||||
config.WiFi_Dhcp = false;
|
||||
}
|
||||
config.WiFi_ApTimeout = root["aptimeout"].as<uint>();
|
||||
config.Mdns_Enabled = root["mdnsenabled"].as<bool>();
|
||||
Configuration.write();
|
||||
|
||||
retMsg["type"] = "success";
|
||||
|
||||
@ -402,7 +402,9 @@
|
||||
"ApTimeout": "AccessPoint Zeitlimit:",
|
||||
"ApTimeoutHint": "Zeit die der AccessPoint offen gehalten wird. Ein Wert von 0 bedeutet unendlich.",
|
||||
"Minutes": "Minuten",
|
||||
"Save": "@:dtuadmin.Save"
|
||||
"Save": "@:dtuadmin.Save",
|
||||
"EnableMdns": "mDNS aktivieren",
|
||||
"MdnsSettings": "mDNS-Einstellungen"
|
||||
},
|
||||
"mqttadmin": {
|
||||
"MqttSettings": "MQTT-Einstellungen",
|
||||
|
||||
@ -402,7 +402,9 @@
|
||||
"ApTimeout": "AccessPoint Timeout:",
|
||||
"ApTimeoutHint": "Time which the AccessPoint is kept open. A value of 0 means infinite.",
|
||||
"Minutes": "minutes",
|
||||
"Save": "@:dtuadmin.Save"
|
||||
"Save": "@:dtuadmin.Save",
|
||||
"EnableMdns": "Enable mDNS",
|
||||
"MdnsSettings": "mDNS Settings"
|
||||
},
|
||||
"mqttadmin": {
|
||||
"MqttSettings": "MQTT Settings",
|
||||
|
||||
@ -402,7 +402,9 @@
|
||||
"ApTimeout": "Délai d'attente du point d'accès",
|
||||
"ApTimeoutHint": "Durée pendant laquelle le point d'accès reste ouvert. Une valeur de 0 signifie infini.",
|
||||
"Minutes": "minutes",
|
||||
"Save": "@:dtuadmin.Save"
|
||||
"Save": "@:dtuadmin.Save",
|
||||
"EnableMdns": "Activer mDNS",
|
||||
"MdnsSettings": "mDNS Settings"
|
||||
},
|
||||
"mqttadmin": {
|
||||
"MqttSettings": "Paramètres MQTT",
|
||||
@ -580,4 +582,4 @@
|
||||
"ValueSelected": "Sélectionné",
|
||||
"ValueActive": "Activé"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,4 +9,5 @@ export interface NetworkConfig {
|
||||
dns1: string;
|
||||
dns2: string;
|
||||
aptimeout: number;
|
||||
}
|
||||
mdnsenabled: boolean;
|
||||
}
|
||||
@ -50,6 +50,12 @@
|
||||
type="text" maxlength="32"/>
|
||||
</CardElement>
|
||||
|
||||
<CardElement :text="$t('networkadmin.MdnsSettings')" textVariant="text-bg-primary" add-space>
|
||||
<InputElement :label="$t('networkadmin.EnableMdns')"
|
||||
v-model="networkConfigList.mdnsenabled"
|
||||
type="checkbox"/>
|
||||
</CardElement>
|
||||
|
||||
<CardElement :text="$t('networkadmin.AdminAp')" textVariant="text-bg-primary" add-space>
|
||||
<InputElement :label="$t('networkadmin.ApTimeout')"
|
||||
v-model="networkConfigList.aptimeout"
|
||||
@ -67,7 +73,7 @@ import BasePage from '@/components/BasePage.vue';
|
||||
import BootstrapAlert from "@/components/BootstrapAlert.vue";
|
||||
import CardElement from '@/components/CardElement.vue';
|
||||
import InputElement from '@/components/InputElement.vue';
|
||||
import type { NetworkConfig } from "@/types/NetworkkConfig";
|
||||
import type { NetworkConfig } from "@/types/NetworkConfig";
|
||||
import { authHeader, handleResponse } from '@/utils/authentication';
|
||||
import { defineComponent } from 'vue';
|
||||
|
||||
@ -122,4 +128,4 @@ export default defineComponent({
|
||||
},
|
||||
},
|
||||
});
|
||||
</script>
|
||||
</script>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user