Skip to content
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

[FEATURE REQUEST] Add MAC address in properties of the zeroconf discovery protocol #686

Open
liudger opened this issue Dec 11, 2024 · 5 comments

Comments

@liudger
Copy link
Contributor

liudger commented Dec 11, 2024

Is your feature request related to a problem? Please describe.
When setting up an integration with zeroconf in Home-Assistant we need to check if it's already setup.
For this we use the MAC address as ip address can change. The problem is that this information is not send in the properties of the zeroconf message.
So we can't check if BSBLan integration is already setup for the device.

Describe the solution you'd like
add MAC address to service text (txtContent?) as a property

Hi Fred,
I don't have the latest firmware installed yet. Will look into this shortly. I suspect this MAC address is not in there? If so discard this request.

@liudger
Copy link
Contributor Author

liudger commented Dec 11, 2024

MDNS.addService("BSB-LAN web service._http", "tcp", 80);

We should add here something like?
MDNS.addServiceTxt("bsblan", "tcp", "mac", escapedMac.c_str());

@liudger
Copy link
Contributor Author

liudger commented Dec 11, 2024

Something like this?

#if defined(ESP32)
    MDNS.begin(mDNS_hostname);
    MDNS.addService("http", "tcp", 80);
    MDNS.addService("BSB-LAN web service._http", "tcp", 80);

    // Add MAC address for ESP32 (WiFi)
    String macAddress = WiFi.macAddress();
    MDNS.addServiceTxt("BSB-LAN web service._http", "tcp", "mac", macAddress);
#else
    if (network_type == WLAN) {
#if defined(WIFISPI)
        mdns.begin(WiFi.localIP(), mDNS_hostname);
#endif
        // Add MAC address for WiFi
        String macAddress = WiFi.macAddress();
        mdns.addServiceTxt("BSB-LAN web service._http", "tcp", "mac", macAddress);
    } else {
        mdns.begin(Ethernet.localIP(), mDNS_hostname);

        // Add MAC address for Ethernet
        byte mac[6];
        Ethernet.MACAddress(mac);
        char macStr[18];
        snprintf(macStr, sizeof(macStr), "%02X:%02X:%02X:%02X:%02X:%02X",
                 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
        mdns.addServiceTxt("BSB-LAN web service._http", "tcp", "mac", macStr);
    }
    mdns.addServiceRecord("BSB-LAN web service._http", HTTPPort, MDNSServiceTCP);
#endif
    printFmtToDebug("Starting MDNS service with hostname %s\r\n", mDNS_hostname);
}

@fredlcore
Copy link
Owner

Sure, can you come up with a (tested) pull request? Happy to add that, but don't have the means to test it at the moment...

@liudger
Copy link
Contributor Author

liudger commented Dec 13, 2024

I will try.

@fredlcore
Copy link
Owner

The above wouldn't work on the ESP32 because after the first #else come the command for the Arduino Due. Maybe that's the one you have, but it should work at least also for the ESP32.

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