Skip to content

Hayder-IRAQ/embedded-sensor-system

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

⚑ Embedded Sensor System β€” Python IoT Framework

Python MicroPython MQTT License CI

A production-grade embedded sensor data acquisition and processing framework for IoT systems. Supports multi-sensor fusion, real-time filtering, MQTT/HTTP telemetry, OTA firmware updates, and a live monitoring dashboard β€” all in Python.


πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   Dashboard (Web UI)                     β”‚
β”‚              Real-time charts & alerts                   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                       β”‚ WebSocket / REST
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                  Middleware Layer                         β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”            β”‚
β”‚   β”‚ MQTT     β”‚  β”‚ HTTP     β”‚  β”‚ Data      β”‚            β”‚
β”‚   β”‚ Broker   β”‚  β”‚ REST API β”‚  β”‚ Logger    β”‚            β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                       β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                  Processing Core                         β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”            β”‚
β”‚   β”‚ Kalman   β”‚  β”‚ Sensor   β”‚  β”‚ Anomaly   β”‚            β”‚
β”‚   β”‚ Filter   β”‚  β”‚ Fusion   β”‚  β”‚ Detector  β”‚            β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                       β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                  Hardware Abstraction                     β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚   β”‚BME280β”‚  β”‚MPU6050β”‚  β”‚ADS  β”‚  β”‚GPS   β”‚  β”‚Ultrasonicβ”‚  β”‚
β”‚   β”‚T/H/P β”‚  β”‚IMU    β”‚  β”‚1115 β”‚  β”‚NEO-6Mβ”‚  β”‚HC-SR04  β”‚  β”‚
β”‚   β””β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
          IΒ²C           SPI          UART        GPIO

✨ Features

Category Feature Description
Sensors 8+ drivers BME280, MPU6050, ADS1115, GPS NEO-6M, HC-SR04, DHT22, BH1750, INA219
Processing Kalman filter Adaptive noise estimation with configurable process/measurement noise
Processing Sensor fusion Multi-sensor weighted fusion with confidence scoring
Processing Anomaly detection Z-score & sliding window anomaly detection with alerts
Protocols MQTT 3.1.1/5.0 Async publish/subscribe with QoS levels, TLS support
Protocols HTTP REST RESTful API for sensor data retrieval and configuration
Protocols Modbus RTU Industrial protocol support for legacy equipment
Middleware Data logger SQLite + CSV + JSON logging with rotation and compression
Middleware OTA updates Over-the-air firmware update mechanism
Middleware Watchdog Hardware/software watchdog with auto-recovery
Dashboard Web UI Real-time monitoring with charts, alerts, and system health
Testing 50+ tests Unit, integration, and hardware simulation tests

πŸ“ Project Structure

embedded-sensor-system/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ drivers/                # Hardware sensor drivers
β”‚   β”‚   β”œβ”€β”€ base_sensor.py      # Abstract sensor interface
β”‚   β”‚   β”œβ”€β”€ bme280.py           # Temperature/Humidity/Pressure
β”‚   β”‚   β”œβ”€β”€ mpu6050.py          # 6-axis IMU (Accel + Gyro)
β”‚   β”‚   β”œβ”€β”€ ads1115.py          # 16-bit ADC
β”‚   β”‚   β”œβ”€β”€ gps_neo6m.py        # GPS receiver
β”‚   β”‚   β”œβ”€β”€ hcsr04.py           # Ultrasonic distance
β”‚   β”‚   β”œβ”€β”€ dht22.py            # Temperature/Humidity
β”‚   β”‚   β”œβ”€β”€ bh1750.py           # Ambient light
β”‚   β”‚   └── ina219.py           # Current/Power monitor
β”‚   β”œβ”€β”€ core/                   # Signal processing engine
β”‚   β”‚   β”œβ”€β”€ kalman_filter.py    # Kalman filter implementation
β”‚   β”‚   β”œβ”€β”€ sensor_fusion.py    # Multi-sensor data fusion
β”‚   β”‚   β”œβ”€β”€ anomaly_detector.py # Anomaly detection engine
β”‚   β”‚   β”œβ”€β”€ pid_controller.py   # PID control loop
β”‚   β”‚   └── ring_buffer.py      # Lock-free circular buffer
β”‚   β”œβ”€β”€ protocols/              # Communication protocols
β”‚   β”‚   β”œβ”€β”€ mqtt_client.py      # MQTT pub/sub client
β”‚   β”‚   β”œβ”€β”€ http_api.py         # REST API server
β”‚   β”‚   └── modbus_rtu.py       # Modbus RTU master/slave
β”‚   β”œβ”€β”€ middleware/              # System services
β”‚   β”‚   β”œβ”€β”€ data_logger.py      # Multi-format data logging
β”‚   β”‚   β”œβ”€β”€ ota_updater.py      # OTA firmware updates
β”‚   β”‚   β”œβ”€β”€ watchdog.py         # System watchdog
β”‚   β”‚   β”œβ”€β”€ config_manager.py   # YAML/JSON configuration
β”‚   β”‚   └── event_bus.py        # Pub/sub event system
β”‚   └── utils/                  # Utilities
β”‚       β”œβ”€β”€ fixed_point.py      # Fixed-point math (no FPU)
β”‚       β”œβ”€β”€ crc.py              # CRC-8/16/32 checksums
β”‚       β”œβ”€β”€ bitfield.py         # Register bit manipulation
β”‚       └── retry.py            # Retry with backoff
β”œβ”€β”€ tests/                      # Test suite
β”œβ”€β”€ examples/                   # Usage examples
β”œβ”€β”€ configs/                    # Configuration files
β”œβ”€β”€ dashboard/                  # Web monitoring UI
β”œβ”€β”€ scripts/                    # Deployment scripts
β”œβ”€β”€ docs/                       # Documentation
β”œβ”€β”€ .github/workflows/          # CI/CD
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ setup.py
└── README.md

