From 5539fd9d0f72ba97bb7c64fabfda6e3fb97b4de9 Mon Sep 17 00:00:00 2001 From: Daniel Campora Date: Mon, 21 Sep 2015 11:36:14 +0200 Subject: [PATCH] Add WLAN API --- Hardware-API.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/Hardware-API.md b/Hardware-API.md index 9d4b869..29455f9 100644 --- a/Hardware-API.md +++ b/Hardware-API.md @@ -324,6 +324,42 @@ Methods: - `wdt.feed()` feed the watchdog. - `wdt.deinit()` disable the WDT (again, might not be possible on some platforms, raise `OSError` in that case). +## The WLAN class + +The WLAN class belongs to the network module. + +Constructor: + +`wlan = WLAN(id, mode=WLAN.STA, *, ssid=`wlan`, auth=WLAN.OPEN, key=None, channel=1, bus=None, pins=None)` + +Methods: + +- `wlan.init()` re-init. +- `wlan.deinit()` disable the NIC. NOHEAP. +- `wlan.mode([mode])` set or get the mode. NOHEAP +- `wlan.ssid([ssid])` set or get our own SSID name +- `wlan.security([(auth, key)])` set or get the security configuration tuple +- `wlan.channel([channel])` set or get the channel. NOHEAP +- `wlan.scan()` perform a network scan and return a named tuple of the form: + `(ssid, bssid, security, channel, rssi)` +- `wlan.mac([mac])` get or set the MAC address. The MAC address is a `bytes` object of length 6. +- `wlan.connect(ssid, *, auth=WLAN.OPEN, key=None, timeout=None)` Connect to the network specified by the SSID using the given authentication and keys. +- `wlan.disconnect()` Closes the current connection. NOHEAP +- `wlan.isconnected()` returns `True` if connected and IP address has been assigned. +- `wlan.ifconfig(id=0, [(ip, netmask, gateway, dns) or 'dhcp'])` get or set the IP configuration. The `id` is the interface id, and defaults to zero. In the case of `AP+STA` mode, the NIC effectively has 2 interfaces that can be configured independently using `id=0` for the AP and `id=1` for the STA. Alternatively, a port can choose to use string names for the `id`, e.g. `id='STA'` and `id='AP'`. + +Constants: + +- `WLAN.STA` Station mode +- `WLAN.AP` Access point mode +- `WLAN.AP+STA` Access point + Station mode (sometimes called SoftAP) +- `WLAN.P2P` Peer to peer (also called WiFi-direct or Ad-Hoc mode) +- `WLAN.OPEN` Open authentication +- `WLAN.WEP` WEP authentication +- `WLAN.WPA` WPA authentication +- `WLAN.WPA2` WPA2 authentication + + # machine module - `machine.reset()` perform a hard reset (same as pressing the reset switch on the board)