mirror of
https://github.com/espressif/ESP8266_RTOS_SDK.git
synced 2025-05-19 16:19:07 +08:00
feat(mdns): Modify mdns component and example for RTOS
This commit is contained in:
@ -1,7 +1,18 @@
|
||||
idf_component_register(SRCS "mdns.c"
|
||||
"mdns_console.c"
|
||||
"mdns_networking.c"
|
||||
INCLUDE_DIRS "include"
|
||||
PRIV_INCLUDE_DIRS "private_include"
|
||||
REQUIRES lwip mbedtls console tcpip_adapter)
|
||||
if(CONFIG_ENABLE_MDNS)
|
||||
set(COMPONENT_SRCS "mdns.c"
|
||||
"mdns_networking.c")
|
||||
|
||||
set(COMPONENT_PRIV_INCLUDEDIRS "private_include")
|
||||
endif()
|
||||
|
||||
set(COMPONENT_ADD_INCLUDEDIRS "include")
|
||||
set(COMPONENT_REQUIRES "lwip" "mbedtls" "tcpip_adapter")
|
||||
|
||||
if(CONFIG_ENABLE_MDNS_CONSOLE)
|
||||
set(COMPONENT_SRCS "${COMPONENT_SRCS}"
|
||||
"mdns_console.c")
|
||||
endif()
|
||||
|
||||
set(COMPONENT_REQUIRES "console" "tcpip_adapter" "newlib")
|
||||
|
||||
register_component()
|
||||
|
@ -1,9 +1,25 @@
|
||||
menu "mDNS"
|
||||
|
||||
config ENABLE_MDNS
|
||||
bool "Enable mDNS"
|
||||
default n
|
||||
select LWIP_IPV6
|
||||
help
|
||||
Enable this option and then mDNS is to be used.
|
||||
|
||||
config ENABLE_MDNS_CONSOLE
|
||||
bool "Enable mDNS console"
|
||||
default n
|
||||
depends on ENABLE_MDNS
|
||||
select USING_ESP_CONSOLE
|
||||
help
|
||||
Enable this option and then mDNS console is to be used.
|
||||
|
||||
config MDNS_MAX_SERVICES
|
||||
int "Max number of services"
|
||||
range 1 64
|
||||
default 10
|
||||
depends on ENABLE_MDNS
|
||||
help
|
||||
Services take up a certain amount of memory, and allowing fewer
|
||||
services to be open at the same time conserves memory. Specify
|
||||
|
@ -1,2 +1,11 @@
|
||||
COMPONENT_ADD_INCLUDEDIRS := include
|
||||
COMPONENT_PRIV_INCLUDEDIRS := private_include
|
||||
|
||||
ifndef CONFIG_ENABLE_MDNS
|
||||
COMPONENT_OBJEXCLUDE += mdns.o
|
||||
COMPONENT_OBJEXCLUDE += mdns_networking.o
|
||||
endif
|
||||
|
||||
ifndef CONFIG_ENABLE_MDNS_CONSOLE
|
||||
COMPONENT_OBJEXCLUDE += mdns_console.o
|
||||
endif
|
||||
|
@ -3102,31 +3102,12 @@ static void _mdns_handle_system_event(esp_event_base_t event_base,
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else if (event_base == ETH_EVENT) {
|
||||
switch (event_id) {
|
||||
case ETHERNET_EVENT_CONNECTED:
|
||||
if (!tcpip_adapter_dhcpc_get_status(TCPIP_ADAPTER_IF_ETH, &dcst)) {
|
||||
if (dcst == TCPIP_ADAPTER_DHCP_STOPPED) {
|
||||
_mdns_enable_pcb(TCPIP_ADAPTER_IF_ETH, MDNS_IP_PROTOCOL_V4);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ETHERNET_EVENT_DISCONNECTED:
|
||||
_mdns_disable_pcb(TCPIP_ADAPTER_IF_ETH, MDNS_IP_PROTOCOL_V4);
|
||||
_mdns_disable_pcb(TCPIP_ADAPTER_IF_ETH, MDNS_IP_PROTOCOL_V6);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else if (event_base == IP_EVENT) {
|
||||
switch (event_id) {
|
||||
case IP_EVENT_STA_GOT_IP:
|
||||
_mdns_enable_pcb(TCPIP_ADAPTER_IF_STA, MDNS_IP_PROTOCOL_V4);
|
||||
_mdns_announce_pcb(TCPIP_ADAPTER_IF_STA, MDNS_IP_PROTOCOL_V6, NULL, 0, true);
|
||||
break;
|
||||
case IP_EVENT_ETH_GOT_IP:
|
||||
_mdns_enable_pcb(TCPIP_ADAPTER_IF_ETH, MDNS_IP_PROTOCOL_V4);
|
||||
break;
|
||||
case IP_EVENT_GOT_IP6:
|
||||
_mdns_enable_pcb(interface, MDNS_IP_PROTOCOL_V6);
|
||||
_mdns_announce_pcb(interface, MDNS_IP_PROTOCOL_V4, NULL, 0, true);
|
||||
@ -4200,9 +4181,6 @@ esp_err_t mdns_init()
|
||||
if ((err = esp_event_handler_register(IP_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL)) != ESP_OK) {
|
||||
goto free_event_handlers;
|
||||
}
|
||||
if ((err = esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL)) != ESP_OK) {
|
||||
goto free_event_handlers;
|
||||
}
|
||||
|
||||
uint8_t i;
|
||||
ip6_addr_t tmp_addr6;
|
||||
@ -4233,7 +4211,6 @@ free_all_and_disable_pcbs:
|
||||
free_event_handlers:
|
||||
esp_event_handler_unregister(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler);
|
||||
esp_event_handler_unregister(IP_EVENT, ESP_EVENT_ANY_ID, &event_handler);
|
||||
esp_event_handler_unregister(ETH_EVENT, ESP_EVENT_ANY_ID, &event_handler);
|
||||
vQueueDelete(_mdns_server->action_queue);
|
||||
free_lock:
|
||||
vSemaphoreDelete(_mdns_server->lock);
|
||||
@ -4252,7 +4229,6 @@ void mdns_free()
|
||||
|
||||
esp_event_handler_unregister(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler);
|
||||
esp_event_handler_unregister(IP_EVENT, ESP_EVENT_ANY_ID, &event_handler);
|
||||
esp_event_handler_unregister(ETH_EVENT, ESP_EVENT_ANY_ID, &event_handler);
|
||||
|
||||
mdns_service_remove_all(_mdns_server);
|
||||
_mdns_service_task_stop();
|
||||
|
@ -21,7 +21,6 @@
|
||||
#include "esp_system.h"
|
||||
#include "esp_timer.h"
|
||||
#include "esp_event.h"
|
||||
#include "esp_eth.h"
|
||||
|
||||
|
||||
/**
|
||||
|
@ -14,7 +14,11 @@
|
||||
#ifndef MDNS_PRIVATE_H_
|
||||
#define MDNS_PRIVATE_H_
|
||||
|
||||
#include "esp_event_base.h"
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "tcpip_adapter.h"
|
||||
#include "esp_timer.h"
|
||||
#include "mdns.h"
|
||||
|
||||
//#define MDNS_ENABLE_DEBUG
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
#include "esp_event.h"
|
||||
#include "esp_log.h"
|
||||
#include "nvs_flash.h"
|
||||
#include "tcpip_adapter.h"
|
||||
#include "esp_netif.h"
|
||||
#include "protocol_examples_common.h"
|
||||
#include "mdns.h"
|
||||
#include "driver/gpio.h"
|
||||
@ -137,8 +137,8 @@ static void query_mdns_host(const char * host_name)
|
||||
static void initialise_button(void)
|
||||
{
|
||||
gpio_config_t io_conf = {0};
|
||||
io_conf.intr_type = GPIO_PIN_INTR_DISABLE;
|
||||
io_conf.pin_bit_mask = BIT64(EXAMPLE_BUTTON_GPIO);
|
||||
io_conf.intr_type = GPIO_INTR_DISABLE;
|
||||
io_conf.pin_bit_mask = 1;
|
||||
io_conf.mode = GPIO_MODE_INPUT;
|
||||
io_conf.pull_up_en = 1;
|
||||
io_conf.pull_down_en = 0;
|
||||
@ -179,7 +179,7 @@ static void mdns_example_task(void *pvParameters)
|
||||
void app_main()
|
||||
{
|
||||
ESP_ERROR_CHECK(nvs_flash_init());
|
||||
tcpip_adapter_init();
|
||||
ESP_ERROR_CHECK(esp_netif_init());
|
||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
|
||||
initialise_mdns();
|
||||
|
@ -1,2 +1,3 @@
|
||||
CONFIG_MDNS_RESOLVE_TEST_SERVICES=y
|
||||
CONFIG_MDNS_ADD_MAC_TO_HOSTNAME=y
|
||||
CONFIG_ENABLE_MDNS=y
|
||||
|
1
examples/protocols/mdns/sdkconfig.defaults
Normal file
1
examples/protocols/mdns/sdkconfig.defaults
Normal file
@ -0,0 +1 @@
|
||||
CONFIG_ENABLE_MDNS=y
|
Reference in New Issue
Block a user