Remove mDNS resets

This commit is contained in:
Robert Strouse 2024-01-09 12:56:01 -08:00
parent 574b2ece04
commit edc4f103d2
7 changed files with 24 additions and 4 deletions

View file

@ -54,7 +54,10 @@ void Network::loop() {
this->emitSockets();
if(!this->connected()) return;
}
if(this->connected() && millis() - this->lastMDNS > 10000) {
if(this->connected() && millis() - this->lastMDNS > 60000) {
// We are doing this every 60 seconds because of the BS related to
// the MDNS library. The original library required manual updates
// to the MDNS or it would lose its hostname after 2 minutes.
if(this->lastMDNS != 0) MDNS.setInstanceName(settings.hostname);
this->lastMDNS = millis();
}
@ -260,6 +263,23 @@ bool Network::connectWired() {
if(this->connectAttempts > 10) this->wifiFallback = true;
return false;
}
void Network::updateHostname() {
if(settings.hostname[0] != '\0' && this->connected()) {
if(this->connType == conn_types::ethernet &&
strcmp(settings.hostname, ETH.getHostname()) != 0) {
Serial.printf("Updating host name to %s...\n", settings.hostname);
ETH.setHostname(settings.hostname);
MDNS.setInstanceName(settings.hostname);
SSDP.setName(0, settings.hostname);
}
else if(strcmp(settings.hostname, WiFi.getHostname()) != 0) {
Serial.printf("Updating host name to %s...\n", settings.hostname);
WiFi.setHostname(settings.hostname);
MDNS.setInstanceName(settings.hostname);
SSDP.setName(0, settings.hostname);
}
}
}
bool Network::connectWiFi() {
if(settings.WIFI.ssid[0] != '\0') {
if(WiFi.status() == WL_CONNECTED && WiFi.SSID().compareTo(settings.WIFI.ssid) == 0) {

View file

@ -29,6 +29,7 @@ class Network {
void setConnected(conn_types connType);
int getStrengthByMac(const char *mac);
int getStrengthBySSID(const char *ssid);
void updateHostname();
bool setup();
void loop();
void end();

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -2402,6 +2402,7 @@ void Web::begin() {
if (obj.containsKey("hostname") || obj.containsKey("ssdpBroadcast")) {
settings.fromJSON(obj);
settings.save();
net.updateHostname();
}
if (obj.containsKey("ntpServer") || obj.containsKey("ntpServer")) {
settings.NTP.fromJSON(obj);

View file

@ -631,12 +631,9 @@ div.wait-overlay > .lds-roller {
}
.somfyShadeCtl .shade-icon {
display: inline-block;
padding-top: 7px;
padding-bottom: 7px;
padding-left: 0px;
padding-right: 0px;
vertical-align: middle;
margin-top: -5px;
font-size: 48px;
position:relative;
}
@ -654,6 +651,7 @@ div.wait-overlay > .lds-roller {
}
.somfyGroupCtl .groupctl-shades {
font-size:12px;
margin-top:-3px;
}
.somfyGroupCtl .groupctl-name,
.somfyShadeCtl .shadectl-name {