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