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

@@ -2,7 +2,7 @@ idf_component_register(SRCS "main.cpp"
# Needed as we use minimal build
PRIV_REQUIRES esp_http_server esp_eth
esp_wifi nvs_flash esp_netif vfs
json app_update esp_timer esp_psram
json app_update esp_timer esp_psram mdns
INCLUDE_DIRS ".")
if(CONFIG_CALENDINK_DEPLOY_WEB_PAGES)

View File

@@ -31,6 +31,13 @@ menu "CalendarInk Network Configuration"
If enabled, the LED will blink the last digit of the IP address
acquired to assist in debugging.
config CALENDINK_MDNS_HOSTNAME
string "mDNS Hostname"
default "calendink"
help
The hostname to use for mDNS. The device will be accessible
at <hostname>.local. (e.g., calendink.local)
endmenu
menu "Calendink Web Server"

View File

@@ -15,5 +15,6 @@ dependencies:
# # All dependencies of `main` are public by default.
# public: true
espressif/led_strip: ^3.0.3
espressif/mdns: ^1.4.1
espressif/ethernet_init: ^1.3.0
joltwallet/littlefs: "^1.20" # https://github.com/joltwallet/esp_littlefs

View File

@@ -14,7 +14,6 @@
#include "sdkconfig.h"
#include "soc/gpio_num.h"
// Project headers
#include "appstate.hpp"
#include "types.hpp"
@@ -24,6 +23,7 @@
#include "led_status.cpp"
#include "connect.cpp"
#include "http_server.cpp"
#include "mdns_service.cpp"
// clang-format on
// Global Application State Definitions
@@ -248,11 +248,14 @@ extern "C" void app_main()
printf("Will use Ethernet!\n");
}
printf("Connected!\n");
printf("Connected! IP acquired.\n");
// Start the webserver
web_server = start_webserver();
// Start mDNS
start_mdns();
// Mark the current app as valid to cancel rollback, only if it's an OTA app
{
const esp_partition_t *running = esp_ota_get_running_partition();

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");
}