mDNS tweaks
This commit is contained in:
parent
e9e9ef68da
commit
af58eb1987
@ -30,6 +30,9 @@ build_flags =
|
||||
-std=c++2a
|
||||
# Enable UTF-8 long file names in SdFat
|
||||
-DUSE_UTF8_LONG_NAMES=1
|
||||
# mDNS service discovery for companion app network scanning
|
||||
-DMDNS_SERVICE_DISCOVERY=1
|
||||
-DMDNS_SERVICE_TXT_RECORDS=1
|
||||
|
||||
; Board configuration
|
||||
board_build.flash_mode = dio
|
||||
|
||||
@ -25,6 +25,32 @@ constexpr uint8_t AP_MAX_CONNECTIONS = 4;
|
||||
// DNS server for captive portal (redirects all DNS queries to our IP)
|
||||
DNSServer* dnsServer = nullptr;
|
||||
constexpr uint16_t DNS_PORT = 53;
|
||||
|
||||
// mDNS service discovery - advertises the device for network scanning
|
||||
// Controlled by build flags in platformio.ini:
|
||||
// MDNS_SERVICE_DISCOVERY - enables service advertisement (required for Android NSD)
|
||||
// MDNS_SERVICE_TXT_RECORDS - enables TXT record metadata (device type, ports)
|
||||
void setupMdnsServiceDiscovery(uint16_t httpPort, uint16_t wsPort) {
|
||||
#if MDNS_SERVICE_DISCOVERY
|
||||
// Advertise HTTP service for network discovery (required for Android NSD)
|
||||
MDNS.addService("http", "tcp", httpPort);
|
||||
Serial.printf("[%lu] [WEBACT] mDNS service advertised: _http._tcp port %d\n", millis(), httpPort);
|
||||
|
||||
#if MDNS_SERVICE_TXT_RECORDS
|
||||
// Add TXT records with device info for enhanced discovery
|
||||
MDNS.addServiceTxt("http", "tcp", "device", "crosspoint");
|
||||
MDNS.addServiceTxt("http", "tcp", "wsPort", String(wsPort).c_str());
|
||||
Serial.printf("[%lu] [WEBACT] mDNS TXT records added (device=crosspoint, wsPort=%d)\n", millis(), wsPort);
|
||||
#else
|
||||
(void)wsPort;
|
||||
#endif
|
||||
|
||||
#else
|
||||
(void)httpPort;
|
||||
(void)wsPort;
|
||||
Serial.printf("[%lu] [WEBACT] mDNS service discovery disabled\n", millis());
|
||||
#endif
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void CrossPointWebServerActivity::taskTrampoline(void* param) {
|
||||
@ -167,6 +193,7 @@ void CrossPointWebServerActivity::onWifiSelectionComplete(const bool connected)
|
||||
// Start mDNS for hostname resolution
|
||||
if (MDNS.begin(AP_HOSTNAME)) {
|
||||
Serial.printf("[%lu] [WEBACT] mDNS started: http://%s.local/\n", millis(), AP_HOSTNAME);
|
||||
setupMdnsServiceDiscovery(80, 81);
|
||||
}
|
||||
|
||||
// Start the web server
|
||||
@ -220,6 +247,7 @@ void CrossPointWebServerActivity::startAccessPoint() {
|
||||
// Start mDNS for hostname resolution
|
||||
if (MDNS.begin(AP_HOSTNAME)) {
|
||||
Serial.printf("[%lu] [WEBACT] mDNS started: http://%s.local/\n", millis(), AP_HOSTNAME);
|
||||
setupMdnsServiceDiscovery(80, 81);
|
||||
} else {
|
||||
Serial.printf("[%lu] [WEBACT] WARNING: mDNS failed to start\n", millis());
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user