Skip to content

Enhancement: log granular startup diagnostics to SD #29

Description

@awickert

Background

Margay currently tracks initialization failures as separate boolean flags (OnBoardError, SensorError, TimeError, SDCardMissing, BatError, BatWarning) and communicates them via LED color codes and Serial output during begin(). This works well for real-time feedback but leaves no persistent record of what failed at startup.

Proposed Enhancement

Replace or supplement the individual boolean flags with a single uint8_t statusFlags where each bit maps to a specific error condition. At startup, write this byte (and a human-readable expansion) to a dedicated log file on the SD card — e.g. startup.log or appended to a diagnostics.log — so that post-deployment review can show exactly what state the logger was in when it started.

Benefits

  • Persistent record: field deployments that experience intermittent failures leave a trace even if the unit recovers
  • More granular than LEDs: 8 bits can encode more distinct conditions than a handful of color codes
  • Richer Serial output: the same byte can drive more descriptive startup messages than the current per-flag checks
  • Composable: sensor libraries (e.g. NW_MCP3421) can expose their own init status, which Margay folds into its byte at startup

Example bit layout

Bit Condition
0 RTC failure
1 SD card missing
2 On-board ADC failure
3 Battery error (below threshold)
4 Battery warning
5 Time/clock error
6 External sensor failure
7 Reserved

Log format (sketch)

2026-05-13T09:14:22 STARTUP statusFlags=0b00100001 [RTC failure, on-board ADC failure]

Relationship to other work

  • NW_MCP3421 is being updated to expose _initOK and a uint8_t _gain (0 = undefined/error) that Margay could query during sensor init and fold into bit 6 or a sensor-specific extension
  • The SD log schema change would affect downstream log parsers — versioning or a separate diagnostics file would minimize disruption to existing deployments

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions