network.WLAN - how to read docs? #11432
-
|
I'm getting started with micropython on a Raspi rp2 Pico W. I'm a noob and having trouble understanding the documentation, and have been unsuccessful in finding "how to read the documentation" documentation. Specifically, this document is at the heart of my issues: https://docs.micropython.org/en/latest/library/network.WLAN.html. I am having trouble getting my wifi going, following https://datasheets.raspberrypi.com/picow/connecting-to-the-internet-with-pico-w.pdf esp section 3.6 "Connecting to a wireless network" issue 1 - Where do i find how to translate the constants there to their values? network.WLAN.status() in that doc shows constants. I am getting several values, 2, -2, -3, but never "3" which in examples seems to be the value indicating a successful connection. Similarly, i thought to try the WLAN.connect() method. In many examples, you invoke it with I thought as part of troubleshooting, that i would specify the access point. The documentation says: Issue 2 - what is the third argument, Issue 3 - most important, i'd like to know how I might have found these answers myself if i were more experienced! thanks a pile! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
To connect to WiFi use something like this (changing network name and password): def do_connect():
import network
sta_if = network.WLAN(network.STA_IF)
ap = network.WLAN(network.AP_IF) # create access-point interface
ap.active(False) # deactivate the interface
if not sta_if.isconnected():
print('connecting to network...')
sta_if.active(True)
sta_if.connect("NETWORK_NAME", "PASSWORD")
while not sta_if.isconnected():
pass
print('network config:', sta_if.ifconfig())
a = sta_if.config('mac')
print('MAC {:02x}:{:02x}:{:02x}:{:02x}:{:02x}'.format(a[0],a[1],a[2],a[3],a[4]))In general you don't need to worry about the numeric values of the constants. The def foo(x, y, *, z):
print(x, y, z)must be called with foo(1, 2, z=3)
foo(1, y=2, z=3)but not foo(1, 2, 3)Language details are best learnt by following an online course on your PC. |
Beta Was this translation helpful? Give feedback.
To connect to WiFi use something like this (changing network name and password):
In general you don't need to worry abou…