Reputation: 1
I use this code for an asynchronous web server and it works fine:
https://gist.github.com/aallan/3d45a062f26bc425b22a17ec9c81e3b6
EDIT : This link is my only code, so it's easy to reproduce the issue
Problem is, I cant find a way to disable wlan.
The original code is like that: (in different locations, check code)
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
So I simply try:
wlan.active(False)
But the web server is still running and print(wlan.active())
returns True...
I tried placing it at MANY locations in the asynchronous web server code, but I coudldnt make it work.
I need to disable the wlan entirely from time to time and I cant make it work... spent the whole day on it.
Thank you!
EDIT 2 : More details after testing
>>> wlan.active(True)
>>> print(wlan.active())
True # as expected
>>> wlan.active(False)
>>> print(wlan.active())
True # ???
>>> wlan.disconnect()
>>> print(wlan.active())
False # ???
wlan.disconnect()
seems to put the wlan interface down, which should be what wlan.active(False)
does, and it doesnt even do it in fact, because a simple wlan.connect(ssid, password)
gets the wlan.active(True)
again by itself... so it wasnt really False.
Oh and wlan.active(False)
doest not work, at all. There is no scenario where it has any effect.
If someone could explain me that... Thank you
Upvotes: 0
Views: 1568
Reputation: 31
I had the same issue, and after some experimentation and digging in the code I found the solution. You have to call the (undocumented) wlan.deinit()
method:
def disconnect():
wlan.disconnect()
wlan.active(False)
wlan.deinit()
This will deactivate the wifi chip and reduce the power usage of the board accordingly.
Upvotes: 2