Initial commit: ESP32-S3-RLCD-4.2 hardware utility classes and demo

This commit is contained in:
Adolfo Reyna
2026-05-31 22:44:49 -04:00
commit 558ee43149
14 changed files with 1295 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
import network
class WiFiUtil:
def __init__(self):
self.wlan = network.WLAN(network.STA_IF)
self.wlan.active(True)
def scan(self):
"""Scans for networks and returns a list of dictionaries with ssid and rssi."""
print("Scanning for Wi-Fi networks...")
networks = self.wlan.scan()
result = []
for net in networks:
# network tuple: (ssid, bssid, channel, RSSI, authmode, hidden)
try:
ssid = net[0].decode('utf-8')
except Exception:
try:
ssid = ''.join(chr(b) if 32 <= b < 127 else '?' for b in net[0])
except Exception:
ssid = "<Unknown SSID>"
rssi = net[3]
if ssid: # Filter out hidden/empty SSIDs
result.append({"ssid": ssid, "rssi": rssi})
# Sort by signal strength (RSSI) descending
result.sort(key=lambda x: x['rssi'], reverse=True)
return result