Skip to content

picow: ask at a lower level if the interface is up #7075

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

Merged
merged 1 commit into from
Oct 18, 2022

Conversation

jepler
Copy link

@jepler jepler commented Oct 17, 2022

Closes: #7072

Adafruit CircuitPython 8.0.0-beta.2-9-g5192082e64-dirty on 2022-10-17; Raspberry Pi Pico W with rp2040
>>> import wifi
>>> print(wifi.radio.ipv4_address)
None
>>> import os
>>> wifi.radio.connect(os.getenv('WIFI_SSID'), os.getenv('WIFI_PASSWORD'))
>>> print(wifi.radio.ipv4_address)
10.0.2.94

Closes: adafruit#7072

```
Adafruit CircuitPython 8.0.0-beta.2-9-g5192082e64-dirty on 2022-10-17; Raspberry Pi Pico W with rp2040
>>> import wifi
>>> print(wifi.radio.ipv4_address)
None
>>> import os
>>> wifi.radio.connect(os.getenv('WIFI_SSID'), os.getenv('WIFI_PASSWORD'))
>>> print(wifi.radio.ipv4_address)
10.0.2.94
```
@jepler
Copy link
Author

jepler commented Oct 17, 2022

@BiffoBear your testing here would also be helpful. Note that this build will only have the fix for this problem, not the one for #7076.

@anecdata
Copy link
Member

Won't this also close #6996 ?

Copy link
Collaborator

@FoamyGuy FoamyGuy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this successfully with a Pico W using the slightly modified version of code from the issue:

print(f"ipv4_gateway    : {wifi.radio.ipv4_gateway}")
print(f"ipv4_subnet     : {wifi.radio.ipv4_subnet}")
print(f"ipv4_address    : {wifi.radio.ipv4_address}")
print(f"ipv4_dns        : {wifi.radio.ipv4_dns}")

wifi.radio.connect(secrets["ssid"], secrets["password"])

print("---------------------")
print(f"ipv4_gateway    : {wifi.radio.ipv4_gateway}")
print(f"ipv4_subnet     : {wifi.radio.ipv4_subnet}")
print(f"ipv4_address    : {wifi.radio.ipv4_address}")
print(f"ipv4_dns        : {wifi.radio.ipv4_dns}")

With this build I do get None before connecting and real values after connecting.

When I use ctrl-c then ctrl-d to restart the script I do still have real values from the prints before the connection, but I assume it's intended to behave this way since there is no explicit disconnect action and therefore technically it's just staying connected similar to how displays do across the soft reset.

Copy link
Member

@anecdata anecdata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to @fomayguy's results, I did it in boot.py, then again in code.py:

boot.py output:
#### boot.py ####
None
None
None
None
Connecting..........
192.168.6.202
192.168.4.1
255.255.252.0
1.1.1.2

#### code.py ####
192.168.6.202
192.168.4.1
255.255.252.0
1.1.1.2
Connecting...
192.168.6.202
192.168.4.1
255.255.252.0
1.1.1.2

We should retest this when we have a code mechanism to disconnect (e.g., wifi.radio.enabled = False or wifi.radio.stop_station()) to verify that disconnection invalidates the IPv4 info and they all return None.

@jepler
Copy link
Author

jepler commented Oct 17, 2022

With rp2040 there's no disconnect-from-wifi call that I've been able to find, so it stays connected across soft reset. This is different than the espressif port.

@anecdata
Copy link
Member

anecdata commented Oct 17, 2022

MicroPython has a wlan.disconnect() for Cyw43 (also p.44)
Is there a way we can use the underlying call there (not sure where it comes from)?
Otherwise we can only disconnect with hard reset or real deep sleep.

found it:
https://github.com/georgerobotics/cyw43-driver/blob/195dfcc10bb6f379e3dea45147590db2203d3c7b/src/cyw43_ctrl.c#L601

@jepler
Copy link
Author

jepler commented Oct 17, 2022

OK, I see _leave() now. Yes, it's worth a try.

@jepler
Copy link
Author

jepler commented Oct 17, 2022

(but honestly after using both wifi workflow on espressif and the never-disconnects wifi of picow -- I want wifi connections to stay across soft reset!)

@anecdata
Copy link
Member

anecdata commented Oct 17, 2022

There are a variety of uses cases for wanting to: disconnect; turn off STA (and/or AP); even deinit wifi (we don't have that currently in either native port).

• reduce resource consumption (power, ram)
• re-initialize from code without a hard reset as an escalation when network issues arise
• disconnect from one SSID to reconnect to another
• disconnect from an multi-AP SSID to reconnect to an SSID at a specific BSSID and/or channel
• turn off STA to run AP-only (TBD future for PiCow)
• ?
• profit
;-)

Oh also, at least in the Espressif case, each time you connect to a multi-AP SSID, it will pick the best one, so roaming with a device within a multi-AP SSID area will be able to optimize the connections better. I haven't come across any info on PiCow in the context of multi-AP SSIDs.

Copy link
Collaborator

@FoamyGuy FoamyGuy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Thank you.

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

Successfully merging this pull request may close these issues.

Pico W wifi.radio.ipv4_address behaviour does not match the documentation.
3 participants