import network
import time
from settings import SSID, PASSWORD
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(SSID, PASSWORD)
max_wait_sec = 15
for wait_sec in range(max_wait_sec):
if wlan.isconnected():
break
print('Waiting for connection...')
time.sleep(1)
if not wlan.isconnected():
raise RuntimeError('Could not connect to network')
print('Connected')
status = wlan.ifconfig()
rssi = wlan.status('rssi')
print(f'ip: {status[0]}')
print(f'rssi: {rssi}')
import requests
url = 'https://www.digikey.cn/'
oled.text(f'HTTP/1.0 GET', 0, 0)
oled.text(f'{url}', 0, 10)
oled.show()
resp = requests.get(url)
status_code = resp.status_code
content = resp.raw.read(1500)
text = content.decode('utf-8')
start = text.find('<title>')
end = text.find('</title>')
title = text[start + 7:end].strip()
print(title)
en_title = ''.join([char for char in title if char <= '\u4e00'])
print(en_title)
resp.close()
oled.text(str(status_code), 0, 30)
oled.text(en_title, 0, 40)
oled.show()