adding mdns so we dont rely on ip to connect

This commit is contained in:
2026-03-08 18:16:50 -04:00
parent c034999d20
commit 38201280ea
6 changed files with 61 additions and 4 deletions

View File

@@ -0,0 +1,35 @@
#include "esp_log.h"
#include "mdns.h"
#include "sdkconfig.h"
static const char *kLogMDNS = "MDNS";
void start_mdns()
{
printf("MDNS: start_mdns() called\n");
// Initialize mDNS
esp_err_t err = mdns_init();
if (err != ESP_OK)
{
ESP_LOGE(kLogMDNS, "mDNS Init failed: %d", err);
return;
}
// Set mDNS hostname (from Kconfig)
const char *hostname = CONFIG_CALENDINK_MDNS_HOSTNAME;
mdns_hostname_set(hostname);
ESP_LOGI(kLogMDNS, "mDNS Hostname set to: [%s.local]", hostname);
// Set mDNS instance name
mdns_instance_name_set("Calendink Provider");
// Add HTTP service
err = mdns_service_add(NULL, "_http", "_tcp", 80, NULL, 0);
if (err != ESP_OK)
{
ESP_LOGE(kLogMDNS, "mDNS Service add failed: %d", err);
}
printf("MDNS: Service initialized with hostname [%s.local]\n", hostname);
ESP_LOGI(kLogMDNS, "mDNS Service initialized");
}