Skip to content
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

Implement wifi.stop_ap for RP2 #8590

Merged
merged 1 commit into from
Nov 13, 2023
Merged

Implement wifi.stop_ap for RP2 #8590

merged 1 commit into from
Nov 13, 2023

Conversation

eightycc
Copy link

Implement wifi.stop_ap() in RP2.

Resolves #8138.

@eightycc eightycc changed the title Implement stop_ap for RP2 Implement wifi.stop_ap for RP2 Nov 12, 2023
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.

Using artifact Adafruit CircuitPython 8.2.7-6-g2aa5b443a7 on 2023-11-12; Raspberry Pi Pico W with rp2040:

LGTM, can start and stop AP, and alternate between Station and AP, repeatedly, without issue. Tested with and without Web Workflow enabled. Retested #8138 without issue.
import time
import os
import wifi

AP_SSID = "Bob"
AP_PASSWORD = "YourUncle"
ITERATIONS = 10
DELAY = 3

time.sleep(3)  # wait for serial
print("="*25)

def connect():
    while not wifi.radio.connected:
        try:
            wifi.radio.connect(os.getenv("WIFI_SSID"), os.getenv("WIFI_PASSWORD"))
        except:
            pass

def ap():
    print("Starting AP...      ", end="")
    wifi.radio.start_ap(ssid=AP_SSID, password=AP_PASSWORD)
    print(f"{wifi.radio.ipv4_address_ap=}")
    time.sleep(DELAY)
    print("Stopping AP...      ", end="")
    wifi.radio.stop_ap()
    print(f"{wifi.radio.ipv4_address_ap=}")

def station():
    print("Starting station...")
    wifi.radio.start_station()
    print("Connecting...       ", end="")
    connect()
    print(f"{wifi.radio.ipv4_address=}")
    time.sleep(DELAY)
    print("Stopping Station... ", end="")
    wifi.radio.stop_station()
    print(f"{wifi.radio.ipv4_address=}")

# start clean
if wifi.radio.connected or wifi.radio.ipv4_address:
    wifi.radio.stop_station()
if (wifi.radio.ap_active) or (wifi.radio.ipv4_address_ap):
    wifi.radio.stop_ap()
while True:
    print()
    # Station toggling
    for _ in range(0, ITERATIONS):
        station()
    # AP toggling
    for _ in range(0, ITERATIONS):
        ap()
    # Station & AP alternating
    for _ in range(0, ITERATIONS):
        station()
        ap()

Thanks, @eightycc!

@anecdata anecdata linked an issue Nov 13, 2023 that may be closed by this pull request
@dhalbert dhalbert requested a review from jepler November 13, 2023 15:02
@dhalbert
Copy link
Collaborator

@jepler asking for a review from you, given your expertise on this, but looks good.

Copy link
Member

@jepler jepler left a comment

Choose a reason for hiding this comment

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

thanks! no testing performed.

@jepler jepler merged commit 1151d1b into adafruit:8.2.x Nov 13, 2023
18 checks passed
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 simple AP code is boot looping
4 participants