WS2812 troubleshooting
This commit is contained in:
@@ -276,6 +276,63 @@ print("DEBUG: setting _wifi_sta...")
|
|||||||
_wifi_sta = None
|
_wifi_sta = None
|
||||||
print("DEBUG: wifi globals set")
|
print("DEBUG: wifi globals set")
|
||||||
|
|
||||||
|
print("DEBUG: defining connect_wifi function...")
|
||||||
|
def connect_wifi(ssid, password, timeout_s=15):
|
||||||
|
global _wifi_sta
|
||||||
|
_wifi_sta = network.WLAN(network.STA_IF)
|
||||||
|
_wifi_sta.active(True)
|
||||||
|
if _wifi_sta.isconnected():
|
||||||
|
ip, mask, gw, dns = _wifi_sta.ifconfig()
|
||||||
|
info("WiFi already connected")
|
||||||
|
info(f" IP:{ip} mask:{mask} gw:{gw} dns:{dns}")
|
||||||
|
return ip
|
||||||
|
info(f"WiFi connecting to '{ssid}' ...")
|
||||||
|
_wifi_sta.connect(ssid, password)
|
||||||
|
deadline = utime.time() + timeout_s
|
||||||
|
while not _wifi_sta.isconnected():
|
||||||
|
if utime.time() > deadline:
|
||||||
|
log_err(f"WiFi connect timeout after {timeout_s}s")
|
||||||
|
raise OSError("WiFi connect timeout")
|
||||||
|
utime.sleep_ms(200)
|
||||||
|
ip, mask, gw, dns = _wifi_sta.ifconfig()
|
||||||
|
mac = ":".join(f"{b:02x}" for b in _wifi_sta.config("mac"))
|
||||||
|
info("WiFi connected!")
|
||||||
|
info(f" SSID : {ssid}")
|
||||||
|
info(f" MAC : {mac}")
|
||||||
|
info(f" IP : {ip} mask:{mask} gw:{gw} dns:{dns}")
|
||||||
|
return ip
|
||||||
|
|
||||||
|
|
||||||
|
def check_wifi():
|
||||||
|
global _wifi_sta, _last_wifi_check, _wifi_reconnect_delay_s
|
||||||
|
now = utime.ticks_ms()
|
||||||
|
if utime.ticks_diff(now, _last_wifi_check) < _wifi_check_interval_ms:
|
||||||
|
return
|
||||||
|
_last_wifi_check = now
|
||||||
|
|
||||||
|
if _wifi_sta is None:
|
||||||
|
_wifi_sta = network.WLAN(network.STA_IF)
|
||||||
|
|
||||||
|
if _wifi_sta.isconnected():
|
||||||
|
return
|
||||||
|
|
||||||
|
log_err("WiFi lost connection — attempting reconnect...")
|
||||||
|
try:
|
||||||
|
_wifi_sta.active(True)
|
||||||
|
_wifi_sta.connect(WIFI_SSID, WIFI_PASSWORD)
|
||||||
|
deadline = utime.time() + 15
|
||||||
|
while not _wifi_sta.isconnected():
|
||||||
|
if utime.time() > deadline:
|
||||||
|
log_err("WiFi reconnect timeout")
|
||||||
|
return
|
||||||
|
utime.sleep_ms(200)
|
||||||
|
ip, mask, gw, dns = _wifi_sta.ifconfig()
|
||||||
|
info(f"WiFi reconnected! IP:{ip}")
|
||||||
|
except Exception as e:
|
||||||
|
log_err(f"WiFi reconnect failed: {e}")
|
||||||
|
|
||||||
|
print("DEBUG: WiFi functions defined")
|
||||||
|
|
||||||
print("DEBUG: about to init LED pins")
|
print("DEBUG: about to init LED pins")
|
||||||
print("DEBUG: computing len(gauges)...")
|
print("DEBUG: computing len(gauges)...")
|
||||||
num_gauges = len(gauges)
|
num_gauges = len(gauges)
|
||||||
|
|||||||
Reference in New Issue
Block a user