Force network.WLAN module to disconnect?

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
Jibun no kage
Posts: 144
Joined: Mon Jul 25, 2022 9:45 pm

Force network.WLAN module to disconnect?

Post by Jibun no kage » Mon Jul 25, 2022 10:08 pm

How to force network.WLAN module to disconnect?

Code: Select all

    # Client/Station Mode...
    theInterface=network.WLAN(network.STA_IF)
    if theInterface is None:
        #
        raise Exception('No Network?')
    # Over kill?
    theInterface.active(True)
    theNetworks=theInterface.scan()
    
    theInterface.disconnect()
    theInterface.active(False)
    
The last line in the code example, does not seem to work. If watch the connection it remains. The documentation states that the link state should change to 'down' if False is passed. But that does not seem to be working. This a bug?

User avatar
karfas
Posts: 193
Joined: Sat Jan 16, 2021 12:53 pm
Location: Vienna, Austria

Re: Force network.WLAN module to disconnect?

Post by karfas » Thu Jul 28, 2022 2:55 pm

Jibun no kage wrote:
Mon Jul 25, 2022 10:08 pm
How to force network.WLAN module to disconnect?
The last line in the code example, does not seem to work. If watch the connection it remains. The documentation states that the link state should change to 'down' if False is passed. But that does not seem to be working.
You don't have any "connection", as you never call wlan.connect(). Where do you see that the interface is still active ?
A few hours of debugging might save you from minutes of reading the documentation! :D
My repositories: https://github.com/karfas

Jibun no kage
Posts: 144
Joined: Mon Jul 25, 2022 9:45 pm

Re: Force network.WLAN module to disconnect?

Post by Jibun no kage » Sat Jul 30, 2022 3:51 pm

If you set active to true, the link state is up, right? That means the interface is visible to the network. Link state on, will be sniffed out if searched for. Connect is higher in the OSI/ISO stack true, but I recall at work our security team could find devices by link state alone, since the connecting switch or router could 'see' link state of an end-node device. Is there something about link state, that is different with the specific driver used via network.WLAN?
Last edited by Jibun no kage on Sat Jul 30, 2022 3:54 pm, edited 1 time in total.

Jibun no kage
Posts: 144
Joined: Mon Jul 25, 2022 9:45 pm

Re: Force network.WLAN module to disconnect?

Post by Jibun no kage » Sat Jul 30, 2022 3:53 pm

Forgot to mention... when I did set to False, and watched my router, finally the device dropped of the connection list, so not sure if my router is just slow to show change of state, or what.

User avatar
curt
Posts: 25
Joined: Thu Jul 29, 2021 3:52 am
Location: Big Lake, Alaska

Re: Force network.WLAN module to disconnect?

Post by curt » Sat Jul 30, 2022 6:19 pm

I don't believe there is any requirement for network.WLAN to inform the router it's going away. You should see similar behaviour if you just unplugged the device.

Curt

Jibun no kage
Posts: 144
Joined: Mon Jul 25, 2022 9:45 pm

Re: Force network.WLAN module to disconnect?

Post by Jibun no kage » Tue Aug 02, 2022 2:18 am

Yeah, it may just be the router is doing a very low level state check,, or gives up on port that has gone inactive.

Post Reply