micropython: add micropython component

This commit is contained in:
KY-zhang-X
2022-09-29 12:10:37 +08:00
parent 1514f1cb9b
commit dd76146324
2679 changed files with 354110 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
"""
machine test for the CC3200 based boards.
"""
import machine
import os
from network import WLAN
mch = os.uname().machine
if not "LaunchPad" in mch and not "WiPy" in mch:
raise Exception("Board not supported!")
wifi = WLAN()
print(machine)
machine.idle()
print(machine.freq() == (80000000,))
print(machine.unique_id() == wifi.mac())
machine.main("main.py")
rand_nums = []
for i in range(0, 100):
rand = machine.rng()
if rand not in rand_nums:
rand_nums.append(rand)
else:
print("RNG number repeated")
break
for i in range(0, 10):
machine.idle()
print("Active")
print(machine.reset_cause() >= 0)
print(machine.wake_reason() >= 0)
try:
machine.main(123456)
except:
print("Exception")

View File

@@ -0,0 +1,7 @@
<module 'umachine'>
True
True
Active
True
True
Exception

View File

@@ -0,0 +1,41 @@
"""
network server test for the CC3200 based boards.
"""
import os
import network
mch = os.uname().machine
if not "LaunchPad" in mch and not "WiPy" in mch:
raise Exception("Board not supported!")
server = network.Server()
print(server.timeout() == 300)
print(server.isrunning() == True)
server.deinit()
print(server.isrunning() == False)
server.init(login=("test-user", "test-password"), timeout=60)
print(server.isrunning() == True)
print(server.timeout() == 60)
server.deinit()
print(server.isrunning() == False)
server.init()
print(server.isrunning() == True)
try:
server.init(1)
except:
print("Exception")
try:
server.init(0, login=("0000000000011111111111222222222222333333", "abc"))
except:
print("Exception")
try:
server.timeout(1)
except:
print("Exception")

View File

@@ -0,0 +1,10 @@
True
True
True
True
True
True
True
Exception
Exception
Exception

View File

@@ -0,0 +1,183 @@
"""
WLAN test for the CC3200 based boards.
"""
from network import WLAN
import os
import time
import testconfig
mch = os.uname().machine
if not "LaunchPad" in mch and not "WiPy" in mch:
raise Exception("Board not supported!")
def wait_for_connection(wifi, timeout=10):
while not wifi.isconnected() and timeout > 0:
time.sleep(1)
timeout -= 1
if wifi.isconnected():
print("Connected")
else:
print("Connection failed!")
wifi = WLAN(0, WLAN.STA)
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)
wifi = WLAN(0, mode=WLAN.AP, ssid="test-wlan", auth=(WLAN.WPA, "123456abc"), channel=7)
print(wifi.mode() == WLAN.AP)
print(wifi.channel() == 7)
print(wifi.ssid() == "test-wlan")
print(wifi.auth() == (WLAN.WPA, "123456abc"))
print(wifi.antenna() == WLAN.INT_ANT)
wifi = WLAN(mode=WLAN.STA)
print(wifi.mode() == WLAN.STA)
time.sleep(5) # this ensures a full network scan
scan_r = wifi.scan()
print(len(scan_r) > 3)
for net in scan_r:
if net.ssid == testconfig.wlan_ssid:
# 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)
print("Network found")
break
wifi.mode(WLAN.STA)
print(wifi.mode() == WLAN.STA)
wifi.channel(7)
print(wifi.channel() == 7)
wifi.ssid("t-wlan")
print(wifi.ssid() == "t-wlan")
wifi.auth(None)
print(wifi.auth() == None)
wifi.auth((WLAN.WEP, "11223344556677889900"))
print(wifi.auth() == (WLAN.WEP, "11223344556677889900"))
wifi.antenna(WLAN.INT_ANT)
print(wifi.antenna() == WLAN.INT_ANT)
wifi.antenna(WLAN.EXT_ANT)
print(wifi.antenna() == WLAN.EXT_ANT)
time.sleep(2) # this ensures a full network scan
scan_r = wifi.scan()
print(len(scan_r) > 3)
for net in scan_r:
if net.ssid == testconfig.wlan_ssid:
print("Network found")
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)
wifi.ifconfig(config="dhcp")
wait_for_connection(wifi)
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"))
wait_for_connection(wifi)
print(wifi.ifconfig(0) == ("192.168.178.109", "255.255.255.0", "192.168.178.1", "8.8.8.8"))
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
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
try:
wifi.init(mode=12345)
except:
print("Exception")
try:
wifi.init(1, mode=WLAN.AP)
except:
print("Exception")
try:
wifi.init(mode=WLAN.AP, ssid=None)
except:
print("Exception")
try:
wifi = WLAN(mode=WLAN.AP, channel=12)
except:
print("Exception")
try:
wifi.antenna(2)
except:
print("Exception")
try:
wifi.mode(10)
except:
print("Exception")
try:
wifi.ssid(
"11111sdfasdfasdfasdf564sdf654asdfasdf123451245ssdgfsdf1111111111111111111111111234123412341234asdfasdf"
)
except:
print("Exception")
try:
wifi.auth((0))
except:
print("Exception")
try:
wifi.auth((0, None))
except:
print("Exception")
try:
wifi.auth((10, 10))
except:
print("Exception")
try:
wifi.channel(0)
except:
print("Exception")
try:
wifi.ifconfig(1, "dhcp")
except:
print("Exception")
try:
wifi.ifconfig(config=())
except:
print("Exception")

View File

@@ -0,0 +1,55 @@
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
Network found
True
True
True
True
True
True
True
True
Network found
True
Connected
Connected
True
Connected
True
Connected
True
True
True
True
True
True
True
True
Exception
Exception
Exception
Exception
Exception
Exception
Exception
Exception
Exception
Exception
Exception
Exception
Exception