Skip to content

Repository files navigation

Embedded Telemetry App

A robust end-to-end telemetry solution featuring a Python-based daemon with dynamic event detection, MQTT transport with offline buffering, and a real-time Angular dashboard with interactive analytics.

Overview

This project simulates a high-reliability embedded telemetry device. It collects sensor data (temperature and accelerometer), processes it through a dynamic event detection engine, and transmits it to a central broker. The system is engineered for resilience, featuring local persistence for offline periods and automatic recovery.

Key Features

  • Simulated Sensors: Periodic generation of high-fidelity temperature and accelerometer data.
  • Dynamic Event Detection: A modular, class-based detection system. Adding new events is as simple as defining a new class in the model—the detector picks it up automatically.
  • Offline Buffering: Automatic fallback to local JSONL storage when the MQTT broker is down.
  • Reliable Transport: Features exponential backoff, automatic reconnection, and prioritized buffer flushing on recovery.
  • Real-time Analytics Dashboard:
    • Interactive Charts: Responsive line graphs (Chart.js) for live sensor monitoring.
    • Notifications Feed: A dedicated events page with color-coded alerts and precise timestamps.
    • Connection Status: Live feedback on broker connectivity.
  • Logging: Log rotation with size limits and backups to prevent disk overflow.
  • Dockerized: Fully orchestrated with Docker Compose for seamless deployment.

Project Structure

embedded-telemetry-app/
├── .github/                    # CI/CD Pipeline (GitHub Actions)
├── app/                        # Python Telemetry Daemon
│   ├── ingestion/              # Sensor simulation
│   ├── processing/             # Dynamic threshold & event logic
│   ├── buffer/                 # Offline storage (JSONL) management
│   ├── transport/              # Reliable MQTT client logic
│   ├── models/                 # Data schemas & Event hierarchy
│   │   ├── events/             # Modular event definitions (Base, Temp, Tilt)
│   │   └── message.py          # Telemetry packet structure
│   ├── utils/                  # Shared utilities (Log rotation, etc.)
│   └── daemon.py               # Main orchestrator class
├── telemetry-dashboard/        # Angular Web Interface
│   ├── src/app/
│   │   ├── components/         # Modular UI (Dashboard, Events, Charts)
│   │   ├── services/           # Telemetry state & MQTT management
│   │   └── app.routes.ts       # Router configuration
│   └── Dockerfile              # Multi-stage build (Node + Nginx)
├── config/                     # Configuration (YAML, Mosquitto)
├── scripts/                    # Automation & helper scripts
│   └── setup_service.sh        # Automated systemd service installer
├── systemd/                    # Linux service configuration
│   └── telemetry.service       # Systemd unit file
├── tests/                      # Python unit tests & verification scripts
├── .flake8                     # Flake8 linting configuration
├── docker-compose.yml          # Container orchestration
└── requirements.txt            # Python dependencies

Running with Docker (Recommended)

The easiest way to run the entire stack is using Docker Compose.

  1. Start the system:

    docker compose up -d --build
  2. Access the Dashboard: Open http://localhost:4200 in your browser.

  3. Monitor Logs:

    docker compose logs -f telemetry

Running Locally (Development)

1. Prerequisites

  • Python 3.12+
  • Node.js & npm
  • Mosquitto Broker (with WebSocket support)

2. Setup

# Install Python dependencies
pip install -r requirements.txt

# Install Angular dependencies
cd telemetry-dashboard && npm install

3. Execution (Separate Terminals)

  • Broker: mosquitto -c config/mosquitto.conf
  • Daemon: python app/main.py
  • Dashboard: cd telemetry-dashboard && npm start

Configuration

Edit config/config.yaml to customize:

  • MQTT: Broker address, ports, and topics.
  • Sensors: Device ID and sampling interval.
  • Thresholds: Limits for temperature (temperature) and tilt (accelerometer) events.
  • Buffer: Local storage path and file size limits.

Testing & Validation

Unit Tests

Verify the system logic with the built-in test suites:

# Set PYTHONPATH and run all tests
$env:PYTHONPATH="."; pytest

Linting

The project uses flake8 for code quality and style enforcement (80-character line limit).

# Run the linter
flake8 .

Continuous Integration (CI)

A GitHub Actions pipeline is configured in .github/workflows/ci.yml. On every push or pull request to the main branch, the following steps are performed:

  1. Linting: Verifies code style with flake8.
  2. Testing: Runs the pytest suite.
  3. Integration: Builds the Docker images and starts the services using docker-compose.
  4. Health Check: Waits for services to initialize and verifies that the telemetry-daemon successfully connects to the MQTT broker by checking the container logs.

Running as a System Service (Linux)

For production-like environments on Linux, you can run the telemetry daemon as a systemd service. This ensures it starts automatically on boot and restarts if it crashes.

Automated Setup

The project includes a setup script that automates the installation to /opt/telemetry-daemon, creates a dedicated telemetry user, sets up a virtual environment, and installs the service.

# Make the script executable and run with sudo
chmod +x scripts/setup_service.sh
sudo ./scripts/setup_service.sh

Management

# Check status
sudo systemctl status telemetry

# Monitor logs in real-time
journalctl -u telemetry -f

# Restart the service
sudo systemctl restart telemetry

Troubleshooting

Mosquitto WebSocket Error

If you see Error: Invalid protocol value (websockets), your version of Mosquitto might be compiled without WebSocket support. On Linux, ensure you have the necessary plugins:

sudo apt install mosquitto mosquitto-clients

In Docker, this is handled automatically by the eclipse-mosquitto:2 image.

About

A full-stack telemetry app featuring a systemd service, embedded simulator and real-time dashboard.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages