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

User avatar
fasani
Posts: 197
Joined: Wed Jan 30, 2019 12:00 pm
Location: Barcelona
Contact:

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

Postby fasani » Sun Jun 02, 2019 7:30 pm

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() {
}


Last edited by fasani on Mon Jul 12, 2021 6:31 pm, edited 1 time in total.
epdiy collaborator | http://fasani.de Fan of Espressif MCUs and electronic design

ESP_Bond
Posts: 51
Joined: Mon Apr 15, 2019 1:37 pm

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

Postby ESP_Bond » Mon Jun 03, 2019 3:10 am

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

User avatar
fasani
Posts: 197
Joined: Wed Jan 30, 2019 12:00 pm
Location: Barcelona
Contact:

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

Postby fasani » Mon Jun 03, 2019 10:04 am

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 ?
epdiy collaborator | http://fasani.de Fan of Espressif MCUs and electronic design

ESP_@In逍遥子
Posts: 132
Joined: Thu Nov 15, 2018 2:06 am

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

Postby ESP_@In逍遥子 » Tue Jun 04, 2019 4:16 am

Yes,I think it‘s ok.However, some adaptation is needed

ISimion
Posts: 2
Joined: Thu Jun 20, 2019 7:35 am

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

Postby ISimion » Thu Jun 20, 2019 7:43 am

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");
       ...
     }

ESP_@In逍遥子
Posts: 132
Joined: Thu Nov 15, 2018 2:06 am

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

Postby ESP_@In逍遥子 » Fri Jun 21, 2019 12:47 pm

you can commit issue on github

ISimion
Posts: 2
Joined: Thu Jun 20, 2019 7:35 am

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

Postby ISimion » Mon Jun 24, 2019 8:11 am

Alright, I did it.

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

ESP_LBB
Posts: 108
Joined: Fri May 18, 2018 3:41 am

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

Postby ESP_LBB » Mon Jun 24, 2019 1:43 pm

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.

User avatar
fasani
Posts: 197
Joined: Wed Jan 30, 2019 12:00 pm
Location: Barcelona
Contact:

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

Postby fasani » Fri Jun 25, 2021 2:12 pm

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
epdiy collaborator | http://fasani.de Fan of Espressif MCUs and electronic design

Who is online

Users browsing this forum: No registered users and 63 guests