mirror of
https://github.com/mfactory-osaka/ESPTimeCast.git
synced 2026-02-19 11:54:56 -05:00
Added mDNS support for easy access via http://esptimecast.local
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#include <sntp.h>
|
||||
#include <time.h>
|
||||
#include <WiFiClientSecure.h>
|
||||
#include <ESPmDNS.h>
|
||||
|
||||
#include "mfactoryfont.h" // Custom font
|
||||
#include "tz_lookup.h" // Timezone lookup, do not duplicate mapping here!
|
||||
@@ -19,7 +20,6 @@
|
||||
#include "months_lookup.h" // Languages for the Months of the Year
|
||||
#include "index_html.h" // Web UI
|
||||
|
||||
|
||||
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
|
||||
#define MAX_DEVICES 4
|
||||
#define CLK_PIN 7 //D5
|
||||
@@ -146,7 +146,7 @@ const unsigned long ntpStatusPrintInterval = 1000; // Print status every 1 seco
|
||||
// Non-blocking IP display globals
|
||||
bool showingIp = false;
|
||||
int ipDisplayCount = 0;
|
||||
const int ipDisplayMax = 2; // As per working copy for how long IP shows
|
||||
const int ipDisplayMax = 1; // As per working copy for how long IP shows
|
||||
String pendingIpToShow = "";
|
||||
|
||||
// Countdown display state - NEW
|
||||
@@ -520,6 +520,21 @@ void connectWiFi() {
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// mDNS
|
||||
// -----------------------------------------------------------------------------
|
||||
void setupMDNS() {
|
||||
const char *hostName = "esptimecast"; // your device name
|
||||
bool mdnsStarted = false;
|
||||
mdnsStarted = MDNS.begin(hostName);
|
||||
|
||||
if (mdnsStarted) {
|
||||
MDNS.addService("http", "tcp", 80);
|
||||
Serial.printf("mDNS started: http://%s.local\n", hostName);
|
||||
} else {
|
||||
Serial.println("mDNS failed to start");
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Time / NTP Functions
|
||||
@@ -2211,6 +2226,7 @@ void setup() {
|
||||
Serial.println(F("[SETUP] WiFi state is uncertain after connection attempt."));
|
||||
}
|
||||
|
||||
setupMDNS();
|
||||
setupWebServer();
|
||||
Serial.println(F("[SETUP] Webserver setup complete"));
|
||||
Serial.println(F("[SETUP] Setup complete"));
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <sntp.h>
|
||||
#include <time.h>
|
||||
#include <WiFiClientSecure.h>
|
||||
#include <ESP8266mDNS.h>
|
||||
|
||||
#include "mfactoryfont.h" // Custom font
|
||||
#include "tz_lookup.h" // Timezone lookup, do not duplicate mapping here!
|
||||
@@ -19,7 +20,6 @@
|
||||
#include "months_lookup.h" // Languages for the Months of the Year
|
||||
#include "index_html.h" // Web UI
|
||||
|
||||
|
||||
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
|
||||
#define MAX_DEVICES 4
|
||||
#define CLK_PIN 14 //D5
|
||||
@@ -92,7 +92,6 @@ int sunriseMinute = 0;
|
||||
int sunsetHour = 18;
|
||||
int sunsetMinute = 0;
|
||||
|
||||
|
||||
//Countdown Globals - NEW
|
||||
bool countdownEnabled = false;
|
||||
time_t countdownTargetTimestamp = 0; // Unix timestamp
|
||||
@@ -147,7 +146,7 @@ const unsigned long ntpStatusPrintInterval = 1000; // Print status every 1 seco
|
||||
// Non-blocking IP display globals
|
||||
bool showingIp = false;
|
||||
int ipDisplayCount = 0;
|
||||
const int ipDisplayMax = 2; // As per working copy for how long IP shows
|
||||
const int ipDisplayMax = 1; // As per working copy for how long IP shows
|
||||
String pendingIpToShow = "";
|
||||
|
||||
// Countdown display state - NEW
|
||||
@@ -517,6 +516,21 @@ void connectWiFi() {
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// mDNS
|
||||
// -----------------------------------------------------------------------------
|
||||
void setupMDNS() {
|
||||
const char *hostName = "esptimecast"; // your device name
|
||||
bool mdnsStarted = false;
|
||||
mdnsStarted = MDNS.begin(hostName);
|
||||
|
||||
if (mdnsStarted) {
|
||||
MDNS.addService("http", "tcp", 80);
|
||||
Serial.printf("mDNS started: http://%s.local\n", hostName);
|
||||
} else {
|
||||
Serial.println("mDNS failed to start");
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Time / NTP Functions
|
||||
@@ -2204,6 +2218,7 @@ void setup() {
|
||||
Serial.println(F("[SETUP] WiFi state is uncertain after connection attempt."));
|
||||
}
|
||||
|
||||
setupMDNS();
|
||||
setupWebServer();
|
||||
Serial.println(F("[SETUP] Webserver setup complete"));
|
||||
Serial.println(F("[SETUP] Setup complete"));
|
||||
@@ -2486,6 +2501,9 @@ void loop() {
|
||||
return;
|
||||
}
|
||||
|
||||
// mDNS update 8266 only
|
||||
MDNS.update();
|
||||
|
||||
|
||||
// -----------------------------
|
||||
// Dimming (auto + manual)
|
||||
|
||||
Reference in New Issue
Block a user