Skip to content

Commit

Permalink
ESP32: enable platform mdns for ESP32-C2 (#25459)
Browse files Browse the repository at this point in the history
  • Loading branch information
wqx6 authored and pull[bot] committed Jun 24, 2023
1 parent 5f9dfdb commit d78f98c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
13 changes: 10 additions & 3 deletions config/esp32/components/chip/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ include(${CMAKE_CURRENT_LIST_DIR}/ota-image.cmake)

set(CHIP_REQUIRE_COMPONENTS freertos lwip bt mbedtls fatfs app_update console openthread nvs_flash spi_flash)

if((NOT "${IDF_TARGET}" STREQUAL "esp32h2") AND (NOT "${IDF_TARGET}" STREQUAL "esp32c2"))
if(NOT "${IDF_TARGET}" STREQUAL "esp32h2")
list(APPEND CHIP_REQUIRE_COMPONENTS mdns)
endif()

Expand Down Expand Up @@ -314,8 +314,15 @@ if(CONFIG_OPENTHREAD_ENABLED)
list(APPEND chip_libraries $<TARGET_FILE:${openthread_lib}>)
endif()

if((NOT CONFIG_USE_MINIMAL_MDNS) AND (NOT CONFIG_IDF_TARGET_ESP32H2) AND (NOT CONFIG_IDF_TARGET_ESP32C2))
idf_component_get_property(mdns_lib mdns COMPONENT_LIB)
if((NOT CONFIG_USE_MINIMAL_MDNS) AND (NOT CONFIG_IDF_TARGET_ESP32H2))
idf_build_get_property(build_components BUILD_COMPONENTS)
# For IDF v5.x, the mdns component was moved to idf_managed_components.
# We should use 'espressif__mdns' for 'idf_component_get_property'.
if("espressif__mdns" IN_LIST build_components)
idf_component_get_property(mdns_lib espressif__mdns COMPONENT_LIB)
elseif("mdns" IN_LIST build_components)
idf_component_get_property(mdns_lib mdns COMPONENT_LIB)
endif()
list(APPEND chip_libraries $<TARGET_FILE:${mdns_lib}>)
endif()

Expand Down
11 changes: 11 additions & 0 deletions src/platform/ESP32/DnssdImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ CHIP_ERROR ChipDnssdPublishService(const DnssdService * service, DnssdPublishCal
espError = mdns_service_txt_set(service->mType, GetProtocolString(service->mProtocol), items,
static_cast<uint8_t>(service->mTextEntrySize));
}
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
for (size_t i = 0; i < service->mSubTypeSize; i++)
{
mdns_service_subtype_add_for_host(service->mName, service->mType, GetProtocolString(service->mProtocol), service->mHostName,
service->mSubTypes[i]);
}
#endif
VerifyOrExit(espError == ESP_OK, error = CHIP_ERROR_INTERNAL);

exit:
Expand Down Expand Up @@ -432,7 +439,11 @@ void MdnsQueryDone(intptr_t context)
}
mdns_search_once_t * searchHandle = reinterpret_cast<mdns_search_once_t *>(context);
GenericContext * ctx = FindMdnsQuery(searchHandle);
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
if (mdns_query_async_get_results(searchHandle, kTimeoutMilli, &(ctx->mResult), NULL))
#else
if (mdns_query_async_get_results(searchHandle, kTimeoutMilli, &(ctx->mResult)))
#endif // ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
{
if (ctx->mContextType == ContextType::Browse)
{
Expand Down

0 comments on commit d78f98c

Please sign in to comment.