-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
extmod/modnetwork: Add global hostname/LWIP-mDNS. #9058
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
Conversation
I tested a few configurations. Working ones: Non-Working: In all cases the additional network module methods do not exist. For PyBoard + W5500 it is anyhow better to wait until PR #9021 is merged. Then modnwwiznet5k.c and network_wiznet5k.c are dropped. |
Once again, thank you @robert-hh for your help in this PR.
Good ! I tested for WIZNET_5500_EVB_PICO and WIZNET_5100S_EVB_PICO boards.
That's strange as the
Argh !! When I try to synchronize the branch with the original master from the GitHub web page, it adds a message that does not follow the requested commit message format (ex: |
The hostname method exists in the RP2040_NINAW10, but not the other ones like mdns_add_service(). bt.w.: It seems strange that one has to configure the nic for dhcp to get the mdns services working. What happens if I want to use fixed IP addresses? About git: I usually to not merge the master into my branches, but rebase them on top of the current master after I updated the master. Nevertheless, PR 9021 is not merged yet. |
That's normal as it does not use LWIP library (which has the mDNS server embedded), or does it?
Nope. You can use a fixed address as well (I use it personally):
By the way, wouldn't be nice to be able to have default implicit values for the tuple content not to have to enter all the values:
Ok. Thanks. I'll use it manually too.
OK. I'll wait until this is done. Hoping that it won't make any conflict because of the removal of these 2 extra files... |
No, LWIP is not used.
Just tried it and it works. I was just confused during my mimxrt test, because there the dhcp request is automatically started. So you do not need a ifconfig() call at all.
But you have to set the default values. And that's only inconvenient in test situations, where you change that all the time. Besides that, it seems easy to write a short python wrapper which you can put in main.py
That will be a conflict. So better wait and remove the changes to these files from your PR. |
Thanks @omogenot & @robert-hh ! I haven't had a chance to review this in detail, but conceptually this seems like a good idea. Just out of curiosity, rather than putting the This will obviously need to be rebased when #9021 but when you do, can I suggest that because LWIP is all or nothing, the mod_network_nic_type_t struct should just have either the netif ptr or all of the API methods. No need to do this via an extra level of indirection. And then, like you've done in this PR, make all interfaces use |
Also need to mention that of course none of this applies to ESP32/ESP8266... I don't know what the right answer is there. In the short term I guess the |
Thanks @jimmo for your support and help.
I thought about this too, however yes it's possible to register a service for one nic board only (you can bind a socket to a specific IP). It might not look logical but I have seen so many strange things in my programming life ;-) ... Since this service registration is limited (as of the time of writing to 1 service per nic board only), you may want to optimize your services registrations.
I though about this as well, but I cannot make this assumption that it is LWIP or nothing (again strange things could happen in the future...), and therefore I decided to add this indirection to save ROM space and keep Once again, these comments are just to explain how I came with these solutions whether it makes sense or not. I will align to everyone's decision, you guys have much more experience in this project than I have :-). |
In that case, in the future we end up with a third set of possible fields in the struct.
The point is that when you're compiling with LWIP, the struct only contains the single pointer. The others are #ifdef'ed out.
There is currently no board that has this field that doesnt' have LWIP. As above, in the future if we add another option then we can type the field for that stack as required. |
@jimmo
And populate the
I keep my indirection to the network api custom functions as this would still keep |
I happen to have an ESP32 based board that works using the GENERIC board definition, although it does not have LAN interface. Do you want me to start a new PR to clean up a bit this code: |
I'm not quite sure I follow. Does this mean that Just because it could be possible to support having unique services per NIC, doesn't mean we should. If we can reduce code size and complexity it might be worth just making them global.
@omogenot I get what you're saying but there are many other parts that currently work on the assumption that you're either compiling with LWIP or custom stack, and never both. For example, whether you get The main point though is that your proposal adds two words per NIC type (the enum value and the pointer) which currently don't confer any benefit. If it's an LWIP build, then the enum value will always be LWIP, etc.
I agree it would be good to do this (and along the way I'm definitely keen to see some standardisation between ESP32 and the other ports with things like the constants on the But let's figure out what we want to do with the API first in this PR -- i.e. whether adding |
Yes. In
The code complexity is kind of 'simplified' (if I can say so) by the fact that the main part of the process handling the mdns_* functions is written in
As you mentioned, it's an assumption. Too bad since we opened the hood and started to touch the engine ;-).
Fine by me, the goal was to decouple the
You're the boss, boss :-). The idea was to open a PR for discussion, I don't know how you proceed in the community to decide for such enhancements. I was just proposing my help because I am still on vacation until the end of the week, after that I'll be back to work and have much less spare time. I'll wait for you final decisions to modify the source code accordingly or drop this PR (or may be you can modify code directly on my GitHub fork).
|
@jimmo
Do you know what it was intended to do? Shall we fix it? |
@jimmo
|
@jimmo @dpgeorge Edit: OK. Looks like no damage has been done to the repository. |
Hey, So i flashed "rp2-pico-w-20220906-unstable-v1.19.1-375-ge90b85cc9.uf2" which is Sept 06th build on Pico_W and network.hostname() is still not an attribute.
Appreciate your help. Thank You! |
@maxacode |
Ahh makes sense, explains it well. So until then I can just compile this branch to flash it on the Pico, since only this branch has the merged code? Thanks |
Yes sorry that is what I meant by "this branch" the new one, thats not messed up. Thank You so much. I am just getting into Micro Controllers and its a whole new world. I know Python for years but this is new for me. |
This PR proposes to globally move hostname definition to the
network
module, so that it will be defined for all nic boards by using thenetwork.hostname()
method. The default host name is set tomp-host
and the hostname length is controlled by theMICROPY_PY_HOSTNAME_LENGTH
constant which is defaulted to 32 if not defined.Note: This PR would replace some of the modifications done specifically for the cyw43 board only (PR #8918), but keeps the ioctl functions up and running using this global hostname definition.
If the nic board uses the LWIP library, we take advantage of the integrated
mDNS
server (if theLWIP_MDNS_RESPONDER
constant is defined) to a) declare hostname for the nic board; b) append three functions to the nic object to add, rename and remove a service to the mDNS server for that nic.From now on, on the network, you can perform a
ping my-host.local
to get a response from your micropython board.I could not test these modifications for all nic boards, I have only WIZNET5K boards available. The
pico_w
board compiles though.The actual only limitation is to define the hostname via network.hostname before creating the nic object. Renaming the hostname after the creation of the nic object does not reflect this name change. To make this mDNS hostname change, it requires to global change to theI don't dare to go further for the time being. I need guidance.mod_network_nic_type_t
and probably put all the socket oriented functions (that are probably sitting there for older versions before the use of LWIP library) into another struct (likemod_network_custom_fun_type_t
for example) pointed by thismod_network_nic_type_t
to save ROM space for nic boards that do not use these specific functions, make sure that all nic board objects really derive from thismod_network_nic_type_t
and add avoid * netif_ptr
member to themod_network_nic_type_t
that would point to thenetif
of the nic board if available, so that themod_network
could access this parameter to use LWIP mDNS functions. Thisnetif_ptr
member will be set by the nic board driver so that boards that have multiple netif(s) will set the right one (for the cyw43 for instance). ButComments and help are more than welcome as I am quite new to micropython firmware and I don't know all the internals as well as you guys.