Tested with real device and works for me with ESP32. Note that
__getattr__ is called only when accessing an undefined attribute. Here is a bit cleaned up code:
Code: Select all
import network
class wlan:
def __init__(self, mode):
self._station = network.WLAN(mode)
self._station.active(True)
def __getattr__(self, name):
return getattr(self._station, name)
Tested from REPL:
Code: Select all
MicroPython ESP32_LoBo_v3.2.24 - 2018-09-06 on ESP32 board with ESP32
Type "help()" for more information.
>>> import network
>>> from wlan import wlan
>>>
>>> wifi = wlan(network.STA_IF)
>>> wifi.scan
<bound_method>
>>> wifi.scan()
[(b'Manny-3BB', b'd\x12l\x00\xf1\xf0', 1, -79, 4, 'WPA_WPA2_PSK', False), (b'Myroom119819', b'\x04OLc7H', 8, -79, 4, 'WPA_WPA2_PSK', False), (b'Fcape1', b'\x03\x17\xd6\xf5s=', 6, -82, 0, 'OPEN', False),... rest removed]