Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

⚡ Wattson

Universal Digital PSU Monitoring Library

Universal Digital PSU Monitoring Library — Energy Sensing Layer of the ExoMind Ecosystem

通用数字电源监控库 — ExoMind 生态的能量感知层

License: CCOPL-1.0 Rust CI


💡 Why Wattson? / 为什么做这个?

Digital PSUs (数字电源) expose real-time telemetry over USB — voltages, currents, temperatures, fan speed — but the vendor software (e.g., HiMOS) typically only refreshes once every 1–2 seconds, with no data export or cost tracking. For anyone who wants to:

  • Monitor electricity costs — know exactly how much it costs to run your PC per day/week/month
  • Integrate power data into research workflows, home automation, or dashboards
  • Push the sampling rate — Wattson queries at 300ms (3.3 Hz), 3–6× faster than vendor tools
  • Understand the protocol — reverse-engineer and document the binary serial protocol for future hardware

We built Wattson. It started with a Segotep DM-1000G and curiosity about what's actually on the wire. The protocol turned out to be straightforward (header + big/little-endian uint16 arrays + checksum), and the result is a general-purpose library that could support any digital PSU with similar serial protocols.

数字电源通过 USB 暴露实时遥测数据,但厂商软件(如 HiMOS)刷新慢(1–2秒)、不能导出数据、没有电费统计。我们想知道开一天电脑到底花多少钱,想把功率数据接入自己的研究流程,想把采样率推到极限。于是从逆向鑫谷 DM-1000G 的串口协议开始,写了这个通用数字电源监控库。


📊 Real-time Monitoring / 实时监控

Wattson Native GUI Dashboard — DM-1000G Live Monitoring

Native GUI dashboard: egui + wgpu, exported from the app itself with live DM-1000G data

原生 GUI 仪表盘:egui + wgpu,由应用内原生导出,展示 DM-1000G 实时数据

Legacy TUI / 传统 TUI

Wattson TUI Dashboard — DM-1000G Real-time Monitoring

TUI dashboard: power trend chart, DC rails, thermal & fan, cost tracking

TUI 面板:功率趋势、DC 电压、温度风扇和电费统计

Metric Min Max Avg
AC Input Power 133W 236W 162W
DC Output Power 117W 193W 137W
Efficiency 82% 91% 86%

✨ Features / 功能特点

  • 🖼️ Native GUI dashboard (egui + wgpu) — GPU-backed desktop UI with live charts, theme switching, and control-side settings 原生桌面界面(egui + wgpu)— GPU 渲染实时图表、主题切换和图形控制设置
  • 📸 Native screenshot export — export the complete GUI window from inside the app without depending on OS-level window capture 原生截图导出 — 由应用内部直接导出完整 GUI,不依赖操作系统层面的窗口抓屏
  • 🌀 Fan write control (0x13 / 0x1B) — set fan mode, flat PWM, or custom curve through the same background serial session 风扇写入控制(0x13 / 0x1B)— 通过同一个后台串口会话设置风扇模式、固定占空比或自定义曲线
  • 🔌 Real-time power monitoring — AC input (EMA-smoothed), DC output, conversion efficiency 实时功率监控 — AC 输入(EMA 平滑)、DC 输出、转换效率
  • 📈 TUI dashboard with live chart — Dual-line power trend (AC red / DC cyan), auto-zoom Y-axis, Braille markers TUI 面板 + 实时图表 — 双线功率趋势、自动缩放 Y 轴
  • 💰 Electricity cost tracking — Session-wide average power → day/week/month projections. Energy accumulated via numerical integration (left Riemann sum, f64 precision — safe for years of continuous operation) 电费追踪 — 全程平均功率推算日/周/月费用,数值积分累加能量(f64 精度,可连续运行数年无溢出)
  • 📊 Chart generation — Power/efficiency/temperature curves as PNG 图表生成 — 功率/效率/温度曲线
  • 🖥️ Three modes — CLI (one-shot), TUI (dashboard), API (HTTP server) 三种传统模式仍保留 — 命令行、终端面板、HTTP API
  • 🌗 Theme support — Light / Dark / System modes with persisted GUI settings 主题支持 — 浅色 / 深色 / 跟随系统,并持久化图形设置
  • ⚙️ Independent rate control — TUI refresh (200ms–2s) and serial poll (200ms–5s) independently adjustable at runtime 独立速率控制 — TUI 刷新率和串口发包率运行时独立可调
  • 🔄 Active query by default — 300ms poll interval, 3.3× faster than vendor software (HiMOS) 默认主动查询 — 300ms 轮询,比厂商软件快 3.3 倍

