Is there a reason why the mDNS name and Server Description / DHCP name are separate and different by default?
The mDNS name (Settings > WiFi) defaults to wled-<lower half of MAC>, e.g. wled-326524. This is good as it’s likely to be unique on the network, and you can predict it if the MAC is known (e.g. printed on the device). IIUC, the mDNS name is set in WLED::setup.
However the DHCP name is set to the the concatenation of wled-and the ‘Server description’ (Settings > User Interface: Web Setup), the default for that is the fixed string WLED, so you end up with a DHCP hostname of wled-WLED.
I believe it would be good to have the mDNS and DHCP names be consistent. That is, all of the hostname + DHCP name + mDNS name should be set to:
- the server description, if it has been set by the user, or
- default:
wled-<escaped MAC>
I’m not familiar with wled’s codebase, but from what I can see prepareHostname() is responsible. prepareHostname() initially sets the hostname as wled-<lower half of MAC>, but then proceeds to overwrite the MAC part with serverDescription (default is WLED).
Seems like an easy win would be to change prepareHostname()to something like:
void prepareHostname(char* hostname)
{
if (serverDescription == 'WLED') {
sprintf_P(hostname, PSTR("wled-%*s"), 6, escapedMac.c_str() + 6);
return;
}
const char *pC = serverDescription;
unsigned pos = 0;
while (*pC && pos < 24) { // while !null and not over length
...
Separately, the mDNS code is repeating the logic of prepareHostname(), that should just call prepareHostname() right?