From 008d5998a1ffde8b78b8a9504360e75093c3ffdc Mon Sep 17 00:00:00 2001 From: Andrey Hinkov Date: Wed, 3 Feb 2021 12:28:33 +0200 Subject: [PATCH] add dhcp_hostname config for esp32 --- mos_esp32.yml | 1 + src/esp32/esp32_eth.c | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/mos_esp32.yml b/mos_esp32.yml index 0da8d8e..ab5abaa 100644 --- a/mos_esp32.yml +++ b/mos_esp32.yml @@ -9,6 +9,7 @@ cdefs: MGOS_ETH_PHY_DP83848: 0 config_schema: + - ["eth.dhcp_hostname", "s", {title: "Host name to include in DHCP requests"}] - ["eth.clk_mode", "i", 0, {title: "50 MHz clock source: 0 in <- GPIO0, 1 out -> GPIO0, 2 out -> GPIO16, 3 out -> GPIO17 (inverted)"}] - ["eth.mdc_gpio", "i", 23, {title: "GPIO to use for RMII MDC signal"}] - ["eth.mdio_gpio", "i", 18, {title: "GPIO to use for RMII MDIO signal"}] diff --git a/src/esp32/esp32_eth.c b/src/esp32/esp32_eth.c index 7ec748d..4385ef0 100644 --- a/src/esp32/esp32_eth.c +++ b/src/esp32/esp32_eth.c @@ -126,6 +126,14 @@ bool mgos_ethernet_init(void) { return false; } + if (mgos_sys_config_get_eth_dhcp_hostname() != NULL && + esp_netif_set_hostname(esp_netif_get_handle_from_ifkey("ETH_DEF"), + mgos_sys_config_get_eth_dhcp_hostname()) != + ESP_OK) { + LOG(LL_ERROR, ("ETH: Failed to set host name")); + goto out; + } + esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, esp32_eth_event_handler, eth_if); esp_event_handler_register(IP_EVENT, IP_EVENT_ETH_GOT_IP,