Reputation: 1
I want to set up a soft access point (a hotspot without an internet connection) on my Raspberry Pi Pico W with a webserver, the reason it needs to also be a soft access point is because I want to take it with me on the road so most of the times there won't be wifi networks around me to join. I need to use CircuitPython instead of MicroPython, it worked on MicroPython and I keep getting errors that I can't import network.
I tried installing newer firmware of CircuitPython on the Pico W from the original site: https://circuitpython.org/board/raspberry_pi_pico_w/ the latest release is CircuitPython 8.0.3 and I also tried installing older versions of CircuitPython, but it just won't work. I also tried importing the wifi module, that worked but it can't create a soft access point.
This is the code that I'm using:
import network
ap_ssid = "myAP"
ap_password = "password123"
# create access point interface
ap_if = network.WLAN(network.AP_IF)
# disable default access point
ap_if.active(False)
# configure access point settings
ap_if.active(True)
ap_if.config(essid=ap_ssid, password=ap_password)
# print access point settings
print("Access point created with SSID: {}, password: {}".format(ap_ssid, ap_password))
print("Access point IP address:", ap_if.ifconfig()[0])
Upvotes: 0
Views: 2425
Reputation: 21
CircuitPython does not use MicroPython's network module, instead, it uses its own wifi module, which comes preinstalled on most wifi-equipped boards, including the Raspberry Pi Pico W.
First, import the module:
import wifi
Then start the access point:
wifi.radio.start_ap(ssid=ap_ssid, password=ap_password)
To stop the access point run:
wifi.radio.stop_ap()
Here would be your full code:
# import wifi module
import wifi
# set access point credentials
ap_ssid = "myAP"
ap_password = "password123"
# You may also need to enable the wifi radio with wifi.radio.enabled(true)
# configure access point
wifi.radio.start_ap(ssid=ap_ssid, password=ap_password)
"""
start_ap arguments include: ssid, password, channel, authmode, and max_connections
"""
# print access point settings
print("Access point created with SSID: {}, password: {}".format(ap_ssid, ap_password))
# print IP address
print("My IP address is", wifi.radio.ipv4_address)
Here's a description of the start_ap command from the docs:
start_ap(ssid: str | ReadableBuffer, password: str | ReadableBuffer = b'', *, channel: int = 1, authmode: AuthMode | None = None, max_connections: int | None = 4)→ None Starts an Access Point with the specified ssid and password.
If channel is given, the access point will use that channel unless a station is already operating on a different channel.
If authmode is not None, the access point will use that Authentication mode. If a non-empty password is given, authmode must not be OPEN. If authmode is not given or is None, OPEN will be used when the password is the empty string, otherwise authmode will be WPA_WPA2_PSK.
If max_connections is given, the access point will allow up to that number of stations to connect.
For more information, head to CircuitPython's documentation: https://docs.circuitpython.org/en/latest/shared-bindings/wifi/index.html#wifi.Radio.start_ap
Here's a tutorial on using the wifi module with a Raspberry Pi Pico W: https://learn.adafruit.com/pico-w-wifi-with-circuitpython/pico-w-basic-wifi-test
Upvotes: 2