Skip to content

feat(mdns): post event when hostname changes - #1127

Merged
david-cermak merged 3 commits into
espressif:masterfrom
zwx1995esp:feat/add_event_for_hostname_changed
Aug 26, 2026
Merged

feat(mdns): post event when hostname changes#1127
david-cermak merged 3 commits into
espressif:masterfrom
zwx1995esp:feat/add_event_for_hostname_changed

Conversation

@zwx1995esp

@zwx1995esp zwx1995esp commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Add the public mdns_hostname_changed_cb_t callback type and mdns_register_hostname_changed_callback() API.
  • Notify registered callbacks after the hostname changes, including automatic hostname conflict resolution.
  • Support multiple callback registrations and ignore duplicate (cb, arg) registrations.
  • Keep hostname-change notification independent of the system event loop; callbacks receive the new hostname directly and must not call mDNS APIs.

Tests

  • Add Linux host-unit coverage for callback registration, initial hostname assignment, unchanged hostname, and subsequent hostname changes.
  • Add ESP target unit coverage for invalid registration arguments and hostname-change notification behavior.

Validation

  • Linux host-unit test_receiver: 4 tests passed, including test_hostname_changed_callback.
  • Built and flashed the M5Stack Thread Border Router example with the local mDNS component. The example now uses the callback API, and hostname updates were confirmed on the connected boards.

@zwx1995esp
zwx1995esp force-pushed the feat/add_event_for_hostname_changed branch from bc8d91b to 1461446 Compare August 12, 2026 11:56
Comment thread components/mdns/mdns_responder.c Outdated
@zwx1995esp
zwx1995esp force-pushed the feat/add_event_for_hostname_changed branch from 1461446 to 6643e90 Compare August 18, 2026 04:15
Comment thread components/mdns/mdns_responder.c Outdated

@david-cermak david-cermak left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM overall, the only thing is posting to the system/defautl event_post

Let's rework it for now to callbacks, something like this:

typedef void (*mdns_hostname_changed_cb_t)(const char *hostname, void *arg);
esp_err_t mdns_register_hostname_changed_callback(mdns_hostname_changed_cb_t cb, void *arg);

since this method is widely used alrady in the mdns component.

I'll think about the event loop usage and will probably create a private event loop that could be used instead of callbacks. BUt will do that in the next release

@david-cermak

Copy link
Copy Markdown
Collaborator

@zwx1995esp Also please rebase and resolve conflicts

@zwx1995esp

zwx1995esp commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator Author

LGTM overall, the only thing is posting to the system/defautl event_post

Let's rework it for now to callbacks, something like this:

typedef void (*mdns_hostname_changed_cb_t)(const char *hostname, void *arg);
esp_err_t mdns_register_hostname_changed_callback(mdns_hostname_changed_cb_t cb, void *arg);

Hi @david-cermak Thanks for your reviewing. I’ll refactor the related logic and rewrite the test cases. Once everything is ready, I’ll push the updated changes and let you know.

@zwx1995esp
zwx1995esp force-pushed the feat/add_event_for_hostname_changed branch from 6643e90 to 6045268 Compare August 25, 2026 13:24
@zwx1995esp

Copy link
Copy Markdown
Collaborator Author

@david-cermak Refactor done, PTAL.

@david-cermak david-cermak left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM otherwise

Comment thread components/mdns/mdns_responder.c
Comment thread components/mdns/include/mdns.h Outdated
@zwx1995esp
zwx1995esp force-pushed the feat/add_event_for_hostname_changed branch from 6045268 to 4c8b76d Compare August 26, 2026 03:15
@david-cermak david-cermak self-assigned this Aug 26, 2026
@david-cermak
david-cermak merged commit 28286d2 into espressif:master Aug 26, 2026
180 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants