Get current Wifi object

Questions and discussion about The WiPy 1.0 board and CC3200 boards.
Target audience: Users with a WiPy 1.0 or CC3200 board.
oli
Posts: 17
Joined: Wed Aug 05, 2015 9:13 am

Get current Wifi object

Post by oli » Mon Oct 19, 2015 6:14 am

Hi,

is there a way to get the current wifi-object? if i start the wipy and connect to it, i can login via telnet. but how to get current wifi-object to get my ipaddress, and can send network packets and stuff like that...

thanks in advance!
Regards
Oli

User avatar
danicampora
Posts: 342
Joined: Tue Sep 30, 2014 7:20 am
Contact:

Re: Get current Wifi object

Post by danicampora » Mon Oct 19, 2015 7:28 am

The new API doesn't allow to get objects without re-initializing them, but I've been thinking for a while that perhaps WLAN could make an exception in this area, since it's always enabled and because it is a "system" feature of the WiPy.

However:

Code: Select all

is there a way to get the current wifi-object? if i start the wipy and connect to it, i can login via telnet
If you can connect via telnet, you already know the IP address, don't you?

Damien
Site Admin
Posts: 647
Joined: Mon Dec 09, 2013 5:02 pm

Re: Get current Wifi object

Post by Damien » Mon Oct 19, 2015 9:42 am

To send network packets you just use sockets as normal. You don't need to know the network adaptor object.

But if you did want to have access to the network object then you can save it to a global variable when it's first created in boot.py.

User avatar
danicampora
Posts: 342
Joined: Tue Sep 30, 2014 7:20 am
Contact:

Re: Get current Wifi object

Post by danicampora » Mon Oct 19, 2015 9:53 am

Imagine the scenario where your boot.py changes WLAN mode to station, configures a static IP and then connects to your home router, this way you know the address and you can telnet. You also need to be able to soft reset the board, and keep the connection alive, but, boot.py runs after the soft reset, so WLAN will be reconfigured and you will be disconnected. One way to sort it out is:

Code: Select all

import machine
from network import WLAN

wlan = WLAN()
if machine.reset_cause() != machine.SOFT_RESET:
	# init as STA, set static IP and connect
	wlan.init(mode=WLAN.STA)
	...
else if not wlan.isconnected():
	wlan.connect(...)
But for this we need a way to retrieve the existing WLAN object...

Damien
Site Admin
Posts: 647
Joined: Mon Dec 09, 2013 5:02 pm

Re: Get current Wifi object

Post by Damien » Mon Oct 19, 2015 10:08 am

Ok. I guess the same applies to USB objects as well.

User avatar
danicampora
Posts: 342
Joined: Tue Sep 30, 2014 7:20 am
Contact:

Re: Get current Wifi object

Post by danicampora » Mon Oct 19, 2015 10:14 am

Ok. I guess the same applies to USB objects as well.
Yes, probably.

alanb
Posts: 6
Joined: Sat Oct 17, 2015 3:39 pm

Re: Get current Wifi object

Post by alanb » Tue Oct 20, 2015 3:27 am

+1 for a way to get the current wifi object. I was hoping to setup exactly what you suggested where you don't drop the connection across soft resets.

User avatar
danicampora
Posts: 342
Joined: Tue Sep 30, 2014 7:20 am
Contact:

Re: Get current Wifi object

Post by danicampora » Tue Oct 20, 2015 7:26 am

Already implemented in: https://github.com/micropython/micropyt ... a5c513c9a7

I will release a new software version, end of this week. BTW docs are up to date now (for the most part): http://micropython.org/resources/docs/en/latest/wipy/

oli
Posts: 17
Joined: Wed Aug 05, 2015 9:13 am

Re: Get current Wifi object

Post by oli » Tue Oct 20, 2015 7:45 am

that was quick! thank you very much for your great work!

birkenfeld
Posts: 8
Joined: Fri Oct 16, 2015 7:36 pm

Re: Get current Wifi object

Post by birkenfeld » Tue Oct 20, 2015 4:49 pm

danicampora wrote:BTW docs are up to date now (for the most part): http://micropython.org/resources/docs/en/latest/wipy/
This is great! Thanks for the hard work. You might want to remove the link to the GitHub wiki page from http://forum.micropython.org/viewtopic.php?f=11&t=713 now.

Post Reply