Add Wi-Fi auto-boot connection, MCP JSON-RPC Server, and host bridge
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
# This file is executed on every boot (including wake-boot from deepsleep)
|
||||
import network
|
||||
import time
|
||||
import rlcd
|
||||
from machine import Pin, SPI
|
||||
import wifi_config
|
||||
|
||||
def connect_wifi():
|
||||
# Initialize display to show connection progress
|
||||
display = None
|
||||
try:
|
||||
spi = SPI(1, baudrate=20000000, polarity=0, phase=0, sck=Pin(11), mosi=Pin(12))
|
||||
display = rlcd.RLCD(spi, cs=Pin(40), dc=Pin(5), rst=Pin(41))
|
||||
display.clear(0)
|
||||
display.text("ESP32-S3-RLCD-4.2", 10, 10, 1)
|
||||
display.line(10, 20, 390, 20, 1)
|
||||
display.text("Connecting to Wi-Fi...", 10, 35, 1)
|
||||
display.text(f"SSID: {wifi_config.WIFI_SSID}", 10, 50, 1)
|
||||
display.show()
|
||||
except Exception as e:
|
||||
print("Display init failed in boot.py:", e)
|
||||
|
||||
# Initialize Wi-Fi Station
|
||||
wlan = network.WLAN(network.STA_IF)
|
||||
wlan.active(True)
|
||||
|
||||
if not wlan.isconnected():
|
||||
print(f"Connecting to network {wifi_config.WIFI_SSID}...")
|
||||
wlan.connect(wifi_config.WIFI_SSID, wifi_config.WIFI_PASS)
|
||||
|
||||
# Wait up to 15 seconds for connection
|
||||
timeout = 15
|
||||
dot_x = 10
|
||||
while not wlan.isconnected() and timeout > 0:
|
||||
time.sleep(1)
|
||||
timeout -= 1
|
||||
print("Connecting...")
|
||||
if display:
|
||||
display.text(".", dot_x, 70, 1)
|
||||
dot_x += 10
|
||||
display.show()
|
||||
|
||||
if wlan.isconnected():
|
||||
ip = wlan.ifconfig()[0]
|
||||
print(f"Wi-Fi Connected! IP Address: {ip}")
|
||||
if display:
|
||||
display.clear(0)
|
||||
display.text("ESP32-S3-RLCD-4.2", 10, 10, 1)
|
||||
display.line(10, 20, 390, 20, 1)
|
||||
display.text("Wi-Fi Status: Connected!", 10, 35, 1)
|
||||
display.text(f"SSID: {wifi_config.WIFI_SSID}", 10, 50, 1)
|
||||
display.text(f"IP: {ip}", 10, 65, 1)
|
||||
display.text("Starting MCP Server...", 10, 90, 1)
|
||||
display.show()
|
||||
time.sleep(1.5)
|
||||
else:
|
||||
print("Wi-Fi Connection Failed.")
|
||||
if display:
|
||||
display.clear(0)
|
||||
display.text("ESP32-S3-RLCD-4.2", 10, 10, 1)
|
||||
display.line(10, 20, 390, 20, 1)
|
||||
display.text("Wi-Fi Status: Connection Failed!", 10, 35, 1)
|
||||
display.text("Check credentials in:", 10, 55, 1)
|
||||
display.text("wifi_config.py", 20, 70, 1)
|
||||
display.text("Starting offline...", 10, 95, 1)
|
||||
display.show()
|
||||
time.sleep(2)
|
||||
|
||||
connect_wifi()
|
||||
Reference in New Issue
Block a user