Page 1 of 1

How to resolve the IP Address of a Mesh Light ? <SOLVED>

Posted: Sun Jun 02, 2019 7:30 pm
by fasani
First of all excuse me for posting in this section, since this is more a general question, but I thought that in this forum secion it will address people with more knowledge that already did this. Feel free to move it if it's not adequated.

I'm just experimenting sending color signals from another ESP32 (An M5Stick with a Microphone) to make the lights react with the sound.
And I would like to make a mDNS query to the esp32_mesh.local root lamp to avoid hardcoding the address.

But still could not make it. Although I searched quite a lot and look in the IDF examples (Note here I'm doing just a quick and dirty example in Arduino framework)

If someone did this, can you please shed some light on it with a quick example ?
If I understand right, the way to get an ip address from something.local is to send UDP packets into the mDNS net until someone responds and says "I'm something.local" is that right ?

Code: Select all

#include <mdns.h>
#include <WiFi.h>
#include "setupConfig.h"
// setupConfig has your connection
//const char* ssid = "KabelBox-A210";      //  your network SSID (name)
//const char* pass = "";       // your network password

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

    struct ip4_addr addr;
    addr.addr = 0;

    esp_err_t err = mdns_query_a(host_name, 2000,  &addr);
    delay(500);Serial.println(err);

    
    if(err){
        if(err == ESP_ERR_NOT_FOUND){
            Serial.println("Host was not found!");
            return;
        }
        Serial.println(addr.addr);
        Serial.println("Query Failed");
        return;
    }

   
}
void setup()
{
    Serial.begin(115200);
    WiFi.mode(WIFI_STA);
    WiFi.begin(ssid, pass);
    if (WiFi.waitForConnectResult() != WL_CONNECTED) {
        Serial.print(".");
        delay(100);
    }
    Serial.println("Firmware online");

const char * host = "esp32_mesh";
resolve_mdns_host(host);
}
void loop() {
}



Re: How to resolve the IP Address of a Mesh Light ?

Posted: Mon Jun 03, 2019 3:10 am
by ESP_Bond
An [example][https://github.com/espressif/esp-mdf/bl ... tice.c#L57] of a local discovery of the parameter esp-mdf

You can also run the [example of mdns][https://github.com/espressif/esp-idf/bl ... main.c#L34] directly in esp-idf

Re: How to resolve the IP Address of a Mesh Light ?

Posted: Mon Jun 03, 2019 10:04 am
by fasani
Thank you very much. I've started with IDF but I'm still a newbie.

I would like to ask: Are this IDF examples also possible to use in Arduino Framework ?

Re: How to resolve the IP Address of a Mesh Light ?

Posted: Tue Jun 04, 2019 4:16 am
by ESP_@In逍遥子
Yes,I think it‘s ok.However, some adaptation is needed

Re: How to resolve the IP Address of a Mesh Light ?

Posted: Thu Jun 20, 2019 7:43 am
by ISimion
Hi, I am experiencing the same type of issue.

For the record, I am trying to access http://myServerName.local/ link through a client running on ESP32 after I establish the mDNS on the server running on another ESP32.

I tried implementing an HTTP request with the previous link, but it won't seem to work. I also tried just to access the link from my browser but that won't work either.

The only thing I got so far was -1 for httpCode and nothing else.

So if you get ESP-IDF examples working on the Arduino Framework I would be grateful to know how you did it, since I'm a newbie to ESP-IDF as well and I work better on Arduino IDE.


Client Code:

Code: Select all

      HTTPClient http;
      Serial.print("[HTTP] begin... \n");
      http.begin("http://myServerName.local/"); //HTTP
      Serial.print("[HTTP GET... \n");
      int httpCode = http.GET();
      ...
Server Code:

Code: Select all

     void advertiseServices(const char* myName)
     {
       if(MDNS.begin(myName))
       {
         Serial.println(F("mDNS responder started."));
         Serial.print(F("I am: "));
         Serial.println(myName);
         //Add service to MDNS-SD
         MDNS.addService("http", "tcp", 80);
       }
       else
       {
         while(1)
         {
           Serial.println(F("Error setting up MDNS responder"));
           delay(1000);
         }
       }
     }

     void setup(void) 
     {
       //Activarea serviciilor prin care putem lua legatura cu device-urile in functie de numele lor
       advertiseServices("myServerName");
       ...
     }

Re: How to resolve the IP Address of a Mesh Light ?

Posted: Fri Jun 21, 2019 12:47 pm
by ESP_@In逍遥子
you can commit issue on github

Re: How to resolve the IP Address of a Mesh Light ?

Posted: Mon Jun 24, 2019 8:11 am
by ISimion
Alright, I did it.

It is at the following link: https://github.com/ISimion/Issue-ESP32

Re: How to resolve the IP Address of a Mesh Light ?

Posted: Mon Jun 24, 2019 1:43 pm
by ESP_LBB
Hi ISimion,

I'm really sorry that my collegue may misguide you.

As we are not so sure about the issues regarding with arduino, he meant to guide you to raise this issue in the GitHub following : https://github.com/espressif/arduino-esp32/issues (He put the link under the word github), to have someone else help solve this.

I'm sorry for the misunderstood we caused.

Re: How to resolve the IP Address of a Mesh Light ?

Posted: Fri Jun 25, 2021 2:12 pm
by fasani
No problem @ESP_LBB
This days I'm using only ESP-IDF
And I found the comments again after 3 years of posting this and today I could try it out again. Here is a commit adding a MDNS Query to auto-detect the IP address of a Mesh root lamp (esp32_mesh.local) with ESP32.

https://github.com/martinberlin/lv_port ... b7fdb75a6e

Happy lamp hacking!
Here is my proof-of-concept video ESP32 controller with epaper touch to control the lights:
https://twitter.com/martinfasani/status ... 6120491008