PowerScraper is a high-performance, multithreaded Rust application designed to query metrics from solar inverters and energy meters, calculate battery charge/discharge commands dynamically to zero out grid interaction, and forward telemetry to monitoring platforms (EmonCMS and InfluxDB).
It operates on a fully decoupled, MQTT-only inter-task communication architecture for maximum task isolation and resilience.
See the Changelog for a summary of recent changes and updates.
- Inverter Drivers:
- SolaX WiFi: Queries real-time JSON endpoints on legacy WiFi dongles.
- SolaX Modbus TCP (Standard): Connects to classic SolaX SK-SU5000E inverters.
- SolaX X-Hybrid Modbus TCP: Queries modern X-Series hybrid inverters using sparse block reads.
- SolaX Generation 4 (G4) Modbus TCP: Implements the VPP (Virtual Power Plant) 32-bit active power control rate interfaces.
- SolaX Generation 3 (G3) Modbus TCP: Implements G3-specific VPP 16-bit active power control rate overrides.
- Grid Meter Drivers:
- SDM630 Modbus RTU: Isolated OS-threaded Modbus RTU serial driver with scheduling priority escapes (
SCHED_FIFO/ nice-20) to eliminate polling latency. - DTSU666 Modbus RTU: High-priority serial driver for Chint energy meters.
- MQTT Power Meter: Bridges external MQTT meter topics (Shelly, ESPHome) to the regulation loop.
- SDM630 Modbus RTU: Isolated OS-threaded Modbus RTU serial driver with scheduling priority escapes (
- Control Loop & Battery Coordination:
- Battery Grouping: Proportionally balances charge/discharge requests based on SoC capacity headroom and BMS throttling states across multiple linked inverters.
- Dynamic Grid Regulation: Regulation loop automatically adjusts battery rates to track a configured grid target error (e.g. maintaining a target offset like
-50W).
- Simulation & Parameter Tuning:
- Optimization Engine: Includes Lookahead MPC, Adaptive Peak Shaving, and Evolved Heuristic simulation strategies.
- Genetic Algorithm (GA) Tuning: Automatically optimizes threshold parameters and solar forecast weightings against historical database telemetry.
- Web Dashboard & UI:
- Built-in lightweight Actix-web server hosting status JSON API endpoints and an interactive web interface for real-time visualization and configuration.
- Static UI assets are packed directly inside the binary (src/web_assets.rs) for single-file deployments.
- System Reliability:
- WAL Mode SQLite Database: Enforces Write-Ahead Logging and busy timeouts to safely query metrics and save configurations concurrently.
- Hardware Watchdog: Monitors MainsMeter activity and exits the process to allow systemd service restarts if communication links freeze.
- Rust Toolchain: Rust 2024 edition (
cargoandrustc). - System Libraries:
libssl-devandpkg-config(required for HTTPS/SSL connections). - External Broker: An MQTT broker (such as
mosquitto) is required for inter-task messaging.
# On Debian/Ubuntu systems:
sudo apt-get install build-essential libssl-dev pkg-config mosquittoIf you have modified any files in the frontend web folder (web/), you must recompile and pack them into the Rust source code using the python utility script:
python3 scripts/pack_assets.pyBuild a release-optimized binary using standard Cargo profiles:
cargo build --releaseThe compiled binary will be available at target/release/PowerScraper.
A helper script is provided to bundle the binary, systemd services, and configurations into a standard Debian package (.deb) for deployment.
The build script supports cross-compilation target arguments:
./scripts/build_deb.sh <architecture> <rust_target_triple>- Build locally (AMD64 / x86_64):
./scripts/build_deb.sh amd64 x86_64-unknown-linux-gnu
- Build for target system (ARM64 / aarch64):
./scripts/build_deb.sh arm64 aarch64-unknown-linux-gnu
The output package will be generated inside the dist/ directory (e.g. dist/powerscraper_1.0.68_arm64.deb).
Install the generated package on the target device:
sudo dpkg -i dist/powerscraper_1.0.68_arm64.debStart and enable the systemd daemon:
sudo systemctl daemon-reload
sudo systemctl enable powerscraper.service
sudo systemctl start powerscraper.serviceThe new Rust implementation uses the same TOML structure and is fully backwards-compatible with the older Python config.toml file.
You can import your configuration using two different methods:
- Copy your existing
config.tomlfile to the root directory wherePowerScraperis run. - Ensure there is no existing SQLite database file (
config.db). - Start the application. PowerScraper will detect
config.toml, parse it, and automatically seed and initialize theconfig.dbdatabase.
- Start the application to initialize a blank database.
- Open the Web Dashboard in your browser.
- Navigate to Settings and click the Import Config button.
- Select and upload your old
config.tomlfile to parse and apply it to the database instantly.
This repository enforces a Git pre-commit hook (scripts/pre-commit) to guarantee code quality. The hook automatically executes:
cargo fmtformat validation.cargo clippy --all-targets -- -D warningslint check.RUSTDOCFLAGS="-D warnings" cargo doc --no-depsdocumentation links validation.- Unit/integration test execution.
- Increments the patch version in
Cargo.tomland updatesCargo.lockwith the synced version before staging both files.