diff --git a/esp32/platformio.ini b/esp32/platformio.ini index a19f930..46c6895 100644 --- a/esp32/platformio.ini +++ b/esp32/platformio.ini @@ -40,3 +40,22 @@ build_flags = ;; - Additional parameters in the WifiManager config menu for configuring these features. ;; Check out the README for a schematic of how to wire up the LDR. -D FEATURE_LDR=3 + + +[env:seeed_xiao_esp32c3] +platform = espressif32 +board = seeed_xiao_esp32c3 +framework = arduino +lib_deps = + adafruit/Adafruit NeoPixel@^1.12.3 + bblanchon/ArduinoJson@^7.1.0 + sstaub/NTP@^1.6 + tzapu/WiFiManager@^2.0.17 + khoih-prog/ESP32_C3_TimerInterrupt@^1.8.0 +build_flags = + -D ARDUINO_USB_MODE=1 + -D ARDUINO_USB_CDC_ON_BOOT=1 + -D WS2812_PIN=D8 + -D FEATURE_CONFIGAP=D0 + -D FEATURE_CONFIGAP_GND=D1 + -D FEATURE_LDR=A2 diff --git a/esp32/src/main.cpp b/esp32/src/main.cpp index f51fc54..28db6cf 100644 --- a/esp32/src/main.cpp +++ b/esp32/src/main.cpp @@ -12,7 +12,9 @@ #include "spacemap.h" +#ifndef WS2812_PIN #define WS2812_PIN 0 +#endif #define WS2812_LEN (sizeof(spaces)/sizeof(char*)) #define WS2812_BS 5 @@ -38,6 +40,7 @@ ESP32Timer ITimer0(0); volatile bool wmp_needs_config_save; volatile bool timerExpired; bool error = false; +uint16_t failcount = 0; enum SpaceState { Closed, @@ -330,6 +333,14 @@ void loop() { timerExpired = false; Serial.println("Timer expired!"); error = !updateMap(); + if (error) { + ++failcount; + } else { + failcount = 0; + } + if (failcount > 3) { + ESP.restart(); + } } time_t now = ntp.epoch();