πŸš€ Quick Start

Installation

git clone https://github.com/Hayder-IRAQ/embedded-sensor-system.git
cd embedded-sensor-system
pip install -r requirements.txt
pip install -e .

Basic Usage β€” Read a BME280 Sensor

from src.drivers.bme280 import BME280
from src.core.kalman_filter import KalmanFilter

# Initialize sensor on I2C bus
sensor = BME280(bus_id=1, address=0x76)

# Apply Kalman filtering for noise reduction
kf = KalmanFilter(process_noise=0.01, measurement_noise=0.1)

while True:
    reading = sensor.read()
    filtered = kf.update(reading.temperature)
    print(f"Temp: {filtered:.2f}Β°C | Humidity: {reading.humidity:.1f}%")

Multi-Sensor Fusion

from src.core.sensor_fusion import SensorFusion
from src.drivers.bme280 import BME280
from src.drivers.dht22 import DHT22

fusion = SensorFusion(strategy="weighted_average")
fusion.add_source("bme280", weight=0.7, sensor=BME280(bus_id=1))
fusion.add_source("dht22", weight=0.3, sensor=DHT22(pin=4))

result = fusion.read("temperature")
print(f"Fused temp: {result.value:.2f}Β°C (confidence: {result.confidence:.0%})")

MQTT Telemetry

from src.protocols.mqtt_client import MQTTClient
from src.drivers.bme280 import BME280

mqtt = MQTTClient(broker="mqtt.example.com", port=8883, tls=True)
sensor = BME280(bus_id=1)

async def publish_telemetry():
    await mqtt.connect()
    while True:
        data = sensor.read()
        await mqtt.publish("sensors/env", data.to_json(), qos=1)
        await asyncio.sleep(5)

Run Tests

python -m pytest tests/ -v --tb=short

πŸ“Š Dashboard

Launch the real-time monitoring dashboard:

python dashboard/app.py
# Open http://localhost:8050

πŸ”§ Configuration

# configs/system.yaml
system:
  name: "weather-station-01"
  sample_rate_hz: 10
  log_level: INFO

sensors:
  bme280:
    bus: 1
    address: 0x76
    oversample: 16
  mpu6050:
    bus: 1
    address: 0x68
    accel_range: "4g"
    gyro_range: "500dps"

processing:
  kalman:
    process_noise: 0.01
    measurement_noise: 0.1
  anomaly:
    method: "zscore"
    threshold: 3.0
    window_size: 100

telemetry:
  mqtt:
    broker: "mqtt.example.com"
    port: 8883
    tls: true
    topic_prefix: "iot/sensors"
    qos: 1

🎯 Target Platforms

Platform Status Notes
Raspberry Pi 4/5 βœ… Full support Primary development target
Raspberry Pi Pico W βœ… MicroPython Via MicroPython compatibility layer
ESP32 βœ… MicroPython WiFi + BLE capable
BeagleBone Black βœ… Full support Industrial-grade
Jetson Nano βœ… Full support GPU-accelerated processing
Desktop (Simulated) βœ… Full support For development and testing

πŸ“– Documentation

🀝 Contributing

See CONTRIBUTING.md for guidelines.

πŸ“„ License

MIT License β€” see LICENSE for details.

About

Production-grade IoT framework for embedded sensor data acquisition, Kalman filtering, multi-sensor fusion, anomaly detection, and MQTT/HTTP telemetry. Supports 8+ sensors (BME280, MPU6050, GPS, INA219...) with simulation mode for desktop development.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages