xbattbar a battery monitor alternative

Forum Forums General Tips and Tricks xbattbar a battery monitor alternative

This topic contains 6 replies, has 4 voices, and was last updated by BobC Feb 13-12:49 pm.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #3253
    Member
    mroot
    mroot

    Do you have an old battery that has lost its capacity or an energy intensive cpu that makes monitoring the battery critical? Or even worse do you have both like me? Do you get busy and hide conky behind a window and then realize that your battery is approaching 0% charge? Well, xbattbar may work as battery monitor for you. Xbattbar is an older battery monitor that works on systems that use either acpi or the much older apm for power management. Xbattbar places a line on the length of your screen’s border that changes color as your battery is discharging or charging. The line can be located on the top, bottom, left, or right of the screen depending on the preference of the user. If you move your cursor over the line it shows the exact percentage of charge remaining and whether the battery is charging or discharging.

    I attached pictures of xbattbar in the charging and discharging state below as it looks with fluxbox on my system. Xbattbar being located on the bottom edge of the screen.

    The code used for this is below and is placed in control center —- > session —- > User Desktop-Session for automatic startup.

    xbattbar -t 4 -p 1 -I gray -i black -O purple -o red -c &

    My xbattbar is located on the bottom of the screen since I don’t want to cover my panel which is located on the top of the screen. The bottom position happens to be the default for xbattbar. Most of you have your panel on the bottom and may prefer to have xbattbar on the top of the screen which is easily provided by the following:

    xbattbar -t 4 -p 1 -I gray -i black -O purple -o red -c top &

    Thickness of the bar is controlled by the number following -t in my case the thickness is 4 pixels. The update interval is controlled by the number following -p in my case the update interval is 1 second. Colors are also user selectable. In general, I find xbattbar be unobtrusive and yet highly visible.

    Once you have installed xbattbar on your system additional information can be found by typing:

    man xbattbar or xbattbar –help in a terminal

    -mroot

    • This topic was modified 2 months, 3 weeks ago by mroot.
    #3299
    Member
    skidoo
    skidoo

    Great writeup, thanks for the tip!

    #3329
    Member
    mroot
    mroot

    Thank you. There was some info on xbattbar on the old forum and I thought an update would be useful to someone especially since xbattbar isn’t well known.

    -mroot

    #3339
    Member
    cyrilus31
    cyrilus31

    Just tested. Great app. Thank you.

    #6503
    Member

    BobC

    I found this was the only small footprint app that estimates reasonably the amount of life left in the battery and time left to fully charge, but when I tried to redirect it to a file, the file was empty.

    I looked and found it on the debian package site for stretch, and found a git link to the source. I installed git and I found the source code and figured out that the reason is that printf is being used, but was not being flushed to the disk with an fflush(stdout); afterwards. So I fixed the code. I also added the info from the display box along with time/date as well as seconds since epoch to the logfile and made a way to easily use tail and sed to process it so I could feed it to my conky.

    I had to install enough things to then compile and test it, but I am still missing some because xmkmf -a doesn’t work and make install doesn’t work…

    build-essential
    apt-file
    libx11-dev

    Then I compiled and tested, and it now works right. I found out who the debian packager is and sent him the code (I also attached it here) with a nice email in hopes he’ll add my changes since I don’t know anything about packaging. I suppose I could also post the object here in a zipfile if anyone wants it so they don’t need to recompile it.

    In my startup I start it, redirecting output to the log file
    xbattbar -c -t 4 -I green -O brown -i red -o black > ~/xbattbar.log &

    Output:
    Battery at Tue Feb 13 02:23:31 2018 1518510211 seconds AC on-line: Charging 67% Needs 0 hr. 49 min. 30 sec.
    Battery at Tue Feb 13 02:28:50 2018 1518510530 seconds AC on-line: Charging 68% Needs 2 hr. 45 min. 20 sec.
    Battery at Tue Feb 13 02:29:32 2018 1518510572 seconds AC off-line: Depleting 67% Left 0 hr. 41 min. 20 sec.
    Battery at Tue Feb 13 02:30:23 2018 1518510623 seconds AC off-line: Depleting 66% Left 0 hr. 50 min. 50 sec.
    Battery at Tue Feb 13 02:31:14 2018 1518510674 seconds AC off-line: Depleting 65% Left 0 hr. 50 min. 0 sec.
    Battery at Tue Feb 13 02:32:26 2018 1518510746 seconds AC off-line: Depleting 64% Left 1 hr. 8 min. 50 sec.

    And it writes the log out to the drive, and I get the last line of it to output on my conky screen

    tail -n 1 ~/xbattbar.log | sed -e ‘s/^.*\(line\:.*min\.\).*$/\1/’ -e ‘s/line\: //’

    Output:
    Depleting 64% Left 1 hr. 8 min.

    Also, what is the purpose of the -s scriptfile option? I haven’t found an example where I understand what they are doing with it…

    • This reply was modified 6 days, 14 hours ago by BobC.
    Attachments:
    1. xbattbar.c
    #6535
    Member
    skidoo
    skidoo

    purpose of the -s scriptfile option?

    Yeah, the manpage is unclear:

    https://sources.debian.org/src/xbattbar/1.4.8-1/xbattbar.man/

    xbattbar [-a] [blahblahblah] [-s script-name]
    You can use your external script for check battery status. It must print two lines to STDOUT ‘battery=value’ and ‘ac_line=on|off

    xbattbar.c reads values from an external datasource
    apm | acpi | sys | myscript
    The default datasource is apm; via options, we can instruct it to use an alternative datasource: -c (acpi), -r (sys aka sysfs), or -s (myscript)

    #6537
    Member

    BobC

    Yes, I see it now, the script option is to feed it data from something else, not to get anything from it.

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.