Skip to content

Commit c86951b

Browse files
committed
feat(scripts): add test
1 parent a6423f0 commit c86951b

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed

scripts/test/https.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import network
2+
import time
3+
import urequests
4+
5+
# Configure the Wi-Fi interface
6+
wifi = network.WLAN(network.STA_IF)
7+
wifi.active(True)
8+
9+
# Connect to Wi-Fi
10+
def connect_to_wifi(ssid, password):
11+
wifi.connect(ssid, password)
12+
start_time = time.time()
13+
14+
# Wait for connection
15+
while not wifi.isconnected():
16+
if time.time() - start_time > 10:
17+
print("Connection timeout!")
18+
return False
19+
time.sleep(1)
20+
21+
print(f"Connected to {ssid}!")
22+
return True
23+
24+
# Fetch content via HTTPS
25+
def fetch_https(url):
26+
try:
27+
# Make the HTTPS request
28+
response = urequests.get(url, timeout=10)
29+
30+
# Print the response status and content
31+
print(f"Status Code: {response.status_code}")
32+
print("Response Body:")
33+
print(response.text)
34+
35+
response.close()
36+
except Exception as e:
37+
print("Error during HTTP request:", e)
38+
39+
# Get user input from the terminal
40+
def get_user_input():
41+
ssid = input("Enter Wi-Fi SSID: ")
42+
password = input("Enter Wi-Fi Password: ")
43+
url = input("Enter the URL to fetch via HTTPS: ")
44+
return ssid, password, url
45+
46+
# Main program
47+
ssid, password, url = get_user_input()
48+
49+
# Connect to Wi-Fi
50+
if not connect_to_wifi(ssid, password):
51+
print("Unable to connect to Wi-Fi.")
52+
else:
53+
# Fetch content via HTTPS
54+
fetch_https(url)

scripts/test/wifi_scan.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import network
2+
import time
3+
4+
# Configure the Wi-Fi interface
5+
wifi = network.WLAN(network.STA_IF)
6+
wifi.active(True)
7+
8+
# Scan for nearby networks
9+
def scan_networks():
10+
print("Scanning for nearby networks...")
11+
networks = wifi.scan()
12+
13+
if not networks:
14+
print("No networks found.")
15+
return
16+
17+
# Display the scan results
18+
print("Found the following networks:")
19+
for network in networks:
20+
ssid = network[0].decode('utf-8') # Name of the network
21+
bssid = network[1] # BSSID of the network
22+
channel = network[2] # Channel
23+
rssi = network[3] # Signal strength
24+
authmode = network[4] # Authentication mode
25+
hidden = network[5] # Whether the network is hidden
26+
27+
print(f"SSID: {ssid}, BSSID: {bssid}, Channel: {channel}, RSSI: {rssi}, Authmode: {authmode}, Hidden: {hidden}")
28+
29+
# Connect to a Wi-Fi network
30+
def connect_to_wifi(ssid, password):
31+
wifi.connect(ssid, password)
32+
start_time = time.time()
33+
34+
# Wait for the connection
35+
while not wifi.isconnected():
36+
if time.time() - start_time > 10:
37+
print("Connection timeout!")
38+
return False
39+
time.sleep(1)
40+
41+
print(f"Connected to {ssid}!")
42+
return True
43+
44+
# Perform Wi-Fi scan
45+
scan_networks()

0 commit comments

Comments
 (0)