Skip to content

Add wifi.radio.connected, wifi.radio.ap_active #7823

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 2 commits into from
Apr 1, 2023

Conversation

dhalbert
Copy link
Collaborator

@dhalbert dhalbert commented Mar 31, 2023

Tested on Pico W and Metro ESP32-S2.

@dhalbert dhalbert requested review from tannewt and jepler March 31, 2023 22:03
@dhalbert dhalbert requested a review from anecdata April 1, 2023 02:33
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.

Tested .connected more thoroughly, looks good all around through mode and started / enabled changes.

.ap_active is now True (only) when wifi is started / enabled, and after start_ap() (mode is AP or AP+STA). It goes False if wifi is disabled or if stop_ap(). Tested various sequences, and everything tracked.

.ap_active seems to be True (only) when there is a valid wifi.radio.ipv4_address_ap, and vice versa.

Both new properties LGTM on espressif!

I'll try to work on raspberrypi later, but since they are driver one-liners and you tested them, no need to wait on me.

@anecdata
Copy link
Member

anecdata commented Apr 1, 2023

I see 124 artifacts, but no Pico W?

@dhalbert
Copy link
Collaborator Author

dhalbert commented Apr 1, 2023

The latest changes only changed a file in port/espressif, so the CI logic only rebuilt those artifacts, to save time. You can find the previous CI runs here: https://github.com/adafruit/circuitpython/actions, and go back in time to https://github.com/adafruit/circuitpython/actions/runs/4579504313, to the last run that had a Pico W build.

There doesn't seem to be an easy way to get there from the PR, that I can find.

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.

raspberrypi .connected and .ap_active LGTM.
(Simpler scenarios with the current CYW implementation #7101 (review))

.connected and .ipv4_address are both correct immediately after a .connect(), and again after a .stop_station().

ap_active and ipv4_address_ap are both correct immediately after a .start_ap() (APs can't currently be stopped).

code and results...
import time
import wifi
from secrets import secrets

time.sleep(3)  # wait for serial

print(f"Connecting...")
wifi.radio.connect(secrets["ssid"], secrets["password"])
start = time.monotonic_ns()
while not wifi.radio.connected:
    pass
print(f"connected in {start - time.monotonic_ns()}ns connected={wifi.radio.connected} ipv4={wifi.radio.ipv4_address}")
print(f"Stopping STA...")
wifi.radio.stop_station()
print(f"connected={wifi.radio.connected} ipv4={wifi.radio.ipv4_address}")

time.sleep(1)

print(f"Connecting...")
wifi.radio.connect(secrets["ssid"], secrets["password"])
start = time.monotonic_ns()
while not wifi.radio.ipv4_address:
    pass
print(f"IPv4 in {start - time.monotonic_ns()}ns connected={wifi.radio.connected} ipv4={wifi.radio.ipv4_address}")
print(f"Stopping STA...")
wifi.radio.stop_station()
print(f"connected={wifi.radio.connected} ipv4={wifi.radio.ipv4_address}")

time.sleep(1)

print(f"Starting AP...")
wifi.radio.start_ap("Bob", "YourUncle")
print(f"ap_active={wifi.radio.ap_active} ipv4={wifi.radio.ipv4_address_ap}")
Connecting...
connected in 0ns connected=True ipv4=192.168.6.198
Stopping STA...
connected=False ipv4=None
Connecting...
IPv4 in 0ns connected=True ipv4=192.168.6.198
Stopping STA...
connected=False ipv4=None
Starting AP...
ap_active=True ipv4=192.168.4.1

@dhalbert dhalbert merged commit cc0eeb4 into adafruit:main Apr 1, 2023
@dhalbert dhalbert deleted the wifi-connected branch April 1, 2023 19:01
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.

wifi.radio: provide "connected" and "access point is up" boolean properties
2 participants