GUI Controls / 图形控制项

Control 控制 Description 说明
Theme 主题 System / Light / Dark
Chart Window 图表窗口 30–600 seconds
UI Refresh 刷新率 16–1000 ms
Serial Poll 轮询间隔 200–5000 ms
Series 曲线显隐 AC / DC independently toggleable
Scale 缩放 Auto / Zero Based
Serial Visibility 序列号显示 masked by default, optional full reveal 默认脱敏,可手动显示完整值
Screenshot Export 截图导出 export the current GUI as PNG from inside the app 应用内直接导出当前 GUI 为 PNG
Fan Mode 风扇模式 Auto / Silent / Performance / Custom / Clean
Manual PWM 固定占空比 0–100%, sends a flat custom curve
Custom Curve 自定义曲线 3 editable control points + fixed 0C/100C endpoints

TUI Hotkeys / TUI 快捷键

Key 按键 Action 功能
q Quit 退出
a / s / p / u / c Set fan mode: auto / silent / performance / custom / clean 切换风扇模式
h / l Decrease / increase manual PWM target by 5% 调整手动占空比目标
m Apply current manual PWM target 应用当前手动占空比
z Toggle chart scale: auto-zoom / zero-based 切换图表缩放模式
+ / - Adjust TUI refresh rate (200ms–2000ms) 调节画面刷新率
] / [ Adjust serial poll rate (200ms–5000ms) 调节串口发包率

Algorithm / 算法说明

AC Input    = EMA-smoothed instantaneous power (α=0.5)
              EMA 平滑后的瞬时功率

AC Average  = total_wh / duration_h  (session-wide, stabilizes over time)
              全程累计能量 ÷ 运行时长 = 真实平均功率

Energy (Wh) = Σ P(tᵢ) × Δtᵢ  (numerical integration, f64 accumulator)
              数值积分,每个 tick 累加 功率×时间间隔

Cost        = energy_kwh × price_per_kwh
Daily est.  = session_avg_w × 24h / 1000 × price

🔧 Supported Hardware / 支持的硬件

Brand 品牌 Series 系列 Interface 接口 Status 状态
Segotep 鑫谷 DM series (DM-850G, DM-1000G, ...) CH340 UART 115200-8N1 ✅ Tested 已验证
Segotep 鑫谷 KE series (KE-1300P) CH340 UART 115200-8N1 🔧 Compatible 兼容
Others 其他 Contributions welcome 欢迎贡献

🚀 Quick Start / 快速开始

Install / 安装

# From source
git clone https://github.com/exomind-team/wattson.git
cd wattson
cargo build --release

Initialize / 初始化

# Generate config file
wattson config init

# Check available ports
wattson ports

Usage / 使用

# Default desktop launch (GUI-first)  默认启动原生 GUI
wattson

# Native GUI with live PSU data  用真实电源数据启动 GUI
wattson gui

# Native GUI with deterministic demo data  用演示数据启动 GUI
wattson gui --demo

# One-shot read (JSON output)  一次读取
wattson read

# Read for 60 seconds  读取 60 秒
wattson read --duration 60

# Continuous JSON stream  持续输出
wattson watch

# Interactive TUI dashboard  交互式面板
wattson tui

# HTTP API server  API 服务器
wattson serve

# Set manual fan PWM (flat custom curve)  设置固定风扇占空比
wattson fan set 55

# Set fan mode  设置风扇模式
wattson fan mode custom

# Apply a custom curve  应用自定义风扇曲线
wattson fan curve "[[30,40],[50,55],[70,75]]"

# Generate chart  生成图表
wattson chart --last 60

Screenshot Export / 截图导出

# Launch the native GUI with live data  启动真实数据 GUI
wattson gui

# Launch the TUI dashboard  启动 TUI 面板
wattson tui
  • In the GUI, click Export Screenshot 导出截图 to save a PNG into docs/screenshots/
  • GUI 导出走应用内原生渲染路径,不依赖外部窗口位置、焦点或整屏截图
  • TUI 截图当前作为文档资产维护在 docs/screenshots/legacy-tui-dashboard.png

Configuration / 配置管理

# View config  查看配置
wattson config show

# Set serial port  设置串口
wattson config set port COM4

# Set electricity price (CNY/kWh)  设置电价
wattson config set price 0.56

# Set communication mode  设置通信模式
wattson config set mode passive

API Endpoints / API 接口

When running wattson serve:

Endpoint Description
GET /api/status Full PSU snapshot 完整快照
GET /api/power Power data only (AC/DC/efficiency) 功率数据
GET /api/voltage DC voltage readings 电压
GET /api/temperature Temperature sensors 温度
GET /api/device Device info 设备信息
GET /api/cost Electricity cost 电费
POST /api/fan/speed Set flat PWM / 设置固定占空比
POST /api/fan/curve Apply custom curve / 应用自定义曲线
POST /api/fan/mode Set fan mode / 设置风扇模式
GET /health Health check 健康检查

Example requests / 请求示例:

curl -X POST http://127.0.0.1:8066/api/fan/speed \
  -H "Content-Type: application/json" \
  -d '{"pwm":55}'

curl -X POST http://127.0.0.1:8066/api/fan/mode \
  -H "Content-Type: application/json" \
  -d '{"mode":"custom"}'

curl -X POST http://127.0.0.1:8066/api/fan/curve \
  -H "Content-Type: application/json" \
  -d '{"points":[[30,40],[50,55],[70,75]]}'

🧪 Testing / 测试

# Full test suite  全量测试
cargo test

# GUI snapshot/e2e coverage  GUI 快照与端到端覆盖
cargo test --test gui_e2e -- --nocapture

📐 Configuration File / 配置文件

wattson.toml:

[serial]
port = "COM4"          # Serial port 串口
baud = 115200          # Baud rate 波特率
mode = "passive"       # passive | active 被动|主动

[device]
profile = "segotep_dm" # Device calibration profile 设备校准

[cost]
price_per_kwh = 0.56   # Electricity price 电价 (CNY/kWh)
currency = "CNY"       # Currency 货币

[chart]
output_dir = "./charts"
watermark = "Wattson | exomind-team/wattson"

[api]
port = 8066            # HTTP API port

🔬 Protocol Details / 协议细节

Wattson communicates with digital PSUs via USB serial (CH340/CH341 UART). The protocol uses a custom binary frame format:

[0x55][0x7E][LEN][CMD][DATA...][CHECKSUM][0xAE]
Packet Content Byte Order
0x02 Voltages, currents, AC input, fan RPM Little-endian
0x03 Device model string ASCII
0x04 Temperature, fan mode, AC power Big-endian
0x05 Serial number ASCII

Write support currently covers:

  • 0x13 fan mode
  • 0x1B custom fan curve with CRC-8 (poly=0x07, init=0x00)

See docs/protocol.md for reverse-engineering notes, frame samples, and current unknowns.


🙏 Acknowledgments / 致谢

Protocol reverse engineering based on:


📄 License / 许可证

CCOPL-1.0 — Contributors' Collective Ownership Public License

Copyright (c) 2026 ExoMind Collective


Part of the ExoMind ecosystem

ExoMind · ExoMind Cell · CCOPL License

About

⚡ Wattson — Universal digital PSU monitoring library. Real-time power consumption via serial protocols. Rust.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages