Skip to content

Commit 39452db

Browse files
mattytrentinidpgeorge
authored andcommitted
docs/rp2: Add network information to the rp2 quickref.
Some rp2 boards include WiFi, at least with the very popular Pico W and Pico 2 W. New users frequently ask how to set up WiFi and are confused because it's not covered in the quickref. This commit adds the wlan section, copied and modified with notes from the ESP32 quickref. Signed-off-by: Matt Trentini <[email protected]>
1 parent 93a8c53 commit 39452db

File tree

2 files changed

+63
-12
lines changed

2 files changed

+63
-12
lines changed

docs/esp32/quickref.rst

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,30 +83,30 @@ The :class:`network.WLAN` class in the :mod:`network` module::
8383

8484
import network
8585

86-
wlan = network.WLAN(network.WLAN.IF_STA) # create station interface
87-
wlan.active(True) # activate the interface
88-
wlan.scan() # scan for access points
89-
wlan.isconnected() # check if the station is connected to an AP
86+
wlan = network.WLAN() # create station interface (the default, see below for an access point interface)
87+
wlan.active(True) # activate the interface
88+
wlan.scan() # scan for access points
89+
wlan.isconnected() # check if the station is connected to an AP
9090
wlan.connect('ssid', 'key') # connect to an AP
91-
wlan.config('mac') # get the interface's MAC address
92-
wlan.ipconfig('addr4') # get the interface's IPv4 addresses
91+
wlan.config('mac') # get the interface's MAC address
92+
wlan.ipconfig('addr4') # get the interface's IPv4 addresses
9393

9494
ap = network.WLAN(network.WLAN.IF_AP) # create access-point interface
95-
ap.config(ssid='ESP-AP') # set the SSID of the access point
96-
ap.config(max_clients=10) # set how many clients can connect to the network
97-
ap.active(True) # activate the interface
95+
ap.config(ssid='ESP-AP') # set the SSID of the access point
96+
ap.config(max_clients=10) # set how many clients can connect to the network
97+
ap.active(True) # activate the interface
9898

9999
A useful function for connecting to your local WiFi network is::
100100

101101
def do_connect():
102-
import network
103-
wlan = network.WLAN(network.WLAN.IF_STA)
102+
import machine, network
103+
wlan = network.WLAN()
104104
wlan.active(True)
105105
if not wlan.isconnected():
106106
print('connecting to network...')
107107
wlan.connect('ssid', 'key')
108108
while not wlan.isconnected():
109-
pass
109+
machine.idle()
110110
print('network config:', wlan.ipconfig('addr4'))
111111

112112
Once the network is established the :mod:`socket <socket>` module can be used

docs/rp2/quickref.rst

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,57 @@ The :mod:`rp2` module::
5555

5656
import rp2
5757

58+
Networking
59+
----------
60+
61+
WLAN
62+
^^^^
63+
64+
.. note::
65+
This section applies only to devices that include WiFi support, such as the `Pico W`_ and `Pico 2 W`_.
66+
67+
The :class:`network.WLAN` class in the :mod:`network` module::
68+
69+
import network
70+
71+
wlan = network.WLAN() # create station interface (the default, see below for an access point interface)
72+
wlan.active(True) # activate the interface
73+
wlan.scan() # scan for access points
74+
wlan.isconnected() # check if the station is connected to an AP
75+
wlan.connect('ssid', 'key') # connect to an AP
76+
wlan.config('mac') # get the interface's MAC address
77+
wlan.ipconfig('addr4') # get the interface's IPv4 addresses
78+
79+
ap = network.WLAN(network.WLAN.IF_AP) # create access-point interface
80+
ap.config(ssid='RP2-AP') # set the SSID of the access point
81+
ap.config(max_clients=10) # set how many clients can connect to the network
82+
ap.active(True) # activate the interface
83+
84+
A useful function for connecting to your local WiFi network is::
85+
86+
def do_connect():
87+
import machine, network
88+
wlan = network.WLAN()
89+
wlan.active(True)
90+
if not wlan.isconnected():
91+
print('connecting to network...')
92+
wlan.connect('ssid', 'key')
93+
while not wlan.isconnected():
94+
machine.idle()
95+
print('network config:', wlan.ipconfig('addr4'))
96+
97+
Once the network is established the :mod:`socket <socket>` module can be used
98+
to create and use TCP/UDP sockets as usual, and the ``requests`` module for
99+
convenient HTTP requests.
100+
101+
After a call to ``wlan.connect()``, the device will by default retry to connect
102+
**forever**, even when the authentication failed or no AP is in range.
103+
``wlan.status()`` will return ``network.STAT_CONNECTING`` in this state until a
104+
connection succeeds or the interface gets disabled.
105+
106+
.. _Pico W: https://www.raspberrypi.com/documentation/microcontrollers/pico-series.html#picow-technical-specification
107+
.. _Pico 2 W: https://www.raspberrypi.com/documentation/microcontrollers/pico-series.html#pico2w-technical-specification
108+
58109
Delay and timing
59110
----------------
60111

0 commit comments

Comments
 (0)