-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Hostname unification #4751
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
Hostname unification #4751
Conversation
WalkthroughConsolidates hostname/mDNS handling, replaces unsafe fixed-size copies with sizeof-based copying, adds mDNS enable flag, removes prepareHostname, adds resolveHostname, applies hostname immediately to network interfaces, and updates network UI (hostname input, mDNS toggle, Ethernet/ESP-NOW logic). Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~30 minutes Assessment against linked issues
Possibly related PRs
Suggested reviewers
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. 📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration. 📒 Files selected for processing (9)
💤 Files with no reviewable changes (1)
🚧 Files skipped from review as they are similar to previous changes (8)
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
wled00/network.cpp
Outdated
// convert the "serverDescription" into a valid DNS hostname (alphanumeric) | ||
char hostname[64]; | ||
prepareHostname(hostname); | ||
char hostname[33]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the change from 64 to 33 and this seems out of step with other parts of the code where you are using 25
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
None of the UI fields are 64 bytes.
With this change, can we still have no mDNS but still the user-defined hostname? (used in DHCP request for "regular" DNS) |
Yes, the fallback is UI device name. |
Yeah that doesn't quite make sense then. While I accept that not putting anything in there will maintain existing behaviour, I thought that part of the reason for this change is that current behaviour is unclear. Most users would expect the network hostname to be with the network settings, not automatically generated from a setting under UI. So this change to move hostname to be consistent for regular DNS and mDNS is an improvement, but it would be sad if you couldn't see your own regular hostname without being forced to enable mDNS as the only way to disable is to remove the hostname |
Then the only option is to add a checkmark for enabling mDNS. |
@netmindz @willmmiles @DedeHai @softhack007 @Aircoookie I would like we all agree on the proposed change since it may disrupt some people's network configuration and we should be aware of this change. As a pro for this change it fixes wrong/missing hostname on change or boot. |
this is above my networking know-how. I exclusively work with IPs. |
It is not really technical. This PR switches the hostname generation to mDNS name instead of UI name (by default). UI name is used as a fallback when user does not want to use mDNS and empties mDNS name. In current situation UI name is WLED by default and if user does not change that there may be several devices with same hostname. Default mDNS name is a combination of "wled-" and MAC address. |
Ah I get it, still don't really understand the background, did not have time yet to read the issues solved with this. Can't really comment on "disrupting network". I do not use names, I assign fixed IPs. All I want to add: it must not be convoluted, like input fields need to be clear. If I change mDNS name, it should not change the host name and vice versa (if that is how it currently is). If any naming settings are linked, they MUST be in the same settings page and synced directly in that page so its obvious. edit: |
I'm pulling this to draft as perhaps we need to discuss the following:
IMO hostname and mDNS name should be identical (not necessarily the case with this PR) however device name should not be used in the networking context (it is with this PR if user erases mDNS). I have modified the entire name handling and introduced explicit mDNS selection as a POC in my fork (unpublished ATM). |
…hostname to "nw" key in config JSON - add new config key in "nw" for mDNS (bool) - remove `prepareHostname()` function - update mDNS calls - add hostname update for Ethernet - move WiFi configuration to cfg.json - rename LED and WiFi to Hardware and Network in settings - reorder network settings
<div id="ESPNOW"> | ||
Enable ESP-NOW: <input type="checkbox" name="RE" onchange="tE()"><br> | ||
<i>Listen for events over ESP-NOW<br> | ||
Keep disabled if not using a remote or wireless sync, increases power consumption.<br></i> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name it ESPNow-Sync instead of wireless sync?
@willmmiles does the latest push fulfill what we talked about (single hostname across all networking options)? It does not change UI name, though, which remains WLED by default but can be overridden during compile. |
I think we should just have an explicit hostname field, that is then used by the DHCP client to self register against your domain used for you LAN, for example wled123.fritz.box and then also the same hostname for mDNS wled123.local By default it set to WLED dash mac address, with colons removed. For existing installs we populate this new field with the current logic of the sanitised version of the server name, to maintain compatibility |
@netmindz this is exactly what this PR does. |
It is very close, I'm just testing at the moment, but the hostname I got for my existing install did not use the device name, but i need to double check i was in the correct state before |
If we are going to display the full URL that your mDNS address will be, then that should be a link |
I terms of placement, I think it should be just before the static ip rather than right at the top |
yeah, I've just double checked and as it stands at the moment, this PR is a breaking change, the existing way of setting the hostname does not carry over to the new setup, i just get wled-e73b10 We need to populate the new hostname value based on the existing logic |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to migrate people's existing hostname
getStringFromJson(hostName, id[F("mdns")], sizeof(hostName)); | ||
if (strlen(hostName) == 0) { | ||
mDNSenabled = false; // if no host name is set, disable mDNS | ||
sprintf_P(hostName, PSTR("wled-%.*s"), 6, escapedMac.c_str() + 6); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be changed to use the existing logic, for example my current hostname of window is because i have the WLED device called Window
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This uses existing logic. If {"id":{"mdns":....}, ...}
exists, it uses that name. Only if someone disabled mDNS (by entering empty name) then new hostname is generated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's using the mDNS name, personally I've never edited that as I'm using regular DNS which uses the device name from the UI settings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure which we choose, but whatever we choose it won't be the right option for 100% of users.
Certainly if the device name in UI settings is still "WLED" then we could definitely ignore that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the non-mDNS hostname is wled-{serverDescription}, so actually you get "wled-window" not just "window"
wled-window.ftriz.box for example - when name in server description in the UI settings is "Window"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cmDNS
and serverDescription
are only created during 1st boot. Each consecutive boot will use stored values if they were modified by user or not.
The only difference this PR does (regarding network naming) is the change of DHCP lease names (and dnsmasqd responses to DNS querires (non-mDNS) if your router supported that). Those were missing in case of ESP32 (producing esp-xxxxxx
registration) or constructed from serverDescription
(producing wled-zzzzzzz
name, where zzzzzz conformed to [0-9a-zA-Z\-\_]+
regexp). DNS queries were never officially supported or advertised by WLED.
The mDNS name and hostname are now (with this PR) the same (as is usual or common practice).
However, I am loosing interest in pursuing this PR further (since none of the OP responded to my queires, these include: @tablatronix, @huggy-d1, @mateuszdrab, @b3-4r, @Rodney2K, @BBaoVanC, @schildbach and @Colbyjdx) so do whatever pleases you (merge, edit or abandon), I am not going to update it any more.
I must have this muted didn't see this |
Hi all! First of all, I'd like to thank @blazoncek for all the hard work. I don't intend to 'steal' his PR in any way, but saw that he didn't want to pursue this any further, so I tried to get this to a state where it can be merged. The result is over in my fork. There were two issues:
This PR was tested on both an ESP8266 and ESP32, but the latter reported If you need anything more, just let me know! |
@milhnl you are welcome to PR into EDIT: FYI I disliked behaviour of |
I agree. But not breaking backwards compatibility seems more important to the maintainers, which I get, even though it's not in a documented feature. |
Sometimes you need to break things to make something new. 😉 |
After that, there's two commits at in my PR. No clue how these not-to-main PRs work in the GitHub view. But they're there. |
Summary by CodeRabbit
New Features
Improvements
Bug Fixes
Style