feat(firmware): log boot and reboot reason to event log
Every boot logs EVT_BOOT with esp_reset_reason(); every deliberate ESP.restart() is preceded by EVT_REBOOT with a reason code. This gives us a persistent answer to 'why did the device just reboot?'.
This commit is contained in:
@@ -8,6 +8,8 @@
|
||||
#include "cv.h"
|
||||
#include "ble_scanner.h"
|
||||
#include "reporter.h"
|
||||
#include "event_log.h"
|
||||
#include <esp_system.h>
|
||||
|
||||
// LED on GPIO2 (TimerCamera-F built-in LED) — verify against board schematic
|
||||
// Factory reset: hold GPIO37 (BOOT button) for 5 seconds
|
||||
@@ -45,6 +47,7 @@ static void check_factory_reset() {
|
||||
uint32_t held = millis();
|
||||
while (digitalRead(BUTTON_PIN) == LOW) {
|
||||
if (millis() - held >= FACTORY_RESET_HOLD_MS) {
|
||||
event_log_write(EVT_REBOOT, REBOOT_FACTORY_RESET, 0);
|
||||
config_clear_wifi();
|
||||
ESP.restart();
|
||||
}
|
||||
@@ -140,6 +143,9 @@ void setup() {
|
||||
pinMode(BUTTON_PIN, INPUT_PULLUP);
|
||||
led_set(true); // on = booting
|
||||
|
||||
event_log_init();
|
||||
event_log_write(EVT_BOOT, (uint16_t)esp_reset_reason(), 0);
|
||||
|
||||
if (!config_load(g_cfg)) {
|
||||
Serial.println("FATAL: device_id/location_id/hmac_secret not provisioned");
|
||||
while (true) { delay(500); led_set(!digitalRead(LED_PIN)); } // fast blink
|
||||
@@ -148,6 +154,7 @@ void setup() {
|
||||
// Connect to WiFi
|
||||
if (!config_has_wifi()) {
|
||||
provisioning_run();
|
||||
event_log_write(EVT_REBOOT, REBOOT_WIFI_REPROV, 0);
|
||||
ESP.restart();
|
||||
}
|
||||
|
||||
@@ -161,6 +168,7 @@ void setup() {
|
||||
if (WiFi.status() != WL_CONNECTED) {
|
||||
// Saved creds failed — re-provision
|
||||
provisioning_run();
|
||||
event_log_write(EVT_REBOOT, REBOOT_WIFI_REPROV, 0);
|
||||
ESP.restart();
|
||||
}
|
||||
|
||||
@@ -183,7 +191,11 @@ void setup() {
|
||||
// OTA update support
|
||||
ArduinoOTA.setHostname(g_cfg.device_id.c_str());
|
||||
ArduinoOTA.onStart([]() { ble_scanner_pause(); });
|
||||
ArduinoOTA.onEnd([]() { ble_scanner_resume(); ESP.restart(); });
|
||||
ArduinoOTA.onEnd([]() {
|
||||
ble_scanner_resume();
|
||||
event_log_write(EVT_REBOOT, REBOOT_OTA, 0);
|
||||
ESP.restart();
|
||||
});
|
||||
ArduinoOTA.onError([](ota_error_t e) { ble_scanner_resume(); });
|
||||
ArduinoOTA.begin();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user