class WINC – WiFi shield driver¶
The WINC class drives the Atmel WINC1500 802.11 b/g/n WiFi
module on the OpenMV WiFi Shield. Available on the OpenMV Cam M4, M7,
H7, H7 Plus and Pure Thermal (the STM32 boards that the WiFi shield
was designed for). For boards with built-in WiFi (OpenMV Cam N6,
OpenMV Cam RT1062, Arduino Giga) use WLAN instead.
Example – connect to an access point and print the address:
import network
wlan = network.WINC()
wlan.connect("SSID", "KEY", security=network.WINC.WPA_PSK)
print("status: ", "connected" if wlan.isconnected() else "off")
print("rssi: ", wlan.rssi(), "dBm")
print("interface: ", wlan.ifconfig())
print("netinfo: ", wlan.netinfo())
Example – bring up an open access point and wait for a client:
import network
wlan = network.WINC(mode=network.WINC.MODE_AP)
wlan.start_ap("OpenMV-Cam", security=network.WINC.OPEN, channel=6)
print("waiting for a station to associate...")
print(wlan.wait_for_sta(timeout=None))
Constructors¶
- class network.WINC(mode: int = WINC.MODE_STA) None¶
Create a
WINCdriver object and bring up the WiFi shield.modeselects the operating mode the module starts in:WINC.MODE_STA– station / client. Connect to an access point withconnect(). This is the default.WINC.MODE_AP– access point. Configure the AP withstart_ap(), then accept client connections.WINC.MODE_P2P– WiFi Direct.WINC.MODE_BSP– bring up the BSP only (no radio).WINC.MODE_FIRMWARE– firmware-update mode; required byfw_dump()andfw_update().
Note
In AP mode the WINC1500 has hardware limits:
Only one client can connect at a time.
Only
OPENor WEP security are supported.A WiFi-module firmware bug causes any bound sockets to stop working when the client disconnects. Set a timeout on the server socket so it raises an exception that you can use to re-open it.
Methods¶
- active(is_active: bool | None = None) bool¶
Bring the WiFi shield up or down.
With no argument, return the current state –
Truewhile the shield is initialised and the radio is up,Falseotherwise.active(True)performs the WINC1500 firmware handshake over SPI and brings the radio up in the configuredmode. It is a no-op if the interface is already active.connect()auto-calls this if it has not been called yet; for any other method (scan(),rssi(),netinfo(), …) you must callactive(True)first.active(False)shuts the radio back down (the WINC drops to BSP-only mode) and releases the SPI pins.
- connect(ssid: str, key: str | None = None, *, security: int = WINC.WPA_PSK, channel: int = 1) None¶
Associate with the WiFi network
ssidusing passwordkey, security modesecurity(one ofOPEN,WPA_PSKor the 802.1X constant) on radiochannel.securityandchannelare keyword-only.After connecting use the
socketmodule to open TCP/UDP ports.This method blocks until the association completes or fails.
- config(ssid: str, key: str | None = None, *, security: int = WINC.WPA_PSK, channel: int = 1) None¶
Alias of
connect(). Provided for compatibility with code that callsconfigon othernetworkinterfaces.
- start_ap(ssid: str, key: str | None = None, *, security: int = WINC.OPEN, channel: int = 1) None¶
Alias of
connect()used after constructing the object withmode=MODE_APto configure and start the access point. The AP only supportsOPENor WEP security; if WEP is usedkeyis required.
- disconnect() None¶
In STA mode, disassociate from the currently associated access point. The shield stays active; call
connect()to re-associate. No-op when not currently associated.
- isconnected() bool¶
In STA mode return
Truewhen associated with an access point and an IPv4 address has been obtained (via DHCP orifconfig()). ReturnsFalsewhile still in the authenticating / associating / DHCP phase.
- connected_sta() List[str]¶
In AP mode, return a list containing the IP address of the currently connected client (or an empty list if no client is connected).
- wait_for_sta(timeout: int | None) List[str]¶
In AP mode, block until a client connects and return a list containing the client’s IP address.
timeoutis the maximum wait in milliseconds; passNoneto wait indefinitely.
- ifconfig(config: Tuple[str, str, str, str] | None = None) Tuple[str, str, str, str]¶
Get or set IPv4 interface parameters. The 4-tuple contains
(ip, subnet, gateway, dns)as dotted-quad strings.Called with no argument: returns the current configuration.
Called with a 4-tuple: sets a static IP configuration in place of the DHCP-acquired one.
Example – pin a static IP before connecting:
wlan = network.WINC() wlan.ifconfig(("192.168.1.100", "255.255.255.0", "192.168.1.1", "192.168.1.1")) wlan.connect(SSID, key=KEY, security=network.WINC.WPA_PSK)
Note
WINCdoes not implement the modernAbstractNIC.ipconfig()API; useifconfig()here.
- netinfo() Tuple[int, int, str, str, str]¶
Return a 5-tuple describing the current association:
[0]RSSI as an int (dBm).[1]Security mode – one of the security constants.[2]SSID string.[3]BSSID as an"XX:XX:XX:XX:XX:XX"MAC string.[4]IPv4 address as a dotted-quad string.
- scan() List[Tuple[str, str, int, int, int, int]]¶
Scan for nearby access points. Returns a list of 6-tuples:
[0]SSID string.[1]BSSID as an"XX:XX:XX:XX:XX:XX"MAC string.[2]Channel number.[3]RSSI in dBm.[4]Security mode – one of the security constants.[5]Reserved (always1).
Can be called without first associating with a network.
- rssi() int¶
Return the RSSI in dBm of the currently associated access point. Roughly:
-30is excellent,-67is OK for streaming,-80is marginal,-90and below is unusable. Only meaningful in STA mode whileisconnected()isTrue.
- fw_version() Tuple[int, int, int, int, int, int, int]¶
Return a 7-tuple describing the WINC1500 firmware and driver versions:
[0]Firmware major.[1]Firmware minor.[2]Firmware patch.[3]Driver major.[4]Driver minor.[5]Driver patch.[6]Chip hardware revision.
- fw_dump(path: str) None¶
Read the WINC1500’s internal flash and write the resulting firmware image to the file at
pathon the OpenMV’s filesystem. Use this to back up the currently-installed image before callingfw_update().Requires the module to have been constructed with
mode=MODE_FIRMWARE.
- fw_update(path: str) None¶
Erase the WINC1500’s internal flash and program it with the binary image at
path. The image must match the layout expected by the OpenMV firmware (typically supplied by Atmel / Microchip with the WINC SDK).The call blocks for several seconds while the flash is programmed and verified. Power-cycle the OpenMV Cam after the call returns so the WINC1500 starts from the new image.
Requires the module to have been constructed with
mode=MODE_FIRMWARE.
Constants¶
- OPEN: int¶
Security value for an unencrypted network. Pass to the
securityargument ofconnect()/start_ap().
Note
A WPA/WPA2 Enterprise (802.1X) security value also exists. The firmware exposes it under the name
802_1X, which is not a valid Python identifier – access it viagetattr(network.WINC, "802_1X").- MODE_BSP: int¶
Initialise the WINC board-support package only – the radio is not brought up. Used by the firmware-update flow.
- MODE_FIRMWARE: int¶
Firmware-update mode. Required by
fw_dump()andfw_update().