sixfab / sixfab-power-python-api

Python API for Sixfab Power Management and UPS HAT v2
http://power.sixfab.com
9 stars 10 forks source link

System not honouring power.get_safe_shutdown_status() configuration #12

Closed snrkl closed 3 years ago

snrkl commented 4 years ago

Issue: A system that (I believe) is configured to automatically shut down based on a particular battery level being hit is not actually shutting down.

What I expected to happen: The system would automatically shut down when the battery level reached the value set in power.get_safe_shutdown_battery_level()

What actually happened: The system went on operating as usual

Config: Firmware

v0.3.3

Raspberry Pi

Raspi Zero W

Python Version:

3.7.3

OS:

Raspbian GNU/Linux 10 (buster)

Kernel

Linux nitrogen.lab.snrkl.org 5.4.51+ #1327 Thu Jul 23 10:53:06 BST 2020 armv6l GNU/Linux

Power_agent service: Disabled snrkl@nitrogen 0 /var/log $ service power_agent status ● power_agent.service - Sixfab PMS Agent Loaded: loaded (/etc/systemd/system/power_agent.service; enabled; vendor preset: enabled) Active: inactive (dead) since Sat 2020-09-05 16:47:39 AEST; 5h 7min ago Process: 438 ExecStart=/usr/bin/python3 -u agent.py (code=killed, signal=TERM) Main PID: 438 (code=killed, signal=TERM)

Sep 05 16:47:24 nitrogen.lab.snrkl.org sudo[2199]: pam_unix(sudo:session): session opened for user root by (uid=0) Sep 05 16:47:24 nitrogen.lab.snrkl.org sudo[2199]: pam_unix(sudo:session): session closed for user root Sep 05 16:47:26 nitrogen.lab.snrkl.org python3[438]: Sending PUBLISH (d0, q0, r0, m148), 'b'/device/...censored_uuid.../feed'',... (132 bytes Sep 05 16:47:36 nitrogen.lab.snrkl.org sudo[2253]: powermgmt : TTY=unknown ; PWD=/opt/sixfab/pms/agent ; USER=root ;COMMAND=/bin/cat /opt/six Sep 05 16:47:36 nitrogen.lab.snrkl.org sudo[2253]: pam_unix(sudo:session): session opened for user root by (uid=0) Sep 05 16:47:37 nitrogen.lab.snrkl.org sudo[2253]: pam_unix(sudo:session): session closed for user root Sep 05 16:47:39 nitrogen.lab.snrkl.org systemd[1]: Stopping Sixfab PMS Agent... Sep 05 16:47:39 nitrogen.lab.snrkl.org systemd[1]: power_agent.service: Main process exited, code=killed, status=15/TERM Sep 05 16:47:39 nitrogen.lab.snrkl.org systemd[1]: power_agent.service: Succeeded. Sep 05 16:47:39 nitrogen.lab.snrkl.org systemd[1]: Stopped Sixfab PMS Agent.

Steps to reproduce: Python Library Installed: $ pip3 install --upgrade --force-reinstall sixfab-power-python-api

snrkl@nitrogen 0 ~ $ python3 Python 3.7.3 (default, Dec 20 2019, 18:57:59) [GCC 8.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> from power_api import SixfabPower, Definition >>> power = SixfabPower() >>> power.get_battery_max_charge_level() 100 >>> power.get_safe_shutdown_battery_level() 70 >>> power.get_safe_shutdown_status() 1 >>> power.get_battery_level() 90 >>> power.get_input_voltage() 0.0

<... Time Elapses ...>

>>> power.get_battery_level() 57 >>> power.get_input_voltage() 0.0 >>> power.get_battery_current() -0.207

selengalp commented 4 years ago

Hi, Safe shutdown feature just works in the situation of the adapter power absence in order to avoid unnecessary shutdowns. Your issue might be caused by the adapter is plugged.

snrkl commented 4 years ago

Hi @selengalp: I can assure you the system has no input power... (it was sitting on my desk, not connected to ANYTHING..) 😁

As you can see from the original python output above, input voltage is 0.0 and battery current is negative (ie: the sytem is discharging the battery)...

As it stands at the moment, I believe the system is not behaving the way it is expected to..

Attached are some screenshots from the grafana system that I use for capturing telemetry... You can see the barrier at 70% that shows where the system is configured to shut down - as you can see, it didn't...

2020-09-06_15-26-52 198

You can also see the inputs/outputs from a power perspective at the 21:08hrs in the line chart, that shows: Input: 0V, 0A System: 5.18V, 0.11A Battery: 3.87V, -0.23A 2020-09-06_15-27-13 972

Any suggestions on how to troubleshoot this further?

selengalp commented 4 years ago

I guess that I understood the reason for the issue in your case. UPS HAT assumes end-device (raspberry pi etc.) is off if the system current is lower than 0.25A. So, when the end-device is off, there isn't necessary to run safe shutdown mechanism. In your case system current 0.11 A. Can I ask what your hardware setup is to understand the situation in more detail?

snrkl commented 4 years ago

That makes sense. System setup is a Raspberry Pi Zero W, that has been optimised to reduce energy consumption (disable HDMI interface, disable onboard LEDs), remove un-necessary software to maximise its runtime on battery. (this is a totally off grid 10W PV system that has sun during the day, and I am working on getting it through the night with a single 18650)

The lowest active (ie: powered on) system current I have seen during testing is 0.0530A 2020-09-06_23-30-55 517

snrkl commented 4 years ago

@selengalp: what is the suggested path forward? Is the low current threshold something that can be modified?

snrkl commented 4 years ago

Any suggestions here? I am essentially blocked till I can find a solution to this problem...

selengalp commented 4 years ago

We have added the feature of the current threshold to decide the end device is on or off to the next version that will be released soon. Thanks for the feedback. I will let you know the new version has been released.

snrkl commented 4 years ago

Awesome.. just in time to work on my project over the holidays! Thanks..

snrkl commented 3 years ago

Hey @selengalp: any indication on timeframes for the update you mentioned 3 weeks ago?

dcarpy commented 3 years ago

Hi @snrkl. It looks to me like a change has been committed a few days ago--you should be good. https://github.com/sixfab/sixfab-power-python-api/commit/9d1c89a1a139a1b7d064612ea4256735faadd2ff

selengalp commented 3 years ago

Hi @snrkl. The API was updated and new methods were added. But, test of firmware is going on. You will need the last firmware version in order to use new API methods. We will complete the the test of firmware and it will be released in this week. @ensarkarabudak will let you know you when the new version of firmware is released. Sorry for the delay.

ensarkarabudak commented 3 years ago

Hi @snrkl,

If you want to test this feature now, the steps are:

Please go on your test. :confetti_ball:

Thanks.

ensarkarabudak commented 3 years ago

By the way, the new version has been released. You can also update it via power software platform. @snrkl