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 (as I got many request regarding those drivers. They are in place, you do not have to do anything).
You can check the existence on your system with "cat /lib/modules/$(uname -r)/modules.builtin" for drives build statically into the Kernel and "ls ls /lib/modules/$(uname -r)/kernel/drivers/rtc" for the drivers compiled as module.

  • 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 and self.alert_email() in the python script "picofssd" (e.g. in PiModules/code/python/upspico/picofssd/scripts or edit it in the new location after installation e.g. /storage/upspico/usr/bin)

 

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: 

[code]
[install]
root=/storage/upspico
[/code]

 

run

[code]
python setup.py install
[/code]

 

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

[code]
[install]
root=/storage/upspico
[/code]

While you are in the picofssd folder, you might want to use the opportunity to disable the eMail functionality unless you managed to install "jinja2".
Comment out the instantiation of the sendEmail class, its invocation and self.alert_email() in the python script "picofssd"

 

run

[code]
python setup.py install
[/code]

 

Install xmltodict:

[code]
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
[/code]

 

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

[code]
echo "rm -f /storage/upspico/usr/bin/picofssd.pid" >> ~/.config/autostart.sh
echo "python /storage/upspico/usr/bin/picofssd --log-level 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
[/code]

 

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

[code]
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
[/code]

 

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

[code]
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 http://www.forum.pimodules.com/viewtopic.php?f=20&t=3442 for an explanation
dtparam=i2c1_baudrate=10000
[/code]

 

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

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

 

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

[code]
# hwclock -s
# hwclock -r
Thu Mar 9 17:33:23 2017 0.000000 seconds
[/code]

 

Now add the following to the top of picofssd:

[code]
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')
[/code]

 change:

[code]
import xmltodict
[/code]

to

[code]
from xmltodict import xmltodict
[/code]

 

 

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

Add the following to pico_status.py:

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

 

run pico_status.py:

[code]
# 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 *
**********************************************
[/code]

 

Pull the power and run pico_status.py again:

[code]
# 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 *
**********************************************
[/code]

 

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. 

[code]
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
[/code]

 

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

[code]
tail -f /var/log/picoisd.log
[/code]

 

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

[code]
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}
[/code]

 

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:

[code]
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
[/code]

 

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

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

 

Now you can update the PIco firmware as usual.