2020-03-23 02:26:08 +00:00
|
|
|
"""
|
2015-09-26 20:55:24 +00:00
|
|
|
WLAN test for the CC3200 based boards.
|
2020-03-23 02:26:08 +00:00
|
|
|
"""
|
2015-09-26 20:55:24 +00:00
|
|
|
|
|
|
|
from network import WLAN
|
|
|
|
import os
|
|
|
|
import time
|
|
|
|
import testconfig
|
|
|
|
|
2015-09-27 11:45:48 +00:00
|
|
|
mch = os.uname().machine
|
2020-03-23 02:26:08 +00:00
|
|
|
if not "LaunchPad" in mch and not "WiPy" in mch:
|
|
|
|
raise Exception("Board not supported!")
|
2015-09-26 20:55:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
def wait_for_connection(wifi, timeout=10):
|
|
|
|
while not wifi.isconnected() and timeout > 0:
|
|
|
|
time.sleep(1)
|
|
|
|
timeout -= 1
|
|
|
|
if wifi.isconnected():
|
2020-03-23 02:26:08 +00:00
|
|
|
print("Connected")
|
2015-09-26 20:55:24 +00:00
|
|
|
else:
|
2020-03-23 02:26:08 +00:00
|
|
|
print("Connection failed!")
|
2015-09-26 20:55:24 +00:00
|
|
|
|
|
|
|
|
2015-10-19 18:53:02 +00:00
|
|
|
wifi = WLAN(0, WLAN.STA)
|
2015-09-26 20:55:24 +00:00
|
|
|
print(wifi.mode() == WLAN.STA)
|
|
|
|
print(wifi.antenna() == WLAN.INT_ANT)
|
|
|
|
|
|
|
|
wifi = WLAN(mode=WLAN.AP)
|
|
|
|
print(wifi.mode() == WLAN.AP)
|
|
|
|
print(wifi.channel() == 1)
|
|
|
|
print(wifi.auth() == None)
|
|
|
|
print(wifi.antenna() == WLAN.INT_ANT)
|
2020-03-23 02:26:08 +00:00
|
|
|
wifi = WLAN(0, mode=WLAN.AP, ssid="test-wlan", auth=(WLAN.WPA, "123456abc"), channel=7)
|
2015-09-26 20:55:24 +00:00
|
|
|
print(wifi.mode() == WLAN.AP)
|
|
|
|
print(wifi.channel() == 7)
|
2020-03-23 02:26:08 +00:00
|
|
|
print(wifi.ssid() == "test-wlan")
|
|
|
|
print(wifi.auth() == (WLAN.WPA, "123456abc"))
|
2015-09-26 20:55:24 +00:00
|
|
|
print(wifi.antenna() == WLAN.INT_ANT)
|
|
|
|
|
|
|
|
wifi = WLAN(mode=WLAN.STA)
|
|
|
|
print(wifi.mode() == WLAN.STA)
|
2020-03-23 02:26:08 +00:00
|
|
|
time.sleep(5) # this ensures a full network scan
|
2015-09-26 20:55:24 +00:00
|
|
|
scan_r = wifi.scan()
|
|
|
|
print(len(scan_r) > 3)
|
|
|
|
for net in scan_r:
|
|
|
|
if net.ssid == testconfig.wlan_ssid:
|
2015-10-14 07:45:37 +00:00
|
|
|
# test that the scan results contains the desired params
|
|
|
|
print(len(net.bssid) == 6)
|
|
|
|
print(net.channel == None)
|
|
|
|
print(net.sec == testconfig.wlan_auth[0])
|
|
|
|
print(net.rssi < 0)
|
2020-03-23 02:26:08 +00:00
|
|
|
print("Network found")
|
2015-09-26 20:55:24 +00:00
|
|
|
break
|
|
|
|
|
|
|
|
wifi.mode(WLAN.STA)
|
|
|
|
print(wifi.mode() == WLAN.STA)
|
|
|
|
wifi.channel(7)
|
|
|
|
print(wifi.channel() == 7)
|
2020-03-23 02:26:08 +00:00
|
|
|
wifi.ssid("t-wlan")
|
|
|
|
print(wifi.ssid() == "t-wlan")
|
2015-09-26 20:55:24 +00:00
|
|
|
wifi.auth(None)
|
|
|
|
print(wifi.auth() == None)
|
2020-03-23 02:26:08 +00:00
|
|
|
wifi.auth((WLAN.WEP, "11223344556677889900"))
|
|
|
|
print(wifi.auth() == (WLAN.WEP, "11223344556677889900"))
|
2015-09-26 20:55:24 +00:00
|
|
|
wifi.antenna(WLAN.INT_ANT)
|
|
|
|
print(wifi.antenna() == WLAN.INT_ANT)
|
|
|
|
|
|
|
|
wifi.antenna(WLAN.EXT_ANT)
|
|
|
|
print(wifi.antenna() == WLAN.EXT_ANT)
|
2020-03-23 02:26:08 +00:00
|
|
|
time.sleep(2) # this ensures a full network scan
|
2015-09-26 20:55:24 +00:00
|
|
|
scan_r = wifi.scan()
|
|
|
|
print(len(scan_r) > 3)
|
|
|
|
for net in scan_r:
|
|
|
|
if net.ssid == testconfig.wlan_ssid:
|
2020-03-23 02:26:08 +00:00
|
|
|
print("Network found")
|
2015-09-26 20:55:24 +00:00
|
|
|
break
|
|
|
|
|
|
|
|
wifi.antenna(WLAN.INT_ANT)
|
|
|
|
wifi.mode(WLAN.STA)
|
|
|
|
print(wifi.mode() == WLAN.STA)
|
|
|
|
wifi.connect(testconfig.wlan_ssid, auth=testconfig.wlan_auth, timeout=10000)
|
|
|
|
wait_for_connection(wifi)
|
|
|
|
|
2020-03-23 02:26:08 +00:00
|
|
|
wifi.ifconfig(config="dhcp")
|
2015-09-26 20:55:24 +00:00
|
|
|
wait_for_connection(wifi)
|
2020-03-23 02:26:08 +00:00
|
|
|
print("0.0.0.0" not in wifi.ifconfig())
|
|
|
|
wifi.ifconfig(0, ("192.168.178.109", "255.255.255.0", "192.168.178.1", "8.8.8.8"))
|
2015-09-26 20:55:24 +00:00
|
|
|
wait_for_connection(wifi)
|
2020-03-23 02:26:08 +00:00
|
|
|
print(wifi.ifconfig(0) == ("192.168.178.109", "255.255.255.0", "192.168.178.1", "8.8.8.8"))
|
2015-09-26 20:55:24 +00:00
|
|
|
wait_for_connection(wifi)
|
|
|
|
|
|
|
|
print(wifi.isconnected() == True)
|
|
|
|
wifi.disconnect()
|
|
|
|
print(wifi.isconnected() == False)
|
|
|
|
|
|
|
|
t0 = time.ticks_ms()
|
|
|
|
wifi.connect(testconfig.wlan_ssid, auth=testconfig.wlan_auth, timeout=0)
|
|
|
|
print(time.ticks_ms() - t0 < 500)
|
|
|
|
|
|
|
|
wifi.disconnect()
|
|
|
|
print(wifi.isconnected() == False)
|
|
|
|
|
|
|
|
# test init again
|
2020-03-23 02:26:08 +00:00
|
|
|
wifi.init(WLAN.AP, ssid="www.wipy.io", auth=None, channel=5, antenna=WLAN.INT_ANT)
|
2015-10-19 18:53:02 +00:00
|
|
|
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)
|
2015-09-26 20:55:24 +00:00
|
|
|
|
2015-10-19 18:53:02 +00:00
|
|
|
# test the MAC address length
|
2015-09-27 16:00:36 +00:00
|
|
|
print(len(wifi.mac()) == 6)
|
2015-09-27 15:04:49 +00:00
|
|
|
|
2015-09-26 20:55:24 +00:00
|
|
|
# next ones MUST raise
|
|
|
|
try:
|
|
|
|
wifi.init(mode=12345)
|
|
|
|
except:
|
2020-03-23 02:26:08 +00:00
|
|
|
print("Exception")
|
2015-09-26 20:55:24 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
wifi.init(1, mode=WLAN.AP)
|
|
|
|
except:
|
2020-03-23 02:26:08 +00:00
|
|
|
print("Exception")
|
2015-09-26 20:55:24 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
wifi.init(mode=WLAN.AP, ssid=None)
|
|
|
|
except:
|
2020-03-23 02:26:08 +00:00
|
|
|
print("Exception")
|
2015-09-26 20:55:24 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
wifi = WLAN(mode=WLAN.AP, channel=12)
|
|
|
|
except:
|
2020-03-23 02:26:08 +00:00
|
|
|
print("Exception")
|
2015-09-26 20:55:24 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
wifi.antenna(2)
|
|
|
|
except:
|
2020-03-23 02:26:08 +00:00
|
|
|
print("Exception")
|
2015-09-26 20:55:24 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
wifi.mode(10)
|
|
|
|
except:
|
2020-03-23 02:26:08 +00:00
|
|
|
print("Exception")
|
2015-09-26 20:55:24 +00:00
|
|
|
|
|
|
|
try:
|
2020-03-23 02:26:08 +00:00
|
|
|
wifi.ssid(
|
|
|
|
"11111sdfasdfasdfasdf564sdf654asdfasdf123451245ssdgfsdf1111111111111111111111111234123412341234asdfasdf"
|
|
|
|
)
|
2015-09-26 20:55:24 +00:00
|
|
|
except:
|
2020-03-23 02:26:08 +00:00
|
|
|
print("Exception")
|
2015-09-26 20:55:24 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
wifi.auth((0))
|
|
|
|
except:
|
2020-03-23 02:26:08 +00:00
|
|
|
print("Exception")
|
2015-09-26 20:55:24 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
wifi.auth((0, None))
|
|
|
|
except:
|
2020-03-23 02:26:08 +00:00
|
|
|
print("Exception")
|
2015-09-26 20:55:24 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
wifi.auth((10, 10))
|
|
|
|
except:
|
2020-03-23 02:26:08 +00:00
|
|
|
print("Exception")
|
2015-09-26 20:55:24 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
wifi.channel(0)
|
|
|
|
except:
|
2020-03-23 02:26:08 +00:00
|
|
|
print("Exception")
|
2015-09-26 20:55:24 +00:00
|
|
|
|
|
|
|
try:
|
2020-03-23 02:26:08 +00:00
|
|
|
wifi.ifconfig(1, "dhcp")
|
2015-09-26 20:55:24 +00:00
|
|
|
except:
|
2020-03-23 02:26:08 +00:00
|
|
|
print("Exception")
|
2015-09-26 20:55:24 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
wifi.ifconfig(config=())
|
|
|
|
except:
|
2020-03-23 02:26:08 +00:00
|
|
|
print("Exception")
|