This module provides network drivers and routing configuration. Network
drivers for specific hardware are available within this module and are
used to configure a hardware network interface. Configured interfaces
are then available for use via the
# configure a specific network interface # see below for examples of specific drivers import network nic = network.Driver(...) print(nic.ifconfig()) # now use socket as usual import socket addr = socket.getaddrinfo('micropython.org', 80)[-1] s = socket.socket() s.connect(addr) s.send(b'GET / HTTP/1.1\r\nHost: micropython.org\r\n\r\n') data = s.recv(1000) s.close()
This class provides a driver for WiFi network processor in the ESP8266. Example usage:
import network # setup as a station nic = network.WLAN() nic.connect('your-ssid', 'your-password') # now use socket as usual
Connect to the specified wireless network, using the specified password.
Disconnect from the currently connected wireless network.
Initiate scanning for the available wireless networks.
Scanning is only possible if the radio is in station or station+AP mode; if called while in AP only mode, an OSError exception will be raised.
Once the scanning is complete, the provided callback function
cbwill be called once for each network found, and passed a tuple with information about that network:(ssid, bssid, channel, RSSI, authmode, hidden)
There are five values for authmode:
- 0 – open
- 1 – WEP
- 2 – WPA-PSK
- 3 – WPA2-PSK
- 4 – WPA/WPA2-PSK
and two for hidden:
- 0 – visible
- 1 – hidden
Return the current status of the wireless connection.
The possible statuses are defined as constants:
STAT_IDLE– no connection and no activity,
STAT_CONNECTING– connecting in progress,
STAT_WRONG_PASSWORD– failed due to incorrect password,
STAT_NO_AP_FOUND– failed because no access point replied,
STAT_CONNECT_FAIL– failed due to other problems,
STAT_GOT_IP– connection susccessful.
In case of STA mode, returns
Trueif connected to a wifi access point and has a valid IP address. In AP mode returns
Truewhen a station is connected. Returns