This is a multi-threaded C program that simulates sensors, produces time-stamped samples, computes moving averages and emits alerts. It is designed as a software-only demo of embedded/IoT-oriented C development. It is a compact, testable C project that demonstrates systems-oriented skills relevant to embedded/IoT software such as concurrency, deterministic sampling, simple protocol framing, log-based verification and a small test harness. No hardware required.
src/main.c- program entry, duration handling, shutdown logicsrc/sensor.c,sensor.h- deterministic sensor threadssrc/hub.c,hub.h- logging, in-memory queue, processor (moving average + alerts)Makefile- one-command build (make)data/hub.log- runtime outputstools/check_log.py- Python validator for data/hub.logtests/run_tests.sh- orchestrated test harness (runs app + validator)tools/parse_logs.py- generates charts and a CSV summarizing the output
-
Sensor threads (
sensor.c)
Each sensor (TEMP, HUM, PRESS) runs in its own thread and produces deterministic sample sequences at a configured interval. Determinism enables reproducible runs and stable automated checks. -
Submission & queue (
hub.c)
hub_submit_sample()enqueues incoming samples into a fixed-size circular queue and immediately logs aSAMPLE|...line todata/hub.log. Mutex + condition variable coordinate producer/consumer access. -
Processor thread (
hub.c)
A separate processor consumes queued samples, maintains a sliding moving-average window per sensor (configurable window size) and writesALERT|...|THRESHOLD_EXCEEDEDlines when a windowed average crosses a threshold. -
Logging & verification
All samples and alerts are appended todata/hub.log(human-readable framed lines). A Python validator (tools/check_log.py) inspects the log to verify expected sample counts and alerts for automated testing. -
Analysis & Visualizations
The logs are analysed bytools/parse_logs.pyand visualizations (histogram + timseries) are generated for all three sensors, along with a timeline of alerts and a CSV summarizing the sensor readings.
Run in WSL2 (Ubuntu) or any Linux environment with:
sudo apt update
sudo apt install -y build-essential make gdb python3To build, run from project root:
makeTo run indefinitely (Ctrl+C to stop):
./sensorhubTo run for a fixed duration:
./sensorhub --test-duration 8 # run 8 seconds then exitThe program writes trace lines to data/hub.log (SAMPLE and ALERT framed records).
Run this automated test after building:
./tests/run_tests.sh # default duration 6s
# or
./tests/run_tests.sh 8 # specify duration in secondsRun this to perform the analysis after the log file has been generated:
python3 tools/parse_logs.py data/hub.log --outdir outputs --window 5The following are some sample outputs obtained after executing the program for 35 seconds.
| Histograms | Timeseries |
|---|---|
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |







