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