I am currently trying to make the UPS PIco HV3.0A Stack Plus from πmodules fly on LibreELEC 8 running on a RASPBERRY PI 3 MODEL B. I'll update this post as I make progress.

First of all, all stuff is in place in regards to the drivers needed for the RTC part.

  • rtc-ds1307 is available as module
  • i2c-dev is compiled into the Kernel
  • i2c-bcm2708 is compiled into the Kernel

On the software side two Python packages are missing: XMLTODICT and JINJA2.

  • To enable picofssd to talk to the PIco, you need to install the addon "rpi-tools" which provides RPi.GPIO
  • To read the config file for picofssd we need xmltodict.
  • To send emails we need to download & compile "jinja2"
    This is on my TODO-List - didn't set up a LibreELEC dev system yet
    We can easily work around this flaw by deactivate the eMail feature.
    --> Comment out the instantiation of the sendEmail class, its invocation in picofssd and self.alert_email()

 

Go to "PiModules/code/python/package" and change the install path and change the file "setup.cfg". YOu can of course choose any other location: 

 
[install]
root=/storage/upspico
 

 

run

 
python setup.py install
 

 

Go to "PiModules/code/python/upspico/picofssd" and change the install path and change the file "setup.cfg":

 
[install]
root=/storage/upspico
 

 

run

 
python setup.py install
 

 

Install xmltodict:

 
wget https://github.com/martinblech/xmltodict/archive/master.zip
unzip master.zip
mkdir -p ~/upspico/usr/lib/python2.7/site-packages/xmltodict
cp -av xmltodict-master/xmltodict.py /storage/downloads/python-modules/xmltodict/
touch /storage/downloads/python-modules/xmltodict/__init__.py
chmod +x /storage/downloads/python-modules/xmltodict/__init__.py
 

 

add the following to your "~/.config/autostart.sh":

 
echo "rm -f /storage/upspico/usr/bin/picofssd.pid" >> ~/.config/autostart.sh
echo "python /storage/upspico/usr/bin/picofssd --log-leve info --pid-file /storage/upspico/usr/bin/picofssd.pid --xml-config /storage/upspico/etc/pimodules/picofssd/picofssd.xml" >> ~/.config/autostart.sh
chmod +x ~/.config/autostart.sh
 

 

and the following to your "~/.config/shutdown.sh":

 
echo "cat /storage/upspico/usr/bin/picofssd.pid | xargs kill -s 15" >> ~/.config/shutdown.sh
echo "rm -f /storage/upspico/usr/bin/picofssd.pid" >> ~/.config/shutdown.sh
chmod +x ~/.config/shutdown.sh
 

 

remount /flash in rw mode and add the following to /flash/config.txt to get the RTC running

 
dtparam=i2c_arm=on
enable_uart=1
dtoverlay=i2c-rtc,ds1307
# Since LibreELEC 8 is running Kernel 4.9.8 we need to add the below
# See <a href="http://www.forum.pimodules.com/viewtopic.php?f=20&amp;t=3442">http://www.forum.pimodules.com/viewtopic.php?f=20&amp;t=3442</a> for an explanation
dtparam=i2c1_baudrate=10000
 

 

Add the rtc-ds1307 module to /etc/modules-load.d/usv.conf to be loaded on startup:

 
echo "rtc-ds1307" > /etc/modules-load.d/ups.conf
 

 

run "hwclock -s" to set the current time on the RTC device, run "hwclock -r" to get the curretn time from the RTC device

 
# hwclock -s
# hwclock -r
Thu Mar 9 17:33:23 2017 0.000000 seconds
 

 

Now add the following to the top of picofssd:

 
import sys
sys.path.append('/storage/.kodi/addons/virtual.system-tools/lib')
sys.path.append('/storage/.kodi/addons/virtual.rpi-tools/lib')
sys.path.append('/storage/upspico/usr/lib/python2.7/site-packages')
 

 change:

 
import xmltodict
 

to

 
from xmltodict import xmltodict
 

 

 

To run pico_status.py you need the additional addon system-tools which provides provides smbus

Add the following to pico_status.py:

 
import sys
sys.path.append('/storage/.kodi/addons/virtual.system-tools/lib')
 

 

run pico_status.py:

 
# python pico_status.py
**********************************************
* UPS PIco HV3.0A Status *
* Version 5.0 *
**********************************************
 
UPS PIco Firmware.....: 24
UPS PIco Bootloader...: 50
UPS PIco PCB Version..: 41
UPS PIco BATT Version.: LiPO (ASCII: P)
UPS PIco BATT Runtime.: 216 MIN
UPS PIco rs232 State..: ERROR
 
Powering Mode.........: BATT POWERED
Charger State.........: ERROR
Battery Percentage....: 100 %
Battery Voltage.......: 3.95 V
RPi Voltage...........: 0.0 V
 
**********************************************
* Powered by PiModules *
**********************************************
 

 

Pull the power and run pico_status.py again:

 
# python pico_status.py
**********************************************
* UPS PIco HV3.0A Status *
* Version 5.0 *
**********************************************
 
UPS PIco Firmware.....: 24
UPS PIco Bootloader...: 50
UPS PIco PCB Version..: 41
UPS PIco BATT Version.: LiPO (ASCII: P)
UPS PIco BATT Runtime.: 216 MIN
UPS PIco rs232 State..: ERROR
 
Powering Mode.........: BATT POWERED
Charger State.........: ERROR
Battery Percentage....: 100 %
Battery Voltage.......: 3.95 V
RPi Voltage...........: 0.0 V
 
**********************************************
* Powered by PiModules *
**********************************************
 

 

Since the picofssd can't be configured to execute some tasks before shutting down the system after N seconds once the on-battery status is reported by the UPS PIco for more than X seconds, I quickly wrote a daemon "pico instant shutdown daemon" (picoisd) to do exactly this. You can easily modify this daemon to execute whatever you want before the system shuts down. Just make sure your PIco is set to shutdown later then this daemon will initiate the shutdown.
Just place those two files onto your Pi and your Pi will shutdown if the on-battery status is reported for more than 40 seconds. 

 
wget -O /usr/local/bin/picoisd https://olausson.de/media/my_files/upspico/picoisd.py
wget -O /etc/init.d/picoisd https://olausson.de/media/my_files/upspico/picoisd.init
chmod +x /usr/local/bin/picoisd
systemctl enable picoisd
systemctl start picoisd
 

 

To check if it works, tail the log file and disconnect/reconnect your Pi from the primary power source 

 
tail -f /var/log/picoisd.log
 

 

Until I figured out on how to use systemd on LibreELEC, just do the following:

 
wget -O /storage/picoisd https://olausson.de/media/my_files/upspico/picoisd.py
chmod +x /storage/picoisd
echo "/usr/bin/python /storage/picoisd start" >> /storage/.config/autostart.sh
echo "/usr/bin/python /storage/picoisd stop" >> /storage/.config/shutdown.sh
chmod +x /storage/.config/{autostart.sh,shutdown.sh}
 

 

Now your LibreELEC based home entertainment system should do a clean shutdown if disconnected it from its primary power source.

 

If you want to update the firmware of your PIco you need to follow the manual as usual but you have to manually install "pyserial" first:

 
cd ~/downloads
wget https://github.com/pyserial/pyserial/archive/master.zip
unzip master.zip
cd pyserial-master/
echo "[install]" >> setup.cfg
echo "root=/storage/upspico" >> setup.cfg
python setup.py install
 

 

after that you need to add the following to firmware update script "9600_picofuHV3.0.py"

 
import sys
sys.path.append('/storage/.kodi/addons/virtual.system-tools/lib'
sys.path.append('/storage/upspico/usr/lib/python2.7/site-packages')
 

 

Now you can update the PIco firmware as usual.

 

Filename Size Date & Time
A file of unknown type picoisd.init 3.17 KB 2017-03-13 17:55:23
A code file picoisd.py 4.59 KB 2017-03-13 17:55:23