Skip to content

Connect with mDNS server #1981

@kamilbystryk

Description

@kamilbystryk

I have Linux computer with Avahi, which works as MQTT broker and Web application. Mobile phone (iOS) and other computers (Windows, Linux) can connect with MQTT broker or web application using name.local address.
When I try to connect with MQTT broker or http using Arduino/ESP8266 I have no problem (both, using IP address or mDNS server name). When I try to use ESP32 I can connect via IP without any problem, but when I change address to DNS name (wg. name.local) I can't connect.
Also, demo resolving mDNS host can't find server:

#include <ESPmDNS.h>               
#include <WiFi.h>               



void setup() {
  WiFi.begin("**", "**");
  Serial.begin(115200);
  while ( !WiFi.isConnected() )
  {
    delay(100);
  }
  Serial.println( "Wifi connected" );

  //initialize mDNS service
  esp_err_t err = mdns_init();
  if (err)
  {
    Serial.println( "MDNS Init failed: %d\n" );
    Serial.println(err);
  }
    
  //esolve_mdns_host( hostName );
}

void loop() {
resolve_mdns_host("name.local");
}

void resolve_mdns_host(const char * host_name)
{
    Serial.print(  "Query: ");
    Serial.println( host_name);

    struct ip4_addr addr;
    addr.addr = 0;

    esp_err_t err = mdns_query_a(host_name, 2000,  &addr);
    if(err)
    {
      if(err == ESP_ERR_NOT_FOUND)
      {
        Serial.println(  "Host was not found!");
        return;
      }
      Serial.println(  "Query Failed");
      return;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: StaleIssue is stale stage (outdated/stuck)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions