A C++17 sensor logging application for simulated or serial temperature/light sources. It supports CSV or SQLite persistence, threaded sampling, runtime summaries, threshold alerts, and CSV export.
- Sensor input modes:
- Simulated sensor mode (Linux/Windows, no hardware needed)
- Serial sensor mode (Linux UART/USB serial device)
- Logging outputs:
- CSV file
- SQLite database (when SQLite3 is available)
- Runtime controls:
- Start logging
- Stop logging
- Show live stats (min/max/avg)
- Show runtime status (accepted/rejected samples, failures, last reading)
- Reset session statistics without restarting the app
- Export logs to CSV
- Safety and observability:
- Input validation rejects invalid readings such as
NaNand negative lux values - Configurable alert thresholds for temperature and light
- Optional
--max-samplesauto-stop for bounded runs and tests
- Input validation rejects invalid readings such as
- Demonstrates:
- OOP interfaces (
ISensor,ILogSink) - File I/O and optional SQLite storage
- Threaded periodic logging loop
- Basic serial communication parsing
- OOP interfaces (
ISensorabstracts data sources.SimulatedSensorgenerates drifting readings.SerialSensorreadstemp,lightlines from a serial device on non-Windows platforms.ILogSinkabstracts persistence.CsvLogSinkappends CSV rows.SqliteLogSinkstores rows in asensor_logtable and can export them back to CSV.DataLoggerowns one sensor and one sink, runs the sampling loop on a worker thread, tracks aggregated stats, validates samples, counts failures, and raises threshold alerts.StatsAggregatormaintains min/max/average for temperature and light.
cmake -S . -B build
cmake --build buildctest --test-dir build --output-on-failureThe test target covers stats reset logic plus the logger lifecycle, invalid sample rejection, alert tracking, and bounded auto-stop behavior.
./build/device_sensor_logger --mode sim --output csv --file sensor_log.csv --interval-ms 1000 --temp-alert-max 28 --light-alert-min 100Then use commands:
startstopstatsstatusreset-statsexport exported.csvquit
./build/device_sensor_logger --mode sim --output sqlite --file sensor_log.db --duration-sec 20 --max-samples 50 --export out.csv./build/device_sensor_logger --mode serial --serial-port /dev/ttyUSB0 --baud 115200 --output csv --file serial_log.csvExpected incoming serial line format:
24.1,315.5
--mode sim|serial--serial-port <path>--baud <rate>--interval-ms <milliseconds>--output csv|sqlite--file <output-path>--duration-sec <seconds>--max-samples <count>--temp-alert-min <value>--temp-alert-max <value>--light-alert-min <value>--light-alert-max <value>--export <csv-path>
Sensor Data Logger
Commands:
start Start logging
stop Stop logging
stats Show min/max/avg
status Show runtime counters and last reading
reset-stats Clear collected session statistics
export <file.csv> Export log data to CSV
help Show commands
quit Stop and exit
> start
Logging started.
> status
running=yes accepted=5 rejected=0 read_failures=0 write_failures=0 alerts=1
last=2026-03-12T12:00:05Z temp=28.214C light=92.113 lux
- If SQLite3 is not found during CMake configure, SQLite output is disabled automatically.
- In serial mode on Linux, ensure your user has permission to access the serial device (for example, group
dialout). - On Windows, serial mode is stubbed out in the current implementation and simulated mode should be used unless Windows serial support is added.