Skip to content

RitamPatra/virtual-sensor-hub

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Virtual Sensor Hub

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.

Key files

  • src/main.c - program entry, duration handling, shutdown logic
  • src/sensor.c, sensor.h - deterministic sensor threads
  • src/hub.c, hub.h - logging, in-memory queue, processor (moving average + alerts)
  • Makefile - one-command build (make)
  • data/hub.log - runtime outputs
  • tools/check_log.py - Python validator for data/hub.log
  • tests/run_tests.sh - orchestrated test harness (runs app + validator)
  • tools/parse_logs.py - generates charts and a CSV summarizing the output

Design

  • 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 a SAMPLE|... line to data/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 writes ALERT|...|THRESHOLD_EXCEEDED lines when a windowed average crosses a threshold.

  • Logging & verification
    All samples and alerts are appended to data/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 by tools/parse_logs.py and visualizations (histogram + timseries) are generated for all three sensors, along with a timeline of alerts and a CSV summarizing the sensor readings.

Prerequisites

Run in WSL2 (Ubuntu) or any Linux environment with:

sudo apt update
sudo apt install -y build-essential make gdb python3

Execution

To build, run from project root:

make

To run indefinitely (Ctrl+C to stop):

./sensorhub

To run for a fixed duration:

./sensorhub --test-duration 8   # run 8 seconds then exit

The program writes trace lines to data/hub.log (SAMPLE and ALERT framed records).

Testing & Analysis

Run this automated test after building:

./tests/run_tests.sh          # default duration 6s
# or
./tests/run_tests.sh 8        # specify duration in seconds

Run this to perform the analysis after the log file has been generated:

python3 tools/parse_logs.py data/hub.log --outdir outputs --window 5

Visualizations

The following are some sample outputs obtained after executing the program for 35 seconds.

Histograms Timeseries
Temperature Histogram Temperature Timeseries
Humidity Histogram Humidity Timeseries
Pressure Histogram Pressure Timeseries

Alerts Timeline

Architecture Diagram

Image

About

Multi-threaded C sensor simulator with moving-average processing and alert generation.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published