edpm

🚀 EDPM Lite - Embedded Device Process & Logging Framework

Python Docker License Status

EDPM Lite to uniwersalny, lekki framework do monitorowania i kontroli procesów w systemach embedded. Oferuje prostą komunikację przez ZeroMQ/WebSocket, kompletny Web UI dashboard i wsparcie dla protokołów przemysłowych.

Kluczowe Funkcje

🚀 Quick Start

1. Uruchom Web Dashboard (Najszybszy sposób)

# Clone repository
git clone <repository-url>
cd edpm

# Start EDPM server with Web Dashboard
python3 edpm-lite-server.py

# Open dashboard in browser
open http://localhost:8080

2. Docker Environment (Kompletne środowisko)

# Start full environment with all protocols
make extended-up

# Access web dashboard
open http://localhost:8080

# Run protocol tests
make test-all-protocols

3. Use in Your Code

from edpm_lite import EDPMLite

client = EDPMLite()
client.log('info', 'Hello EDPM!')
client.gpio_set(17, 1)
temperature = client.send({'action': 'read_sensor', 'type': 'bme280'})

🌐 Web UI Dashboard

Główne Panele:

Panel Funkcje
🔌 GPIO Control Pin status, toggle buttons, PWM control, live charts
🌡️ I2C Sensors BME280 temp/humidity/pressure, ADS1115 ADC, bus scanning
🔊 I2S Audio Test tones, recording, playback, FFT analysis, level meters
RS485/Modbus VFD control, power monitoring, industrial device communication
📊 System Stats CPU/RAM usage, message rates, uptime, connection status
📝 Live Logs Real-time colored logging with filtering and search

Interaktywne Funkcje:

🎯 Architecture Overview

Core Components

  1. EDPM Lite Server (edpm-lite-server.py)
    • ZeroMQ REP/REQ and WebSocket server
    • SQLite message buffering
    • GPIO simulator with realistic behavior
    • Static file serving for Web UI
  2. Web Dashboard (web/dashboard.html)
    • Modern responsive interface
    • Real-time WebSocket communication
    • Interactive protocol controls
    • Live data visualization
  3. Protocol Handlers (protocols/)
    • i2c_handler.py - I2C sensors (BME280, ADS1115, PCF8574)
    • i2s_handler.py - Audio generation, recording, FFT analysis
    • rs485_handler.py - Modbus RTU industrial protocols
  4. Client Library (edpm_lite.py)
    • Simple Python API
    • Auto-discovery and failover
    • Local message buffering
    • GPIO helpers

Communication Protocol

Simple JSON message format:

{
  "v": 1,              // Protocol version
  "t": "log",          // Type: log/cmd/evt/res
  "id": "123",         // Message ID
  "src": "app1",       // Source identifier
  "ts": 1234567890.1,  // Timestamp
  "d": {}              // Data payload
}

Transport Methods

🔧 Extended Protocols Support

I2C - Sensor Communication

# Read BME280 environmental sensor
from protocols.i2c_handler import I2CHandler

i2c = I2CHandler(simulator=True)
data = i2c.read_bme280()
print(f"Temperature: {data['temperature']}°C")
print(f"Humidity: {data['humidity']}%")
print(f"Pressure: {data['pressure']} hPa")

# Scan I2C bus for devices
devices = i2c.scan_bus()
print(f"Found devices: {[hex(addr) for addr in devices]}")

I2S - Audio Processing

# Generate and play test tone
from protocols.i2s_handler import I2SHandler

i2s = I2SHandler(simulator=True)

# Generate 440Hz tone
audio_data = i2s.generate_test_tone(440, duration=1.0)
i2s.play_audio(audio_data)

# Record and analyze audio
recording = i2s.record_audio(duration=2.0)
fft_data = i2s.analyze_audio_fft(recording)

RS485/Modbus - Industrial Communication

# Control Variable Frequency Drive
from protocols.rs485_handler import RS485Handler

rs485 = RS485Handler('/dev/ttyUSB0', simulator=True)

# Read holding registers from device
data = await rs485.read_holding_registers(slave_id=1, address=0, count=2)

# Write VFD speed control
await rs485.write_holding_register(slave_id=3, address=0, value=8000)  # 80% speed

🐳 Docker Environment

Standard Setup

# Basic EDPM server
docker-compose up

# Access web interface
open http://localhost:8080

Extended Protocols Environment

# Full environment with I2C/I2S/RS485 simulation
docker-compose -f docker-compose-extended.yml up

# Access enhanced dashboard with all protocols
open http://localhost:8080

# Protocol simulator interface
open http://localhost:8083

Makefile Commands

# Build and start extended environment
make extended-up

# Test individual protocols
make test-i2c
make test-i2s
make test-rs485

# Test all protocols together
make test-all-protocols

# Stop and cleanup
make extended-down

📊 Testing & Validation

Automated Tests

# Run comprehensive test suite
python -m pytest tests/ -v

# Test specific protocols
python -m pytest tests/test_i2c.py -v
python -m pytest tests/test_i2s.py -v
python -m pytest tests/test_rs485.py -v

# Integration tests with Docker
make test-integration

Performance Benchmarks

# Message throughput test
python test_server_connection.py --messages 10000

# Protocol latency test
make benchmark-protocols

# System resource usage
make monitor-resources

Manual Testing via Dashboard

  1. GPIO Testing: Use toggle buttons, observe LED status changes
  2. I2C Testing: Click “Read All Sensors”, monitor live temperature charts
  3. I2S Testing: Play test tones, record audio, view FFT analysis
  4. RS485 Testing: Control VFD speed, monitor power readings
  5. System Testing: Generate test traffic, monitor message rates

🔧 Configuration

Environment Variables

# Server configuration
EDPM_ENDPOINT="ipc:///tmp/edpm.ipc"  # ZeroMQ endpoint
EDPM_PORT=8080                       # Web server port
EDPM_DB="/dev/shm/edpm.db"          # SQLite database path
EDPM_DEBUG=true                     # Enable debug logging

# GPIO simulation
GPIO_MODE=SIMULATOR                  # Use GPIO simulator
SIMULATE_SENSORS=true               # Enable sensor simulation

# Protocol simulation
I2C_SIMULATOR=true                   # Enable I2C simulation
I2S_SIMULATOR=true                   # Enable I2S simulation
RS485_SIMULATOR=true                 # Enable RS485 simulation

Production Configuration

# For real hardware (Raspberry Pi)
GPIO_MODE=BCM                        # Use BCM GPIO
I2C_BUS=1                           # Real I2C bus
I2S_DEVICE="hw:1,0"                 # Real I2S device
RS485_PORT="/dev/ttyUSB0"           # Real RS485 adapter

🚀 Use Cases & Examples

Industrial Automation

# Complete industrial control scenario
async def industrial_automation():
    # Read temperature from I2C sensor
    temp_data = i2c.read_bme280()
    temperature = temp_data['temperature']
    
    # Control VFD based on temperature
    if temperature > 30:
        # Increase fan speed to 80%
        await rs485.write_holding_register(3, 0, 8000)
        
        # Sound alarm via I2S
        alarm_tone = i2s.generate_test_tone(1000, 2.0)
        await i2s.play_audio(alarm_tone)
        
        # Activate warning LED
        edpm.gpio_set(17, 1)
        
        # Log critical event
        edpm.log('warning', f'High temperature: {temperature}°C')
    
    # Monitor power consumption
    power_data = await rs485.read_holding_registers(2, 2, 1)
    
    # Update status display via GPIO expander
    status_byte = calculate_status(temperature, power_data)
    i2c.write_byte(0x20, status_byte)

Environmental Monitoring

# IoT sensor data collection
def environmental_monitoring():
    while True:
        # Read all environmental sensors
        bme_data = i2c.read_bme280()
        adc_data = i2c.read_ads1115_all_channels()
        
        # Collect data
        sensor_data = {
            'timestamp': time.time(),
            'temperature': bme_data['temperature'],
            'humidity': bme_data['humidity'],
            'pressure': bme_data['pressure'],
            'light_level': adc_data[0],
            'soil_moisture': adc_data[1],
            'battery_voltage': adc_data[2]
        }
        
        # Send to cloud via EDPM
        edpm.event('sensor_reading', **sensor_data)
        
        time.sleep(60)  # Read every minute

📚 Documentation

🤝 Contributing

  1. Fork the repository
  2. Create feature branch: git checkout -b feature/amazing-feature
  3. Commit changes: git commit -m 'Add amazing feature'
  4. Push to branch: git push origin feature/amazing-feature
  5. Open Pull Request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🏆 Achievements


Made with ❤️ for the embedded and IoT community