diff --git a/Provider/dependencies.lock b/Provider/dependencies.lock index b89a4f1..8f290e6 100644 --- a/Provider/dependencies.lock +++ b/Provider/dependencies.lock @@ -121,6 +121,16 @@ dependencies: registry_url: https://components.espressif.com/ type: service 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: source: type: idf @@ -138,8 +148,9 @@ dependencies: direct_dependencies: - espressif/ethernet_init - espressif/led_strip +- espressif/mdns - idf - joltwallet/littlefs -manifest_hash: 21816aafdbbde14bfaaaabda34966eec49ae1e6f551bc16fe3ff74370b0fb54c +manifest_hash: 41e6c72fd10e152687d4a06741d6314e63ca2df7c6234cf03f4d27afda3d632a target: esp32s3 version: 2.0.0 diff --git a/Provider/main/CMakeLists.txt b/Provider/main/CMakeLists.txt index 9b3debf..c928c94 100644 --- a/Provider/main/CMakeLists.txt +++ b/Provider/main/CMakeLists.txt @@ -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) diff --git a/Provider/main/Kconfig.projbuild b/Provider/main/Kconfig.projbuild index 950cb20..31ecbc1 100644 --- a/Provider/main/Kconfig.projbuild +++ b/Provider/main/Kconfig.projbuild @@ -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 .local. (e.g., calendink.local) + endmenu menu "Calendink Web Server" diff --git a/Provider/main/idf_component.yml b/Provider/main/idf_component.yml index 597f55a..cdeaa3c 100644 --- a/Provider/main/idf_component.yml +++ b/Provider/main/idf_component.yml @@ -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 diff --git a/Provider/main/main.cpp b/Provider/main/main.cpp index 9e6658e..6076e76 100644 --- a/Provider/main/main.cpp +++ b/Provider/main/main.cpp @@ -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(); diff --git a/Provider/main/mdns_service.cpp b/Provider/main/mdns_service.cpp new file mode 100644 index 0000000..eeaf9f8 --- /dev/null +++ b/Provider/main/mdns_service.cpp @@ -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"); +}