I am trying to get a juice4halt hat working with my Pi 3+ running LibreELEC. A script makes the hat work. It is suppose to safely shutdown the OS after power is lost, then power off the Pi. It works correctly with the original script running under Raspbian. I modified the script to move the directory structure to storage which is writable under LibreELEC. The modified script works as if it does not see the juice4halt hat and shuts down the OS at the completion of booting, which is what is suppose to happen when the juice4halt hat is not detected.
Below are the original script and the modified script
ORIGINAL
Original
#!/bin/bash
#title :shutdown_script
#description :This script runs on Raspberry Pi equipped with the Juice4Halt module.
#author :Nelectra s.r.o.
#date :20190415
#version :1.2 (bug fixed: collision with the rebootj4h script solved by reading the GPIO25 pin 2x)
#usage :copy this file to /home/pi/juice4halt/bin/
# and make it executable: sudo chmod 755 shutdown_script
#notes :Juice4halt – Supercapacitor UPS for RPi
#copyright :GNU GPL v3.0
#==============================================================================
#create directory for working with GPIO and wait
echo "25" > /sys/class/gpio/export
sleep 0.2s
# use the pin as an open-drain output, send a short LOW pulse (= Booting finished, shutdown_script runs, automatic shutdown enabled)
# then change to input and listen
# if a LOW is sent from the J4H then start with the shutdown
# set GPIO25 as output and set output to LOW
echo "out" > /sys/class/gpio/gpio25/direction
echo "0" > /sys/class/gpio/gpio25/value
sleep 0.1s
echo "in" > /sys/class/gpio/gpio25/direction
#wait until pin rises to HI
sleep 0.1s
pinval1="1" # 1st reading
pinval2="1" # 2nd reading
#to be resistant to short pulses (e.g. 100ms pulse generated by the rebootj4h script) two readings 200ms apart from each other are required
while [ "$pinval1" != "0" -o "$pinval2" != "0" ]
do
#reading the value of the input pin
pinval1=$(cat /sys/class/gpio/gpio25/value)
#wait
sleep 0.2s
#reading the value of the input pin again 0.2s later
pinval2=$(cat /sys/class/gpio/gpio25/value)
done
# set GPIO25 as output and set output to LOW
echo "out" > /sys/class/gpio/gpio25/direction
echo "0" > /sys/class/gpio/gpio25/value
# wait for system halt
# after system halted the pin will be automatically switched to input and the level will be pulled up to HI
# a LOW to HI transition signals to the J4H to turn the power off
echo ""
echo "Juice4halt: Power failure, RPi will now shut down."
sudo halt
--------------------------------------------
MODIFIED
Modified
#!/bin/bash
#title :shutdown_script
#description :This script runs on Raspberry Pi equipped with the Juice4Halt module.
#author :Nelectra s.r.o.
#date :20190415
#version :1.2 (bug fixed: collision with the rebootj4h script solved by reading the GPIO25 pin 2x)
#usage :copy this file to /home/pi/juice4halt/bin/
# and make it executable: sudo chmod 755 shutdown_script
#notes :Juice4halt – Supercapacitor UPS for RPi
#copyright :GNU GPL v3.0
#==============================================================================
#create directory for working with GPIO and wait
echo "25" > /sys/class/gpio/export
sleep 0.2s
# use the pin as an open-drain output, send a short LOW pulse (= Booting finished, shutdown_script runs, automatic shutdown enabled)
# then change to input and listen
# if a LOW is sent from the J4H then start with the shutdown
# set GPIO25 as output and set output to LOW
# echo "out" > /sys/class/gpio/gpio25/direction
echo "out" > /storage/home/pi/juice4halt/gpio/gpio25/direction
# echo "0" > /sys/class/gpio/gpio25/value
echo "0" > /storage/home/pi/juice4halt/gpio/gpio25/value
sleep 0.1s
# echo "in" > /sys/class/gpio/gpio25/direction
echo "in" > /storage/home/pi/juice4halt/gpio/gpio25/direction
#wait until pin rises to HI
sleep 0.1s
pinval1="1" # 1st reading
pinval2="1" # 2nd reading
#to be resistant to short pulses (e.g. 100ms pulse generated by the rebootj4h script) two readings 200ms apart from each other are required
while [ "$pinval1" != "0" -o "$pinval2" != "0" ]
do
#reading the value of the input pin
pinval1=$(cat /storage/home/pi/juice4halt/gpio/gpio25/value)
#wait
sleep 0.2s
#reading the value of the input pin again 0.2s later
pinval2=$(cat /storage/home/pi/juice4halt/gpio/gpio25/value)
done
# set GPIO25 as output and set output to LOW
# echo "out" > /sys/class/gpio/gpio25/direction
echo "out" > /storage/home/pi/juice4halt/gpio/gpio25/direction
# echo "0" > /sys/class/gpio/gpio25/value
echo "0" > /storage/home/pi/juice4halt/gpio/gpio25/value
# wait for system halt
# after system halted the pin will be automatically switched to input and the level will be pulled up to HI
# a LOW to HI transition signals to the J4H to turn the power off
echo ""
echo "Juice4halt: Power failure, RPi will now shut down."
halt
Modified
----------------------
I can # out the last line and let LibreELEC boot and start Kodi. Then SSH into the device and see that the script is running. It is creating the files (value and direction) in the correct location.
I am a novice, but it acts to me like it is not sensing the voltage on gpio25.
Can someone give me some help on getting this to work?
Thanks in advance!