Skip to content

Commit c23c786

Browse files
ESPmDNS: Add method for querying discovered service name (#10819)
* Add method for querying service name * Added implementation for getting service name * Update mDNS-SD_Extended example to include service name * ci(pre-commit): Apply automatic fixes --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
1 parent 51ef2a1 commit c23c786

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

libraries/ESPmDNS/examples/mDNS-SD_Extended/mDNS-SD_Extended.ino

+2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ void browseService(const char *service, const char *proto) {
6868
Serial.print(" ");
6969
Serial.print(i + 1);
7070
Serial.print(": ");
71+
Serial.print(MDNS.instanceName(i));
72+
Serial.print(" - ");
7173
Serial.print(MDNS.hostname(i));
7274
Serial.print(" (");
7375
Serial.print(MDNS.address(i));

libraries/ESPmDNS/src/ESPmDNS.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,15 @@ String MDNSResponder::hostname(int idx) {
299299
return String(result->hostname);
300300
}
301301

302+
String MDNSResponder::instanceName(int idx) {
303+
mdns_result_t *result = _getResult(idx);
304+
if (!result) {
305+
log_e("Result %d not found", idx);
306+
return String();
307+
}
308+
return String(result->instance_name);
309+
}
310+
302311
IPAddress MDNSResponder::address(int idx) {
303312
mdns_result_t *result = _getResult(idx);
304313
if (!result) {

libraries/ESPmDNS/src/ESPmDNS.h

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ class MDNSResponder {
110110
}
111111

112112
String hostname(int idx);
113+
String instanceName(int idx);
113114
IPAddress address(int idx);
114115
IPAddress addressV6(int idx);
115116
uint16_t port(int idx);

0 commit comments

Comments
 (0)