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

@@ -121,6 +121,16 @@ dependencies:
registry_url: https://components.espressif.com/ registry_url: https://components.espressif.com/
type: service type: service
version: 3.0.3 version: 3.0.3
espressif/mdns:
component_hash: 7c0fa01a1cd0e72a87ec1928c3b661c0a3a9034a6d3a69dcf4850db8c6f272db
dependencies:
- name: idf
require: private
version: '>=5.0'
source:
registry_url: https://components.espressif.com/
type: service
version: 1.10.1
idf: idf:
source: source:
type: idf type: idf
@@ -138,8 +148,9 @@ dependencies:
direct_dependencies: direct_dependencies:
- espressif/ethernet_init - espressif/ethernet_init
- espressif/led_strip - espressif/led_strip
- espressif/mdns
- idf - idf
- joltwallet/littlefs - joltwallet/littlefs
manifest_hash: 21816aafdbbde14bfaaaabda34966eec49ae1e6f551bc16fe3ff74370b0fb54c manifest_hash: 41e6c72fd10e152687d4a06741d6314e63ca2df7c6234cf03f4d27afda3d632a
target: esp32s3 target: esp32s3
version: 2.0.0 version: 2.0.0

View File

@@ -2,7 +2,7 @@ idf_component_register(SRCS "main.cpp"
# Needed as we use minimal build # Needed as we use minimal build
PRIV_REQUIRES esp_http_server esp_eth PRIV_REQUIRES esp_http_server esp_eth
esp_wifi nvs_flash esp_netif vfs esp_wifi nvs_flash esp_netif vfs
json app_update esp_timer esp_psram json app_update esp_timer esp_psram mdns
INCLUDE_DIRS ".") INCLUDE_DIRS ".")
if(CONFIG_CALENDINK_DEPLOY_WEB_PAGES) 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 If enabled, the LED will blink the last digit of the IP address
acquired to assist in debugging. 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 endmenu
menu "Calendink Web Server" menu "Calendink Web Server"

View File

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

View File

@@ -14,7 +14,6 @@
#include "sdkconfig.h" #include "sdkconfig.h"
#include "soc/gpio_num.h" #include "soc/gpio_num.h"
// Project headers // Project headers
#include "appstate.hpp" #include "appstate.hpp"
#include "types.hpp" #include "types.hpp"
@@ -24,6 +23,7 @@
#include "led_status.cpp" #include "led_status.cpp"
#include "connect.cpp" #include "connect.cpp"
#include "http_server.cpp" #include "http_server.cpp"
#include "mdns_service.cpp"
// clang-format on // clang-format on
// Global Application State Definitions // Global Application State Definitions
@@ -248,11 +248,14 @@ extern "C" void app_main()
printf("Will use Ethernet!\n"); printf("Will use Ethernet!\n");
} }
printf("Connected!\n"); printf("Connected! IP acquired.\n");
// Start the webserver // Start the webserver
web_server = start_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 // 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(); 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");
}