I'm running a BananaPi (Model 1) on bananian, headless, as a git server. Originally I had a SSD attached, but I switched back to a MicroSD card with 64GB, which suffices for this purpose.
Unfortunately the filesystem crashed on uncontrolled powerdowns, so I wanted to attach the Banana to a UPS.
I got the StromPI extension board from joy-it , which is said to be "compatible" with BananaPi (BPi). The manual  describes two modes this boards can run, namely UPS and WIDE, the latter allows to run a Pi within a range from 6V- 36V. For detection of main power failure the Test-Pin must be connected to some GPIO port. The corresponding software  provides two Python programs for the UPS mode. One sends an email when the system switches to aux power, the other shuts down the system safely.
I wanted to stack the board on top of the BPi, to keep it compact. There are two obstacles:
The solution for me was a wire cutter, see below. Of course, the board doesn't have to sit on top, keep it where you want, just observe the correct wiring.
Installing the required python-dev package for the software didn't work. Since GPIO can also be accessed through the shell  and , I was going for a shell script.
To map GPIO numbers and names between BananaPi and RaspberryPi Model A, see  and , the first pin layout drawing. You can run the LED experiment on the raspberry page from shell to verify the assignment of GPIO 0 of BananaPI to BCM 17 of RaspberryPi. I checked other ports and found that GPIO 1 of BPi was addressed by BCMs 18 +19 RPi, while the other ports were as expected.
Here is the powerdown.sh:
#! /bin/bash # (c) 2017, Guido Lutterbach, smartypies.com # init GPIO 17 = GPIO0 on Bananapi GPIOPORT=17 # reset GPIO - not necessary for boot script, helpful for command line tests if [ -d /sys/class/gpio/gpio$GPIOPORT ] then echo $GPIOPORT > /sys/class/gpio/unexport sleep 0.5 fi # setup GPIO echo $GPIOPORT > /sys/class/gpio/export echo in > /sys/class/gpio/gpio$GPIOPORT/direction # this prevents noise signaling "power down" echo up > /sys/class/gpio/gpio$GPIOPORT/pull while $true do CURRENT_STATE=$(cat /sys/class/gpio/gpio$GPIOPORT/value) if [ "$CURRENT_STATE" == "1" ] then #echo "main power down; check again in 30 sec." sleep 30 CURRENT_STATE=$(cat /sys/class/gpio/gpio$GPIOPORT/value) if [ "$CURRENT_STATE" == "1" ] then break fi fi # check every 1/10 sec sleep 0.1 done shutdown -h now
Running this script from command line and unplugging the main supply, the UPS switched to battery mode (green LED off, blue LED on). Plugging main power in within 30 sec, reverted this and the Banana kept running. Otherwise, shutdown after 30 seconds. WOMM!
I start this script as a system demon during boot. There are many pages describing the usage of init scripts e.g. , please follow their instructions.
For starting the BananaPi after a power failure, with StromPI board and main power up, push the reset button.