WS2812 troubleshooting
This commit is contained in:
@@ -24,6 +24,7 @@ import network
|
|||||||
import utime
|
import utime
|
||||||
import ujson
|
import ujson
|
||||||
import urandom
|
import urandom
|
||||||
|
print("DEBUG: imports done")
|
||||||
from umqtt.robust import MQTTClient
|
from umqtt.robust import MQTTClient
|
||||||
from machine import Pin
|
from machine import Pin
|
||||||
from neopixel import NeoPixel
|
from neopixel import NeoPixel
|
||||||
@@ -265,72 +266,17 @@ print("DEBUG: _DEVICE defined")
|
|||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
print("DEBUG: about to set wifi globals")
|
print("DEBUG: about to set wifi globals")
|
||||||
|
print("DEBUG: setting _wifi_reconnect_delay_s...")
|
||||||
_wifi_reconnect_delay_s = 5
|
_wifi_reconnect_delay_s = 5
|
||||||
|
print("DEBUG: setting _wifi_check_interval_ms...")
|
||||||
_wifi_check_interval_ms = 30000
|
_wifi_check_interval_ms = 30000
|
||||||
|
print("DEBUG: setting _last_wifi_check...")
|
||||||
_last_wifi_check = 0
|
_last_wifi_check = 0
|
||||||
|
print("DEBUG: setting _wifi_sta...")
|
||||||
_wifi_sta = None
|
_wifi_sta = None
|
||||||
print("DEBUG: wifi globals set")
|
print("DEBUG: wifi globals set")
|
||||||
|
|
||||||
|
print("DEBUG: about to init LED pins")
|
||||||
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}")
|
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
# LEDs (per gauge)
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
num_gauges = len(gauges)
|
num_gauges = len(gauges)
|
||||||
leds_red = []
|
leds_red = []
|
||||||
leds_green = []
|
leds_green = []
|
||||||
@@ -338,6 +284,7 @@ leds_bl = []
|
|||||||
for g in gauges:
|
for g in gauges:
|
||||||
leds_red.append(Pin(g["red_pin"], Pin.OUT, value=0))
|
leds_red.append(Pin(g["red_pin"], Pin.OUT, value=0))
|
||||||
leds_green.append(Pin(g["green_pin"], Pin.OUT, value=0))
|
leds_green.append(Pin(g["green_pin"], Pin.OUT, value=0))
|
||||||
|
print("DEBUG: LED pins initialized")
|
||||||
|
|
||||||
total_backlight_leds = num_gauges * (BACKLIGHT_LEDS_PER_GAUGE + STATUS_LEDS_PER_GAUGE)
|
total_backlight_leds = num_gauges * (BACKLIGHT_LEDS_PER_GAUGE + STATUS_LEDS_PER_GAUGE)
|
||||||
print(f"DEBUG: initializing NeoPixel on pin {BACKLIGHT_PIN} with {total_backlight_leds} LEDs")
|
print(f"DEBUG: initializing NeoPixel on pin {BACKLIGHT_PIN} with {total_backlight_leds} LEDs")
|
||||||
|
|||||||
Reference in New Issue
Block a user