Get current Wifi object
Get current Wifi object
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
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
- danicampora
- Posts: 342
- Joined: Tue Sep 30, 2014 7:20 am
- Contact:
Re: Get current Wifi object
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:
If you can connect via telnet, you already know the IP address, don't you?
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
Re: Get current Wifi object
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.
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.
- danicampora
- Posts: 342
- Joined: Tue Sep 30, 2014 7:20 am
- Contact:
Re: Get current Wifi object
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:
But for this we need a way to retrieve the existing WLAN object...
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(...)
Re: Get current Wifi object
Ok. I guess the same applies to USB objects as well.
- danicampora
- Posts: 342
- Joined: Tue Sep 30, 2014 7:20 am
- Contact:
Re: Get current Wifi object
Yes, probably.Ok. I guess the same applies to USB objects as well.
Re: Get current Wifi object
+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.
- danicampora
- Posts: 342
- Joined: Tue Sep 30, 2014 7:20 am
- Contact:
Re: Get current Wifi object
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/
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/
Re: Get current Wifi object
that was quick! thank you very much for your great work!
-
- Posts: 8
- Joined: Fri Oct 16, 2015 7:36 pm
Re: Get current Wifi object
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.danicampora wrote:BTW docs are up to date now (for the most part): http://micropython.org/resources/docs/en/latest/wipy/