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
Add nic.ipconfig for other ports (like esp32, stm32 and others) #14199
base: master
Are you sure you want to change the base?
Conversation
8f32d70
to
1b81f03
Compare
@felixdoerre Thank you for your work. I had started yesterday as well with changes. See https://github.com/robert-hh/micropython/tree/ports_ipconfig |
Tested your changes for MIMXRT (MIMXRT1020_EVK) and STM32 (LAN: PYBD_SF6 with DP83848, WiFi: Built-in CYW43) and they work, as expected. I did not test other boards because the changes do not touch board-specific features. |
Tested a little bit more.
and
MIMXRT & STM32:
|
I have updated my branch with the implementation for NINAW10. It includes code for network.ipconfig(), even if the effect with NINAW10 is unclear, which may allow to set the DNS, but it cannot be read back from the module. |
The following change fixes the bug in using the CIDR notation for lwip based stacks:
|
1b81f03
to
08758f3
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #14199 +/- ##
=======================================
Coverage 98.39% 98.39%
=======================================
Files 161 161
Lines 21200 21200
=======================================
Hits 20860 20860
Misses 340 340 ☔ View full report in Codecov by Sentry. |
Code size report:
|
I updated the NINAW10 commit a few minutes ago. So you might not have taken the right version. Better wait a while, usually until the next day. |
OK. What's next. I could either continue with ESP8266 or CC3200. |
extmod/network_ninaw10.c
Outdated
|
||
switch (mp_obj_str_get_qstr(args[1])) { | ||
case MP_QSTR_dhcp4: { | ||
return mp_const_true; |
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.
If I'm reading this (https://github.com/adafruit/nina-fw/blob/47875b775aee74c5f948ef2b955c9786b023a89e/arduino/libraries/WiFi/src/WiFi.cpp#L297) correctly, the ninaw10 has a dhcp client enabled, but disables it once you set a static IP (i.e. once you call NINA_CMD_SET_IF_CONFIG
). And then it would need to be re-initialized to activate the dhcp client again. Maybe this behavior is something we should reflect here?
Otherwise I would argue that we should remove this keyword to indicate that the nic-driver "does not know".
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.
I can do that. @iabdalkader since you made that driver, do you have more information?
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.
And then it would need to be re-initialized to activate the dhcp client again. Maybe this behavior is something we should reflect here?
That would require some static flag, that NINA_CMD_SET_IF_CONFIG
was called. That's something I want to avoid.
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.
I can do that. @iabdalkader since you made that driver, do you have more information?
Hi, information about what specifically ? Can you provide more context ?
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 discussion was about enabling and disabling DHCP in the NINAW10 module and whether there is a dedicated command/function to control it, or if it happens implicitly. The assumption now is: DHCP is enabled, when the NINAW10 module is intialized. And on any manual setting of the IP configuration it's disabled.
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.
Yes that seems to be the case. Although I can't find an explicit call to tcpip_adapter_dhcpc_start
in the nina firmware, but it seems to be enabled by default and disabled on static IP config.
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.
Thanks.
I've incorporated the suggestions that were in the comments, so the esp32 code could work now. You can re-test that one. And/or start working on esp8266. I am not sure if esp8266 needs different code, or if that can re-use code from esp32, and if we can re-use code, should we try to extract the common logic somewhere? |
OK. I'll re-test the ESP32. If you want to work at the ESP8266 code, I can go for the CC3200. |
The ESP32 code works fine. One little hiccup. |
I can go for
If that sounds sane to you, I'd continue with those changes, and you can pick esp8266 or cc3200 whatever you prefer. |
I added a commit to my branch for NINAW10 dealing with dhcp4. For better visibility, I kept that separate. You can pick that commit and squash it to the existing NINAW10 commit. |
I have no knowledge and no position about esp32_ppp. About dns setting per interface or global: that has to be tested. I can do that, if you have the code. dns setting was otherwise a network option. Although having a rather large function and some tweaky code in modnetwork.c seems not appropriate. |
92f35c0
to
cdf1713
Compare
A few build errors with the last commit for ESP32_PPP. The last one is just a typo.
|
Just needed to uncomment |
@felixdoerre The support for the CC3200 is now in my branch. Tested with a WiPy board and STA mode. |
If you think it's ready, you can change the state from draft to open. |
b53000f
to
a053d0c
Compare
@felixdoerre There was still something to fix in extmod/network_lwip.c, when using ipconfig(addr="a.b.c.d") without the number for the netmask. The other ports would then just set the IP addr, but for LWIP ports the value for the address was undefined. |
a053d0c
to
c259bef
Compare
Hmm, when you now set the address without netmask, it assumes |
Right & thanks. The intention was to not touch the netmask at all, like the ESPxx, NINAW10 and CC3200 does at the moment. |
Updated. I was caught by the deferred setting of ip_addr and netmask. Please cross-check. |
c259bef
to
ff6c34d
Compare
@felixdoerre While adding ipconfig() to another port which I support I noticed, that the code setting addr4 can be simplified. addr_str and to_copy are in most ports not needed. I pushed already the changes for C3200 and NINAW10 to the usual place. ESP32 and ESP8266 can be simplified similarly and had the behavior, that when skipping the /nnn in CIDR notation the netmask was 255.255.255.255. Updated files to ESP32 and ESP8266: |
Signed-off-by: Felix Dörre <felix@dogcraft.de>
Due to a omission in the NINAW10 driver stack, setting the DNS address has no effect. But the interface is kept here just in case it's fixed eventually. dhcp4 and has_dhcp4 are dummy arguments. NINAW10 seems to use always DHCP. Signed-off-by: robert-hh <robert@hammelrath.com>
There was a little omisssion in the code. Signed-off-by: robert-hh <robert@hammelrath.com>
Signed-off-by: Felix Dörre <felix@dogcraft.de>
Co-authored-by: robert-hh <robert@hammelrath.com> Signed-off-by: Felix Dörre <felix@dogcraft.de>
Signed-off-by: robert-hh <robert@hammelrath.com>
ff6c34d
to
64a24f4
Compare
Thx for cleaning up. Yes. This looks reasonable. I've incorporated all those changes. |
Thanks. One thing that I not really comfortable with is the dns setting in network.ipconfig(). Even if I understand the reason, it's kind of bumpy, because one cannot set all parameters with one call. It requires network.ipconfig() for dns and nic.ipconfig() for the other parameters. |
We discussed options in #12600. I am not aware of any other When you have a more complete complex linux system with Initially, I also envisioned to set the default gw globally, so one can actively choose where packages are routed per default, but it seems we left that out. (and additionally, |
Interestingly the last comment of Damien in #12600 uses a DNS setting in the nic.ipconfig() method. |
Yes, and when I implemented the first round for lwip, I had dns in the nic method, but Damien hinted to keep the split between global and nic-config: #13689 (comment) |
Maybe that can be re-considered. I most cases just one NIC is used. And most ports allow just one NIC well at a time. The ESP32 port for instance allows to use both WiFi and Ethernet at the same time in a good fashion, but for other ports this either does not work or is somewhat unresponsive. At least it's that what I have seen. |
A similar thing, is that activating dhcp is now non-blocking, meaning that if you want to make sure, you have an IP before you continue, requires additional calls. Maybe the easiest way for "common usage" would be to have one "network-config" method, that can accept one dict, and then also deal with wifi-phy setup and similar? Because the goal, to configure networking in one call, is already not possible in most cases. |
These code changes LGTM, although I think at some point (not this PR) we should look at refactoring out some of the common parts - for example splitting an IPV4/NETMASK string is implemented at least four times and they're not all the same. There might even be a way to do this like the recent extmod/machine changes where the port supplies some static functions for each action, and there's one common argument parsing and verification routine. But not for this PR, this LGTM.
How difficult do you think this would be to implement on top of what's here? Agree it'd be a nice helper method for the common use case, although I worry a bit about the complexity of all the smaller details. |
In order to make network configuration extensible and consistent across ports, we implemented
ipconfig
for the other implemented nics: