OL DISCHRG错误修复与NUT参数优化
在群晖(DSM)上使用正常的 APC BK650M2-CH,接入 UNRAID 后,使用自带的UPS 设置或安装NUT(Network UPS Tools)插件可能会在状态栏持续显示异常的 On Line - Discharging Battery。
此问题通常发生在老版本固件的 BK650M2-CH 上,属于固件在 USB HID 协议下的标志位误报,并不影响实际硬件功能。以下为修复显示 Bug 及针对 UNRAID 关机特性的配置文件优化方案。
一、 原因分析
固件标志位乱码:
老固件 APC 在电池充到 99%~100% 浮充阶段时,其 USB 芯片会同时输出 OL(在线)、CAL(校准)和 DISCHRG(放电)标志位。NUT 的默认逻辑容易把其中的 DISCHRG 误判为“断电放电”。
USB 芯片通信“假死”:
拔掉市电瞬间,该型号的 USB 控芯片经常不会主动通过 Interrupt Pipe 上报事件,导致 Linux 系统拿到的数据停留在断电前(显示 220V 电压和 OL 状态)。
解决方案:
直接使用驱动原生的 onlinedischarge_calibration 参数,将老固件的 OL+DISCHRG/CAL 识别为校准/浮充,而非断电。
二、 UNRAID 配置文件优化
将 UNRAID 网页设置中的 Enable Manual Configuration 改为 for UPS Driver,并选择**default (2.8.5 stable)**驱动,然后在 /etc/nut/ups.conf 中追加以下完整配置:
# 【修复】
# 将轮询间隔缩短为 1 秒
pollinterval = 1
# 当 USB 接口不主动上报事件时,容忍 2 次后强制重置/踢醒 USB 管道
interrupt_pipe_no_events_tolerance = 2
# 开启异步模式,防止 USB 数据阻塞导致状态滞后
synchronous = no
# 将老固件的 OL+DISCHRG/CAL 识别为校准/浮充,而非断电
onlinedischarge_calibration
# 【额外选项】
# 市电恢复(来电)后,UPS 强制等待 60 秒再恢复插座供电,防止刚来电时电网闪断冲击硬件
ondelay = 60
# 降低对市电波动的敏感度(low),防止家里开启大功率电器时 UPS 频繁无意义地切到电池供电(low/medium/high)
default.input.sensitivity = low
三、 UNRAID GUI 匹配设置
在 UNRAID 的 Settings -> NUT Settings 中完成对应修改:
- Enable Manual Configuration:
for UPS Driver - UPS Battery Runtime Attribute:
battery.runtime - Shutdown Mode:
Time on Battery(建议设为4分钟)或Battery Level(设为30%) - Disable UPS Power after Shutdown:
Yes - Battery Replacement Notification:
Yes
四、 验证结果
保存并点击 Restart NUT 重启服务后,日志如下:
Aug 12 08:27:33 Tower ool www[2061217]: /usr/local/emhttp/plugins/nut-dw/scripts/start
Aug 12 08:27:34 Tower rc.nut: Writing NUT configuration...
Aug 12 08:27:34 Tower rc.nut: Updating permissions for NUT...
Aug 12 08:27:34 Tower rc.nut: Checking if the NUT Runtime Statistics Module should be enabled...
Aug 12 08:27:34 Tower rc.nut: Disabling the NUT Runtime Statistics Module...
Aug 12 08:27:35 Tower rc.nut: Network UPS Tools upsdrvctl - UPS driver controller 2.8.5 release
Aug 12 08:27:35 Tower rc.nut: Network UPS Tools 2.8.5 release - Generic HID driver 0.71
Aug 12 08:27:35 Tower rc.nut: USB communication driver (libusb 1.0) 0.53
Aug 12 08:27:35 Tower rc.nut: HIDParse: LogMax is less than LogMin. Vendor HID report descriptor may be incorrect; interpreting LogMax -1 as 255 in ReportID: 0x0c
Aug 12 08:27:35 Tower rc.nut: HIDParse: LogMax is less than LogMin. Vendor HID report descriptor may be incorrect; interpreting LogMax -1 as 255 in ReportID: 0x22
Aug 12 08:27:35 Tower rc.nut: HIDParse: LogMax is less than LogMin. Vendor HID report descriptor may be incorrect; interpreting LogMax -1 as 255 in ReportID: 0x40
Aug 12 08:27:35 Tower rc.nut: Using subdriver: APC HID 0.101
Aug 12 08:27:35 Tower rc.nut: Defaulting lbrb_log_delay_sec=3 for American Power Conversion model BK650M2-CH; consider also setting the lbrb_log_delay_without_calibrating and/or and/or onlinedischarge_log_throttle_sec flag(s) in your configuration
Aug 12 08:27:35 Tower usbhid-ups[2074800]: Listening on socket /var/run/nut/usbhid-ups-ups
Aug 12 08:27:35 Tower rc.nut: Listening on socket /var/run/nut/usbhid-ups-ups
Aug 12 08:27:35 Tower usbhid-ups[2074802]: Startup successful: usbhid-ups
Aug 12 08:27:36 Tower rc.nut: Network UPS Tools upsd 2.8.5 release
Aug 12 08:27:36 Tower rc.nut: listening on 0.0.0.0 port 3493
Aug 12 08:27:36 Tower upsd[2074836]: listening on 0.0.0.0 port 3493
Aug 12 08:27:36 Tower upsd[2074836]: Connected to UPS [ups]: usbhid-ups-ups
Aug 12 08:27:36 Tower rc.nut: Connected to UPS [ups]: usbhid-ups-ups
Aug 12 08:27:36 Tower usbhid-ups[2074802]: sock_connect: enabling asynchronous mode (fixed)
Aug 12 08:27:36 Tower upsd[2074836]: Found 1 UPS defined in ups.conf
Aug 12 08:27:36 Tower rc.nut: Found 1 UPS defined in ups.conf
Aug 12 08:27:36 Tower upsd[2074837]: Startup successful: upsd
Aug 12 08:27:36 Tower rc.nut: Network UPS Tools upsmon 2.8.5 release
Aug 12 08:27:36 Tower rc.nut: UPS: ups@127.0.0.1 (primary) (power value 1)
Aug 12 08:27:36 Tower rc.nut: Using power down flag file /etc/nut/killpower
Aug 12 08:27:36 Tower upsmon[2074840]: Startup successful: upsmon
Aug 12 08:27:36 Tower upsmon[2074840]: Warning: running as one big root process by request (upsmon -p)
Aug 12 08:27:36 Tower upsd[2074837]: User monuser@127.0.0.1 logged into UPS [ups]
Aug 12 08:27:56 Tower upsmon[2074840]: UPS ups@127.0.0.1 on battery
Aug 12 08:27:56 Tower nut-notify[2075310]: is now handling ONBATT
Aug 12 08:27:56 Tower nut-notify[2075310]: [ups] UPS is on battery. The system will shutdown in 300 seconds.
Aug 12 08:27:56 Tower nut-notify[2075310]: Executing user's hook script for ONBATT (as non-blocking)...
Aug 12 08:27:56 Tower nut-notify[2075310]: Sending OS notifications...
Aug 12 08:27:56 Tower xnut-notify-hooks.sh[2075310]: ONBATT commands are now executing in background...
Aug 12 08:27:56 Tower nut-notify[2075310]: Shutdown criteria are now being monitored...
Aug 12 08:28:06 Tower upsmon[2074840]: UPS ups@127.0.0.1: calibration in progress
Aug 12 08:28:11 Tower upsmon[2074840]: UPS ups@127.0.0.1: calibration finished
Aug 12 08:28:11 Tower upsmon[2074840]: UPS ups@127.0.0.1 on line power
Aug 12 08:28:11 Tower nut-notify[2075703]: is now handling ONLINE
Aug 12 08:28:11 Tower nut-notify[2075703]: Terminating monitoring instances of the program...
Aug 12 08:28:11 Tower nut-notify[2075703]: kill -s SIGTERM 2075310
Aug 12 08:28:11 Tower nut-notify[2075703]: [ups] UPS is online, any planned shutdowns were cancelled.
Aug 12 08:28:11 Tower nut-notify[2075703]: Executing user's hook script for ONLINE (as non-blocking)...
Aug 12 08:28:11 Tower xnut-notify-hooks.sh[2075703]: ONLINE commands are now executing in background...
Aug 12 08:28:11 Tower nut-notify[2075703]: Sending OS notifications...
Aug 12 08:28:11 Tower nut-notify[2075310]: has received a termination signal
Aug 12 08:28:11 Tower nut-notify[2075310]: is now exiting from handling ONBATT
Aug 12 08:28:11 Tower nut-notify[2075703]: is now exiting from handling ONLINE
市电正常(100% 满电):
状态准确显示为干净的 On Line 或 Calibrating,不再弹出关机倒计时。
真实断电(拔掉插头):
底层 USB 重置机制会在 2~3 秒内将 input.voltage 强行刷为 0.0V,系统立刻准确捕获 ONBATT 信号,弹出通知并启动倒计时关机。
市电恢复(重新插电):
系统自动中断并取消关机进程,恢复常态监控。