This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Shutdown Management and Geekworm x729 UPS
#1
Has anybody been able to get Safe Shutdown working with the Geekworm x729.

I have been able to get the Power Off working with the following settings:
GPIO 26 - 37
Transition: low->high

When I use the settings for Safe Shutdown it either doesn't work or enters a shutdown loop where as soon as it gets booted up it shuts down. This happens before I can even SSH in and figure out what is happening or disable. I end up having to reformat and start over. I think the x729 does a pull up right at the beginning and this causes the OpenPlotter monitor to think its time for a safe shutdown
GPIO 6 - 31
Transition: low->high (I think. Tried both)
GPIO Pull: pull-up (I think. Tried all 3)

I am able to get Safe Shutdown working with the directions from https://wiki.geekworm.com/X729-script creating a service. But, it does not handle shutting down the UPS from the desktop shutdown or 'sudo shutdown now'. These only shut down the Pi. To restart it you need to physically press the button on the x729. And it leaves the x729 running til it runs out of battery if power is removed.

If you enable the OpenPlotter Power Off function then the x729 properly shuts down when you use the desktop or cli shutdown. But, this breaks the x729 service that monitors for power loss and properly shuts down the Pi.

For the most part this works for me. I only shut down the Pi by removing power to the x729. I would really just like to know how the Safe Shutdown works and why it won't work for me.

FYI, here is the part of my install script to handle all the x729 functions.
Code:
# x729
git clone https://github.com/geekworm-com/x729-script ~/x729-script
chmod +x ~/x729-script/*.sh

# x729 Clock
echo -e "\n# UPS Read RTC Time\ndtoverlay=i2c-rtc,ds1307" | sudo tee -a /boot/firmware/config.txt
sudo apt remove fake-hwclock -y
sudo update-rc.d -f fake-hwclock remove
sudo systemctl disable fake-hwclock
sudo sed -i 's/^\([^#].*\)/# \1/g' /lib/udev/hwclock-set
sudo sed -i '/dev=$1/s/^#//g' /lib/udev/hwclock-set

# x729 Fan
echo -e "\n# UPS Fan\ndtoverlay=pwm-2chan,pin2=13,func2=4" | sudo tee -a /boot/firmware/config.txt
sudo cp -f ~/x729-script/x729-fan.sh /usr/local/bin/
sudo cp -f ~/x729-script/x729-fan.service /lib/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now x729-fan

# x729 Power
# sed -i '/sudo poweroff/i \        sleep 5' ~/x729-script/xPWR.sh
sudo cp -f ~/x729-script/xPWR.sh /usr/local/bin/
sudo cp -f ~/x729-script/x729-pwr.service /lib/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now x729-pwr

# x729 Power Loss
sudo usermod -aG gpio pi
cp -f ~/x729-script/sample/plsd-gpiod.py ~/x729-script/powerloss.py
sed -i 's/chipname = "gpiochip0"/chipname = "gpiochip4"/' ~/x729-script/powerloss.py
sudo chmod +x ~/x729-script/powerloss.py
sudo cp -f ~/x729-script/powerloss.py /usr/local/bin/
###################
bash -c 'cat << "EOF" > ~/x729-script/powerloss.service
[Unit]
Description=Power Loss Service
After=multi-user.target

[Service]
ExecStart=/usr/bin/python3 /usr/local/bin/powerloss.py
Restart=always
User=pi
Group=pi
StandardOutput=journal
StandardError=journal

[Install]
WantedBy=multi-user.target
EOF'
###################
sudo cp -f ~/x729-script/powerloss.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now powerloss
Reply
#2
Reopening an old thread... for some reason, I had a lot of issues getting the X729 scripts to work with the latest Linux Debian version (Trixie). Some parts of the their code, such as disable fake-hwclock didn't work. I'm not convinced they are keeping up wth linux updates. Once I tweaked a bit of code, it is very good and reliable. I modified mine to shutdown on:
- main power loss (12vdc breaker)
- batteries <= 3.9V (instead of default 3.3V)
- x729off command
- shutdown command

I'm not at the boat, so don't have access to the exact method I used, but it's something like this (note: I'm on an Rpi5 running Debian Trixie 13):



As for the shutdown command, it has to be intercepted and use x729off instead. They have a note in their docs "DON'T run the 'shutdown' linux command to shut down, otherwise the power of x729 shield will not be shut down."

To intercept the OS shutdown command, you need to create a systemd service with a custom shutdown script. ChatGPT will do this fairly reliably, so long as you give it good prompts (details about your hardware, OS version, what script you want to call, etc...)

Something like...

#!/bin/bash
# Your custom commands here (e.g., logging, cleanup)
echo "System is shutting down at $(date)" >> /var/log/custom_shutdown.log
# Ensure any necessary services are available (e.g. networking)
# If the script takes a long time, add 'TimeoutStopSec=infinity' to the service file.

make it executable chmod -x

Create a systemd service file in /etc/systemd/system/ (e.g., custom-shutdown.service).

[Unit]
Description=My custom shutdown script
DefaultDependencies=no
# Run before the main shutdown sequence
Before=shutdown.target reboot.target halt.target
# Optional: ensure network is up if needed
# Requires=network-online.target
# After=network-online.target

[Service]
Type=oneshot
ExecStart=/bin/true
# This is the command that runs during shutdown
ExecStop=/path/to/your/custom_script.sh
RemainAfterExit=yes
# Optional: prevent systemd from killing the script if it takes longer than the default timeout
# TimeoutStopSec=infinity

[Install]
# This service is needed when reaching multi-user.target, which ensures it's "active" during normal operation and thus "stopped" at shutdown
WantedBy=multi-user.target


reload, enable and start the service

sudo systemctl daemon-reload
sudo systemctl enable custom-shutdown.service
sudo systemctl start custom-shutdown.service



The other way would be to create a new shutdown script:

#!/bin/bash
# Your custom logic here
echo "Intercepted shutdown command!" >> /var/log/custom_shutdown.log

# Pass all arguments to the original command
exec /sbin/shutdown-original "$@"


Getting the shutdown sequence correct is important to avoid getting the "low voltage detected" msg on restart.
Reply
#3
Hi,
I wrote a python script that I run as a service to manage the Geekworm x120x type of UPS. Perhaps it can be adopted to the x729.
https://github.com/ArjenR/x120x_upsd

Rgrds, Arjen
Reply
#4
Could you provide details on the creation process? I'd like to learn from you, thank you.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)