Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
9c72c71c
Commit
9c72c71c
authored
Oct 19, 2015
by
danicampora
Browse files
cc3200: WLAN class can retrieve the existing instance.
parent
f4c50f1c
Changes
4
Hide whitespace changes
Inline
Side-by-side
cc3200/mods/modwlan.c
View file @
9c72c71c
...
...
@@ -829,21 +829,22 @@ STATIC mp_obj_t wlan_make_new (mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_k
mp_arg_val_t
args
[
MP_ARRAY_SIZE
(
wlan_init_args
)];
mp_arg_parse_all
(
n_args
,
all_args
,
&
kw_args
,
MP_ARRAY_SIZE
(
args
),
wlan_init_args
,
args
);
// check the peripheral id
if
(
args
[
0
].
u_int
!=
0
)
{
nlr_raise
(
mp_obj_new_exception_msg
(
&
mp_type_OSError
,
mpexception_os_resource_not_avaliable
));
}
// setup the object
wlan_obj_t
*
self
=
&
wlan_obj
;
self
->
base
.
type
=
(
mp_obj_t
)
&
mod_network_nic_type_wlan
;
// start the peripheral
wlan_init_helper
(
self
,
&
args
[
1
]);
// pass it to the sleep module
// give it to the sleep module
pyb_sleep_set_wlan_obj
(
self
);
if
(
n_args
>
1
||
n_kw
>
0
)
{
// check the peripheral id
if
(
args
[
0
].
u_int
!=
0
)
{
nlr_raise
(
mp_obj_new_exception_msg
(
&
mp_type_OSError
,
mpexception_os_resource_not_avaliable
));
}
// start the peripheral
wlan_init_helper
(
self
,
&
args
[
1
]);
}
return
(
mp_obj_t
)
self
;
}
...
...
docs/library/network.rst
View file @
9c72c71c
...
...
@@ -312,14 +312,22 @@ For example::
Constructors
------------
.. class:: WLAN(..)
.. class:: WLAN(
id=0, .
..)
Create a WLAN object, and optionally configure it. See ``init`` for params of configuration.
.. note::
The ``WLAN`` constructor is special in the sense that if no arguments besides the id are given,
it will return the already exisiting ``WLAN`` instance without re-configuring it. This is
because ``WLAN`` is a system feature of the WiPy. If the already existing instance is not
initialized it will do the same as the other constructors an will initialize it with default
values.
Methods
-------
.. method:: wlan.init(mode, \*, ssid,
security, key
, channel, antenna)
.. method:: wlan.init(mode, \*, ssid,
auth
, channel, antenna)
Set or get the WiFi network processor configuration.
...
...
@@ -329,34 +337,33 @@ For example::
- ``ssid`` is a string with the ssid name. Only needed when mode is ``WLAN.AP``.
- ``auth`` is a tuple with (sec, key). Security can be ``None``, ``WLAN.WEP``,
``WLAN.WPA`` or ``WLAN.WPA2``. The key is a string with the network password.
If ``sec
urity
`` is ``WLAN.WEP`` the key must be a string representing hexadecimal
If ``sec`` is ``WLAN.WEP`` the key must be a string representing hexadecimal
values (e.g. 'ABC1DE45BF'). Only needed when mode is ``WLAN.AP``.
- ``channel`` a number in the range 1-11. Only needed when mode is ``WLAN.AP``.
- ``antenna`` selects between the internal and the external antenna. Can be either
``WLAN.INT_ANT`` or ``WLAN.EXT
ERNAL
``.
``WLAN.INT_ANT`` or ``WLAN.EXT
_ANT
``.
For example, you can do::
# create and configure as an access point
nic.iwconfig
(mode=WLAN.AP, ssid='wipy-wlan',
security=
WLAN.WPA2,
key=
'www.wipy.io', channel=7, antenna=WLAN.INT
ERNAL
)
wlan.init
(mode=WLAN.AP, ssid='wipy-wlan',
auth=(
WLAN.WPA2,'www.wipy.io'
)
, channel=7, antenna=WLAN.INT
_ANT
)
or::
# configure as an station
nic.iwconfig(mode=WLAN.STA)
With no arguments given, the current configuration is returned as a namedtuple that looks like this:
``(mode=2, ssid='wipy-wlan', security=2, key='www.wipy.io', channel=5, antenna=0)``
wlan.init(mode=WLAN.STA)
.. method:: wlan.connect(ssid, \*, auth=None,
key=None,
bssid=None, timeout=5000)
.. method:: wlan.connect(ssid, \*, auth=None, bssid=None, timeout=5000)
Connect to a wifi access point using the given SSID, and other security
parameters.
- ``key`` is always a string, but if ``security`` is ``WLAN.WEP`` the key must be a string
representing hexadecimal values (e.g. 'ABC1DE45BF').
- ``bssid`` is the MAC address of the AP to connect to. Useful when there are several APs
with the same ssid.
- ``auth`` is a tuple with (sec, key). Security can be ``None``, ``WLAN.WEP``,
``WLAN.WPA`` or ``WLAN.WPA2``. The key is a string with the network password.
If ``sec`` is ``WLAN.WEP`` the key must be a string representing hexadecimal
values (e.g. 'ABC1DE45BF'). Only needed when mode is ``WLAN.AP``
- ``bssid`` is the MAC address of the AP to connect to. Useful when there are several
APs with the same ssid.
- ``timeout`` is the maximum time in milliseconds to wait for the connection to succeed.
.. method:: wlan.scan()
...
...
@@ -373,16 +380,36 @@ For example::
In case of STA mode, returns ``True`` if connected to a wifi access point and has a valid IP address.
In AP mode returns ``True`` when a station is connected. Returns ``False`` otherwise.
.. method:: wlan.ifconfig(if_id, config=['dhcp' or configtuple])
.. method:: wlan.ifconfig(if_id
=0
, config=['dhcp' or configtuple])
With no parameters given eturns a 4-tuple of ``(ip, subnet
mask, gateway, DNS
server)``.
With no parameters given eturns a 4-tuple of ``(ip, subnet
_
mask, gateway, DNS
_
server)``.
if ``'dhcp'`` is passed as a parameter then the DHCP client is enabled and the IP params
are negotiated with the AP.
if the 4-tuple config is given then a static IP is configured. For example::
nic.ifconfig(config=('192.168.0.4', '255.255.255.0', '192.168.0.1', '8.8.8.8'))
wlan.ifconfig(config=('192.168.0.4', '255.255.255.0', '192.168.0.1', '8.8.8.8'))
.. method:: wlan.mode([mode])
Get or set the WLAN mode.
.. method:: wlan.ssid([ssid])
Get or set the SSID when in AP mode.
.. method:: wlan.auth([auth])
Get or set the authentication type when in AP mode.
.. method:: wlan.channel([channel])
Get or set the channel (only applicable in AP mode).
.. method:: wlan.antenna([antenna])
Get or set the antenna type (external or internal).
.. method:: wlan.mac([mac_addr])
...
...
@@ -396,18 +423,15 @@ For example::
- ``handler`` is the function that gets called when the irq is triggered.
- ``wake`` must be ``machine.SLEEP``.
Returns a
callback
object.
Returns a
irq
object.
Constants
---------
.. data:: WLAN.STA
WiFi station mode
.. data:: WLAN.STA
.. data:: WLAN.AP
WiFi access point
mode
selects the WLAN
mode
.. data:: WLAN.WEP
.. data:: WLAN.WPA
...
...
tests/wipy/wlan/wlan.py
View file @
9c72c71c
...
...
@@ -22,7 +22,7 @@ def wait_for_connection(wifi, timeout=10):
print
(
'Connection failed!'
)
wifi
=
WLAN
()
wifi
=
WLAN
(
0
,
WLAN
.
STA
)
print
(
wifi
.
mode
()
==
WLAN
.
STA
)
print
(
wifi
.
antenna
()
==
WLAN
.
INT_ANT
)
...
...
@@ -103,7 +103,15 @@ print(wifi.isconnected() == False)
# test init again
wifi
.
init
(
WLAN
.
AP
,
ssid
=
'www.wipy.io'
,
auth
=
None
,
channel
=
5
,
antenna
=
WLAN
.
INT_ANT
)
print
(
wifi
.
mode
()
==
WLAN
.
AP
)
# get the current instance without re-init
wifi
=
WLAN
()
print
(
wifi
.
mode
()
==
WLAN
.
AP
)
wifi
=
WLAN
(
0
)
print
(
wifi
.
mode
()
==
WLAN
.
AP
)
# test the MAC address length
print
(
len
(
wifi
.
mac
())
==
6
)
# next ones MUST raise
...
...
tests/wipy/wlan/wlan.py.exp
View file @
9c72c71c
...
...
@@ -37,6 +37,9 @@ True
True
True
True
True
True
True
Exception
Exception
Exception
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment