Skip to content

mDNS Failure Outside loop() #6639

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
6 tasks done
lbussy opened this issue Oct 13, 2019 · 1 comment
Closed
6 tasks done

mDNS Failure Outside loop() #6639

lbussy opened this issue Oct 13, 2019 · 1 comment

Comments

@lbussy
Copy link

lbussy commented Oct 13, 2019

Basic Infos

  • This issue complies with the issue POLICY doc.
  • I have read the documentation at readthedocs and the issue is not addressed there.
  • I have tested that the issue is present in current master branch (aka latest git).
  • I have searched the issue tracker for a similar issue.
  • If there is a stack dump, I have decoded it. (N/A)
  • I have filled out all fields below.

Platform

  • Hardware: ESP-12S
  • Core Version: SDK:2.2.1(cfd48f3)/Core:2.5.2=20502000/lwIP:STABLE-2_1_2_RELEASE/glue:1.1-7-g82abda3/BearSSL:a143020
  • Development Env: Platformio
  • Operating System: Windows

Settings in IDE

  • Module: Wemos D1 mini r2
  • Flash Mode: qio
  • Flash Size: 4Mb
  • lwip Variant: v2 Lower Memory
  • Reset Method: ck
  • Flash Frequency: 40Mhz
  • CPU Frequency: 80Mhz
  • Upload Using: SERIAL
  • Upload Speed: 460800

Problem Description

mDNS resolution fails with -5 when called with Ticker, however works (the first time) when called in the loop().

MCVE Sketch

#include <WiFiClient.h>
#include <ESP8266WiFi.h>
#include <Ticker.h>
#include <Arduino.h>

void setup();
void loop();

void setup()
{
    Serial.begin(74880);
    Serial.setDebugOutput(true);
    Serial.flush();
    WiFi.begin(F("Xxxxxx"), F("xxxxxxxx"));
    Serial.println();
    Serial.print(F("Waiting for connection."));
    while (WiFi.status() != WL_CONNECTED)     {
        Serial.print(F("."));
        delay(500);
    }
    Serial.println();
    Serial.println(F("Connected."));
    Serial.print(F("DNS #1: "));
    Serial.print(WiFi.dnsIP().toString().c_str());
    Serial.print(F(", DNS #2: "));
    Serial.println(WiFi.dnsIP(1).toString().c_str());
}

void loop() {
    IPAddress resolvedIP;
    const char* host = "raspberrypi.local";
    if (!WiFi.hostByName(host, resolvedIP)) {
        Serial.print(F("Host lookup failed for "));
        Serial.println(host);
    }
    Serial.print(F("Host: "));
    Serial.print(host);
    Serial.print(", IP: ");
    Serial.println(resolvedIP.toString().c_str());

    Ticker lookup;
    lookup.attach(10, [lookup]() {
        IPAddress resolvedIP;
        const char* host = "raspberrypi.local";
        if (!WiFi.hostByName(host, resolvedIP)) {
            Serial.print(F("Host lookup failed for "));
            Serial.println(host);
        }
        Serial.print(F("Host: "));
        Serial.print(host);
        Serial.print(", IP: ");
        Serial.println(resolvedIP.toString().c_str());
    });

    while (true) { yield(); }
}

Debug Messages

 ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v8b899c12
~ld

SDK:2.2.1(cfd48f3)/Core:2.5.2=20502000/lwIP:STABLE-2_1_2_RELEASE/glue:1.1-7-g82abda3/BearSSL:a143020
scandone

Waiting for connection....wifi evt: 2
...scandone
state: 0 -> 2 (b0)
.state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 3
cnt

connected with Xxxxxx, channel 8
dhcp client start...
wifi evt: 0
ip:192.xxx.xxx.155,mask:255.255.255.0,gw:192.xxx.xxx.1
wifi evt: 3

Connected.
DNS #1: 1.1.1.1, DNS #2: 1.0.0.1
[hostByName] request IP for: raspberrypi.local
[hostByName] Host: raspberrypi.local IP: 192.xxx.xxx.131
Host: raspberrypi.local, IP: 192.xxx.xxx.131
pm open,type:2 0
[hostByName] request IP for: raspberrypi.local
[hostByName] Host: raspberrypi.local lookup error: -5!
Host lookup failed for raspberrypi.local
Host: raspberrypi.local, IP: (IP unset)
@devyte
Copy link
Collaborator

devyte commented Oct 14, 2019

This has nothing to do with mDNS. This is normal DNS.
To be specific, WiFi.hostByName() does DNS resolution only, but your hostname is .local which is mDNS.
For mDNS use the MDNS class.
Closing due to user error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants