Skip to content

MDNS queryService can't print hostname and IP address. #7048

@zekageri

Description

@zekageri

Board

esp-wrover-kit

Device Description

ESP32

Hardware Configuration

ESP32

Version

latest master (checkout manually)

IDE Name

Platform IO

Operating System

Windows 10

Flash frequency

80Mhz

PSRAM enabled

yes

Upload speed

115200

Description

ESP prints garbage to serial monitor when looping trought found services with MDNS.

Sketch

void networkSystem::check_MDNS_Services(){
    int nrOfServices = MDNS.queryService("http", "tcp");
    if (nrOfServices == 0) {
        Serial.println("No services were found.");
        return;
    }
    Serial.printf("%d services were found.\n", nrOfServices);
    String serviceIP = "";
    for (int i = 0; i < nrOfServices; i=i+1) {
        serviceIP = MDNS.IP(i).toString();

        Serial.println("---------------");

        Serial.printf("Hostname: %s\n",MDNS.hostname(i));
        Serial.printf("IP address: %s\n",serviceIP);
        Serial.printf("Port: %d\n",MDNS.port(i));

        Serial.println("---------------");
    }
}

Debug Message

2 services were found.
---------------
Hostname: ���?
IP address: X��?
Port: 80
---------------
---------------
Hostname: ethernet-usb
IP address: 192.168.10.22
Port: 80
---------------

Other Steps to Reproduce

I'm using ETH_LAN8720 chip and not wifi.
MDNS service works for me, i can reach my webserver with .local/

The garbage which is printed is very likely an other ESP32 which has it's mdns service setup like this:

   if( MDNS.begin( fileSys.config.hostname ) ) {
        #if NETWORK_DEBUG_MODE
            Serial.println("MDNS responder started");
        #endif
        MDNS.addService("http", "tcp", 80);
        MDNS.addServiceTxt("http", "tcp", "hsh_service", "HsH");
        MDNS.addServiceTxt("http", "tcp", "hsh_service_prop2", "HsH");
        MDNS.addServiceTxt("HsH", "hshProto", "hsh_service_prop3", "HsH");
    }else{
        #if NETWORK_DEBUG_MODE
            Serial.println("MDNS responder failed");
        #endif
    }

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions