Skip to content

Commit

Permalink
Add mdnsreset handling
Browse files Browse the repository at this point in the history
  • Loading branch information
lbussy committed Nov 28, 2020
1 parent 91279e7 commit e342a3b
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 8 deletions.
82 changes: 79 additions & 3 deletions src/config.h
Expand Up @@ -44,6 +44,82 @@ SOFTWARE. */
//
//////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////
//
// Echo all serial output to telnet
//
#ifndef DOTELNET
#define DOTELNET true
#endif
//
#if DOTELNET == true
#ifndef TELNETPORT
#define TELNETPORT 23
#endif
#endif
//
//////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////
//
// Use SPIFFS Editor
//
#ifndef SPIFFSEDIT
#define SPIFFSEDIT
#endif
//
//////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////
//
// SPIFFS Editor Username
//
#ifndef SPIFFSEDITUSER
#define SPIFFSEDITUSER "admin"
#endif
//
//////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////
//
// SPIFFS Editor Username
//
#ifndef SPIFFSEDITPW
#define SPIFFSEDITPW "p@ssword"
#endif
//
//////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////
//
// Reset controller every 42 days
//
#ifndef ESPREPBOOT
#define ESPREBOOT (uint32_t)3628800000
#endif
//
//////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////
//
// Reset NTP every 24 hours
//
#ifndef NTPRESET
#define NTPRESET (uint32_t)86400000
#endif
//
//////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////
//
// Minumum Free Heap, triggers reset if below this value
//
#ifndef MINFREEHEAP
#define MINFREEHEAP 10000
#endif
//
//////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////
//
// Define API Key (identifies application to target)
Expand Down Expand Up @@ -271,7 +347,7 @@ SOFTWARE. */
// Poll Brew Bubbles server for available version (time in seconds)
//
#ifndef POLLSERVERVERSION
#define POLLSERVERVERSION 60
#define POLLSERVERVERSION 3600
#endif
//
//////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -310,8 +386,8 @@ SOFTWARE. */
//
// Port for local web services
//
#ifndef PORT
#define PORT 80
#ifndef HTTPPORT
#define HTTPPORT 80
#endif
//
//////////////////////////////////////////////////////////////////////////
Expand Down
36 changes: 33 additions & 3 deletions src/mdns.cpp
Expand Up @@ -31,13 +31,43 @@ void mdnssetup()
else
{
Log.notice(F("mDNS responder started for %s.local." CR), config.hostname);
if (!MDNS.addService("http", "tcp", PORT))
if (!MDNS.addService("http", "tcp", HTTPPORT))
{
Log.error(F("Failed to register mDNS service." CR));
Log.error(F("Failed to register Web mDNS service." CR));
}
else
{
Log.notice(F("HTTP registered via mDNS on port %i." CR), PORT);
Log.notice(F("HTTP registered via mDNS on port %i." CR), HTTPPORT);
}
if (!MDNS.addService(config.hostname, "tcp", HTTPPORT))
{
Log.error(F("Failed to register %s mDNS service." CR), API_KEY);
}
else
{
Log.notice(F("%s registered via mDNS on port %i." CR), API_KEY, HTTPPORT);
}
}
}

void mdnsreset()
{
MDNS.end();
if (!MDNS.begin(config.hostname))
{
Log.error(F("Error resetting MDNS responder."));
}
else
{
#ifdef ESP32
Log.notice(F("mDNS responder restarted, hostname: %s.local." CR), WiFi.getHostname());
#elif ESP8266
Log.notice(F("mDNS responder restarted, hostname: %s.local." CR), WiFi.hostname().c_str());
#endif
MDNS.addService("http", "tcp", HTTPPORT);
MDNS.addService(config.hostname, "tcp", HTTPPORT);
#if DOTELNET == true
MDNS.addService("telnet", "tcp", TELNETPORT);
#endif
}
}
1 change: 1 addition & 0 deletions src/mdns.h
Expand Up @@ -34,6 +34,7 @@ SOFTWARE. */
#include <ESP8266WiFi.h>

void mdnssetup();
void mdnsreset();

extern struct Config config;

Expand Down
4 changes: 2 additions & 2 deletions src/webserver.cpp
Expand Up @@ -22,7 +22,7 @@ SOFTWARE. */

#include "webserver.h"

AsyncWebServer server(PORT);
AsyncWebServer server(HTTPPORT);

void initWebServer()
{
Expand All @@ -42,7 +42,7 @@ void initWebServer()

server.begin();

Log.notice(F("Async HTTP server started on port %l." CR), PORT);
Log.notice(F("Async HTTP server started on port %l." CR), HTTPPORT);
Log.verbose(F("Open: http://%s.local to view controller application." CR), WiFi.hostname().c_str());
}

Expand Down

0 comments on commit e342a3b

Please sign in to comment.