Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save chenzhuoyu/80576481eb0696e5dbe0301b51e6408f to your computer and use it in GitHub Desktop.
Save chenzhuoyu/80576481eb0696e5dbe0301b51e6408f to your computer and use it in GitHub Desktop.
Schneider SPM & SPRM Series UPS Support for Synology DSM 7

Schneider SPM/SPRM Series UPS Support for Synology DSM 7

Step 1: Connect your UPS and NAS with USB cable

You should see a NEW serial port (like /dev/ttyUSB0) been added to /dev. Remember that for the later steps.

If not, please refer to this GitHub repo for building and installing the driver for CH341 USB to Serial Converter chips.

Step 2: Test the connection

Edit /etc/ups/ups.conf, replace the [ups] section with

[ups]
    driver = apcsmart
    port = /dev/ttyUSB0     # The new device found in Step 1

Start apcsmart

sudo apcsmart -DDD -a ups

If it starts to print a ton of logs, the connection is good.

In some cases apcsmart reports "unable to detect an APC Smart protocol UPS", perform the following diagnostics.

  1. Check your cable connection
  2. Check your device name, ensure it is the UPS, not other one that happens to be a serial port. If this doesn't solve the problem...
  3. Get anything that can talk to /dev/ttyUSB0 at 2400 baud installed on your NAS (minicom/screen/pyserial, anything you like)
  4. Assume you have minicom, start it with sudo minicom -D /dev/ttyUSB0 -b 2400
  5. Type Y (the capital Y, must be upper case), it should print SM (for Smart Mode) according to the Protocol Specification. If not...
  6. Type Y multiple times (at least 10), if at some point the terminal prints a lot of SM, the driver is faulty, build and install a new driver from Step 1, and start over.
  7. Type A (the capital A, must be upper case), it should print OK and the UPS should beep for 2 seconds. If not, the UPS might be faulty, please contact the customer service.
  8. If none of above happens, either the device name is wrong, or the UPS is faulty, or it's not a SPM/SPRM Series UPS.

Step 3: Let DSM knows about the serial port

Edit /usr/syno/etc/ups/nutscan-usb.h (or /etc/ups/nutscan-usb.h and /etc.defaults/ups/nutscan-usb.h if you are using DSM 7.1.1), add the following line before the /* Terminating entry */ line:

{ 0x1a86, 0x5523, "apcsmart" },

Here 1a86:5523 is the VID:PID pair of the CH341 device.

Save the file and reboot your NAS.

Step 4: Force the ups-usb service to speak apcsmart through /dev/ttyUSB0

After rebooting, edit /usr/syno/lib/systemd/scripts/ups-usb.sh

  • Add a new variable right after the swarm of UPS_xxx variable definitions
UPS_PORT="/dev/ttyUSB0"     # The new device found in Step 1
  • There is a line near the beginning of function SwitchConf2Usb (mine is the first line) that looks like
/bin/sed -i "s/^\tport = .*/\tport = auto/" $UPS_CONF

Replace it with

/bin/sed -i "s|^\tport = .*|\tport = $UPS_PORT|" $UPS_CONF

NOTICE THE DELIMITER OF sed IS DIFFERENT

  • There is a line near the beginning of function StartAllDrv (mine is also the first line) that looks like
local DRV_LIST="usbhid-ups blazer_usb bcmxcp_usb richcomm_usb tripplite_usb"

Prepend apcsmart to the list, turning it into:

local DRV_LIST="apcsmart usbhid-ups blazer_usb bcmxcp_usb richcomm_usb tripplite_usb"
  • Start the service
sudo systemctl start ups-usb

After starting the service, you will notice that the UPS was recognized by DSM, and ready to configure.

Step 5: Make the service load at boot

Create a new file under directory /usr/local/etc/rc.d with name 01-ups-apcsmart.sh (or any other name you like) and content:

#!/bin/sh
systemctl $1 ups-usb

Then make it executable

sudo chmod +x /usr/local/etc/rc.d/01-ups-apcsmart.sh

Reboot your NAS. Now the UPS should be auto-detected by your NAS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment