Results 1 to 4 of 4

Thread: How to get temperature/battery data in C/Shell

  1. #1
    Join Date
    Feb 2012
    Beans
    1

    Angry How to get temperature/battery data in C/Shell

    Hello,

    I'm interested in making a small C/Shell command line utility to display information about computer temperature and battery life.

    I am pulling my hair out trying to find example code or information on how to do this online. Can anyone point me in the right direction?

    Thanks!

  2. #2
    Join Date
    Aug 2011
    Location
    47°9′S 126°43W
    Beans
    2,172
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: How to get temperature/battery data in C/Shell

    The info you need is likely somewhere under /proc. On my computer:

    Code:
    >>>cat /proc/acpi/battery/BAT0/state 
    present:                 yes
    capacity state:          ok
    charging state:          charged
    present rate:            0 mA
    remaining capacity:      6549 mAh
    present voltage:         12376 mV
    
    >>>cat /proc/acpi/thermal_zone/THM0/temperature 
    temperature:             46 C
    among other things. The full ACPI spec is here but it doesn't tell how this maps to /proc/acpi even if most of it can be guessed. You will also find moderately outdated info in the original sourceforge project.
    Last edited by ofnuts; February 24th, 2012 at 10:36 AM.

  3. #3
    Join Date
    Feb 2011
    Location
    Great White North
    Beans
    128
    Distro
    Kubuntu 11.10 Oneiric Ocelot

    Re: How to get temperature/battery data in C/Shell

    You may find this thread interesting. It has a bash script which displays the battery. I believe some modification is needed, but that is the best thing I could find.

    linky
    VHDL and C FTW

    Designing a custom CPU based on MIPS

  4. #4
    Join Date
    Sep 2011
    Location
    UK
    Beans
    76
    Distro
    Ubuntu 11.10 Oneiric Ocelot

    Re: How to get temperature/battery data in C/Shell

    Quote Originally Posted by idedTea View Post
    Hello,

    I'm interested in making a small C/Shell command line utility to display information about computer temperature and battery life.

    I am pulling my hair out trying to find example code or information on how to do this online. Can anyone point me in the right direction?

    Thanks!
    Hi,

    I've written a small C++ app that gets the battery state and displays it in a window. You may find the code interesting and it should be fairly easy to understand. You can get it from:

    https://github.com/doobrie/battery-status/

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •