Skip to content

Commit 48f96e9

Browse files
projectgusdpgeorge
authored andcommitted
docs: Specify the recommended network.WLAN.IF_[AP|STA] constants.
Removes the deprecated network.[AP|STA]_IF form from the docs. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <[email protected]>
1 parent df6b40a commit 48f96e9

File tree

6 files changed

+34
-32
lines changed

6 files changed

+34
-32
lines changed

docs/esp32/quickref.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,19 @@ Networking
7979
WLAN
8080
^^^^
8181

82-
The :mod:`network` module::
82+
The :class:`network.WLAN` class in the :mod:`network` module::
8383

8484
import network
8585

86-
wlan = network.WLAN(network.STA_IF) # create station interface
86+
wlan = network.WLAN(network.WLAN.IF_STA) # create station interface
8787
wlan.active(True) # activate the interface
8888
wlan.scan() # scan for access points
8989
wlan.isconnected() # check if the station is connected to an AP
9090
wlan.connect('ssid', 'key') # connect to an AP
9191
wlan.config('mac') # get the interface's MAC address
9292
wlan.ipconfig('addr4') # get the interface's IPv4 addresses
9393

94-
ap = network.WLAN(network.AP_IF) # create access-point interface
94+
ap = network.WLAN(network.WLAN.IF_AP) # create access-point interface
9595
ap.config(ssid='ESP-AP') # set the SSID of the access point
9696
ap.config(max_clients=10) # set how many clients can connect to the network
9797
ap.active(True) # activate the interface
@@ -100,7 +100,7 @@ A useful function for connecting to your local WiFi network is::
100100

101101
def do_connect():
102102
import network
103-
wlan = network.WLAN(network.STA_IF)
103+
wlan = network.WLAN(network.WLAN.IF_STA)
104104
wlan.active(True)
105105
if not wlan.isconnected():
106106
print('connecting to network...')
@@ -124,7 +124,8 @@ to reconnect forever).
124124
LAN
125125
^^^
126126

127-
To use the wired interfaces one has to specify the pins and mode ::
127+
To use the wired interfaces via :class:`network.LAN` one has to specify the pins
128+
and mode ::
128129

129130
import network
130131

docs/esp8266/quickref.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,27 +49,27 @@ The :mod:`esp` module::
4949
Networking
5050
----------
5151

52-
The :mod:`network` module::
52+
The :class:`network.WLAN` class in the :mod:`network` module::
5353

5454
import network
5555

56-
wlan = network.WLAN(network.STA_IF) # create station interface
56+
wlan = network.WLAN(network.WLAN.IF_STA) # create station interface
5757
wlan.active(True) # activate the interface
5858
wlan.scan() # scan for access points
5959
wlan.isconnected() # check if the station is connected to an AP
6060
wlan.connect('ssid', 'key') # connect to an AP
6161
wlan.config('mac') # get the interface's MAC address
6262
wlan.ipconfig('addr4') # get the interface's IPv4 addresses
6363

64-
ap = network.WLAN(network.AP_IF) # create access-point interface
64+
ap = network.WLAN(network.WLAN.IF_AP) # create access-point interface
6565
ap.active(True) # activate the interface
6666
ap.config(ssid='ESP-AP') # set the SSID of the access point
6767

6868
A useful function for connecting to your local WiFi network is::
6969

7070
def do_connect():
7171
import network
72-
wlan = network.WLAN(network.STA_IF)
72+
wlan = network.WLAN(network.WLAN.IF_STA)
7373
wlan.active(True)
7474
if not wlan.isconnected():
7575
print('connecting to network...')

docs/esp8266/tutorial/network_basics.rst

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
Network basics
22
==============
33

4-
The network module is used to configure the WiFi connection. There are two WiFi
5-
interfaces, one for the station (when the ESP8266 connects to a router) and one
6-
for the access point (for other devices to connect to the ESP8266). Create
4+
The :class:`network.WLAN` class in the :mod:`network` module is used to
5+
configure the WiFi connection. There are two WiFi interfaces, one for
6+
the station (when the ESP8266 connects to a router) and one for the
7+
access point (for other devices to connect to the ESP8266). Create
78
instances of these objects using::
89

910
>>> import network
10-
>>> sta_if = network.WLAN(network.STA_IF)
11-
>>> ap_if = network.WLAN(network.AP_IF)
11+
>>> sta_if = network.WLAN(network.WLAN.IF_STA)
12+
>>> ap_if = network.WLAN(network.WLAN.IF_AP)
1213

1314
You can check if the interfaces are active by::
1415

@@ -57,7 +58,7 @@ connect to your WiFi network::
5758

5859
def do_connect():
5960
import network
60-
sta_if = network.WLAN(network.STA_IF)
61+
sta_if = network.WLAN(network.WLAN.IF_STA)
6162
if not sta_if.isconnected():
6263
print('connecting to network...')
6364
sta_if.active(True)

docs/library/espnow.rst

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ A simple example would be:
5656
import espnow
5757

5858
# A WLAN interface must be active to send()/recv()
59-
sta = network.WLAN(network.STA_IF) # Or network.AP_IF
59+
sta = network.WLAN(network.WLAN.IF_STA) # Or network.WLAN.IF_AP
6060
sta.active(True)
6161
sta.disconnect() # For ESP8266
6262

@@ -76,7 +76,7 @@ A simple example would be:
7676
import espnow
7777

7878
# A WLAN interface must be active to send()/recv()
79-
sta = network.WLAN(network.STA_IF)
79+
sta = network.WLAN(network.WLAN.IF_STA)
8080
sta.active(True)
8181
sta.disconnect() # Because ESP8266 auto-connects to last Access Point
8282

@@ -182,14 +182,14 @@ Configuration
182182
Sending and Receiving Data
183183
--------------------------
184184

185-
A wifi interface (``network.STA_IF`` or ``network.AP_IF``) must be
185+
A wifi interface (``network.WLAN.IF_STA`` or ``network.WLAN.IF_AP``) must be
186186
`active()<network.WLAN.active>` before messages can be sent or received,
187187
but it is not necessary to connect or configure the WLAN interface.
188188
For example::
189189

190190
import network
191191

192-
sta = network.WLAN(network.STA_IF)
192+
sta = network.WLAN(network.WLAN.IF_STA)
193193
sta.active(True)
194194
sta.disconnect() # For ESP8266
195195

@@ -445,8 +445,8 @@ must first register the sender and use the same encryption keys as the sender
445445

446446
- *ifidx*: (ESP32 only) Index of the wifi interface which will be
447447
used to send data to this peer. Must be an integer set to
448-
``network.STA_IF`` (=0) or ``network.AP_IF`` (=1).
449-
(default=0/``network.STA_IF``). See `ESPNow and Wifi Operation`_
448+
``network.WLAN.IF_STA`` (=0) or ``network.WLAN.IF_AP`` (=1).
449+
(default=0/``network.WLAN.IF_STA``). See `ESPNow and Wifi Operation`_
450450
below for more information.
451451

452452
- *encrypt*: (ESP32 only) If set to ``True`` data exchanged with
@@ -588,7 +588,7 @@ api-reference/network/esp_now.html#api-reference>`_. For example::
588588
elif err.args[1] == 'ESP_ERR_ESPNOW_NOT_FOUND':
589589
e.add_peer(peer)
590590
elif err.args[1] == 'ESP_ERR_ESPNOW_IF':
591-
network.WLAN(network.STA_IF).active(True)
591+
network.WLAN(network.WLAN.IF_STA).active(True)
592592
else:
593593
raise err
594594

@@ -645,7 +645,7 @@ A small async server example::
645645
import asyncio
646646

647647
# A WLAN interface must be active to send()/recv()
648-
network.WLAN(network.STA_IF).active(True)
648+
network.WLAN(network.WLAN.IF_STA).active(True)
649649

650650
e = aioespnow.AIOESPNow() # Returns AIOESPNow enhanced with async support
651651
e.active(True)
@@ -747,8 +747,8 @@ ESPNow and Wifi Operation
747747
-------------------------
748748

749749
ESPNow messages may be sent and received on any `active()<network.WLAN.active>`
750-
`WLAN<network.WLAN()>` interface (``network.STA_IF`` or ``network.AP_IF``), even
751-
if that interface is also connected to a wifi network or configured as an access
750+
`WLAN<network.WLAN()>` interface (``network.WLAN.IF_STA`` or ``network.WLAN.IF_AP``),
751+
even if that interface is also connected to a wifi network or configured as an access
752752
point. When an ESP32 or ESP8266 device connects to a Wifi Access Point (see
753753
`ESP32 Quickref <../esp32/quickref.html#networking>`__) the following things
754754
happen which affect ESPNow communications:
@@ -832,8 +832,8 @@ Other issues to take care with when using ESPNow with wifi are:
832832
import network, time
833833

834834
def wifi_reset(): # Reset wifi to AP_IF off, STA_IF on and disconnected
835-
sta = network.WLAN(network.STA_IF); sta.active(False)
836-
ap = network.WLAN(network.AP_IF); ap.active(False)
835+
sta = network.WLAN(network.WLAN.IF_STA); sta.active(False)
836+
ap = network.WLAN(network.WLAN.IF_AP); ap.active(False)
837837
sta.active(True)
838838
while not sta.active():
839839
time.sleep(0.1)

docs/library/network.WLAN.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This class provides a driver for WiFi network processors. Example usage::
88

99
import network
1010
# enable station interface and connect to WiFi access point
11-
nic = network.WLAN(network.STA_IF)
11+
nic = network.WLAN(network.WLAN.IF_STA)
1212
nic.active(True)
1313
nic.connect('your-ssid', 'your-key')
1414
# now use sockets as usual
@@ -18,8 +18,8 @@ Constructors
1818
.. class:: WLAN(interface_id)
1919

2020
Create a WLAN network interface object. Supported interfaces are
21-
``network.STA_IF`` (station aka client, connects to upstream WiFi access
22-
points) and ``network.AP_IF`` (access point, allows other WiFi clients to
21+
``network.WLAN.IF_STA`` (station aka client, connects to upstream WiFi access
22+
points) and ``network.WLAN.IF_AP`` (access point, allows other WiFi clients to
2323
connect). Availability of the methods below depends on interface type.
2424
For example, only STA interface may `WLAN.connect()` to an access point.
2525

@@ -75,7 +75,7 @@ Methods
7575
Return the current status of the wireless connection.
7676

7777
When called with no argument the return value describes the network link status.
78-
The possible statuses are defined as constants:
78+
The possible statuses are defined as constants in the :mod:`network` module:
7979

8080
* ``STAT_IDLE`` -- no connection and no activity,
8181
* ``STAT_CONNECTING`` -- connecting in progress,

docs/reference/mpremote.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ An example ``config.py`` might look like:
477477
""",], # Print out nearby WiFi networks.
478478
"wl_ipconfig": [
479479
"exec",
480-
"import network; sta_if = network.WLAN(network.STA_IF); print(sta_if.ipconfig('addr4'))",
480+
"import network; sta_if = network.WLAN(network.WLAN.IF_STA); print(sta_if.ipconfig('addr4'))",
481481
""",], # Print ip address of station interface.
482482
"test": ["mount", ".", "exec", "import test"], # Mount current directory and run test.py.
483483
"demo": ["run", "path/to/demo.py"], # Execute demo.py on the device.

0 commit comments

Comments
 (0)