Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Register
    • Login

    Laptop Battery Level Widget

    Scheduled Pinned Locked Moved 2.1 Snapshot Feedback and Problems - RETIRED
    11 Posts 4 Posters 4.8k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D
      daplumber
      last edited by

      Since I have a habit of regarding an old laptop as a compact server with a built-in UPS I'm running 2.1 on a surplus  elderly Toshiba Tecra M3.

      (BTW Do Not use the Yukon GbE port, disable it in the BIOS, it has a nasty habit of hanging *BSD and Linux.)

      So I thought it would be nice to see the battery level % (from sysctl) on the pfsense status page, so some quick and dirty cut-and-paste produced battery.widget.php:

      
      require_once("guiconfig.inc");
      require_once("pfsense-utils.inc");
      require_once("functions.inc");
      ?>
      
      		$dev_state = exec("sysctl hw.acpi.battery.life | awk '{print $2}'"); ## get battery life from sysctl
      		$dev_ident =  "Internal";
      
      		echo '' . "\n";
      
      		echo '' . "\n";
      
      ?>
      
      		  |		  |	
      | 
      
      <center>' . "\n";
      		echo $dev_ident ;
      		echo '</center>
      
       | 
      
      <center>';
      
      		if($dev_state == "100") 
      		 echo "$dev_state
      ";
      		else
      		echo "$dev_state
      "; 
      		echo '</center>
      
       |	
      
      <center>[Battery Charge](battery.php)</center>
      
      

      Comments, criticism, and above all better coding(!) welcomed!

      I have no idea how portable (pun!) this is, but hw.acpi.battery.life seems to be pretty generic.

      Picture attached. (Yes, same system as pfsense-ng-blue blue theme.)

      Bonus [ER] (!) :
      Sooner or later I'm going to try and plug a surplus (needs a new battery) APC UPS that I know works with apcupsd over USB into pfSense 2.1. Implementing the apcupsd FreeBSD port along with the neccessary php control and even a widget would be a nice-to-have…
      ![Screen Shot 2012-05-25 at May 25 02.59.59 .jpg_thumb](/public/imported_attachments/1/Screen Shot 2012-05-25 at May 25 02.59.59 .jpg_thumb)
      ![Screen Shot 2012-05-25 at May 25 02.59.59 .jpg](/public/imported_attachments/1/Screen Shot 2012-05-25 at May 25 02.59.59 .jpg)

      –--------
      This user has been carbon dated to the 8-bit era...

      1 Reply Last reply Reply Quote 0
      • rcfaR
        rcfa
        last edited by

        Did you check out the NUT package?

        Seems like that would also be a candidate to consider laptop batteries as "local UPS"…

        1 Reply Last reply Reply Quote 0
        • ?
          Guest
          last edited by

          mmh- i recently worked in a similar area querying acpi wt sysctl.
          Ive seen that things like this were implemented a bit different.
          All the html is placed right directly in the widget, so everythings fine.
          But i dont see hows your widget is going to update the batterys state over time.

          If the NUT package is not an option, then you  may want to refactor your codes core functionality in functions.inc.php and return the data to the battery widget. If you are interested, then youll find some examples in system_information.widget.php.

          Oh and i see a missing gettext($dev_ident)  ;)
          But if you liked the experience of creating code and want to do the refactoring the i can help you
          wt updating your widgets data with ajax.js/getstatus.php and to display a pretty battery bar :)

          so - its up to you :)

          1 Reply Last reply Reply Quote 0
          • D
            daplumber
            last edited by

            @rcfa:

            Did you check out the NUT package?

            Seems like that would also be a candidate to consider laptop batteries as "local UPS"…

            I had a quick look at nut, but I didn't see anywhere it addressed non-networked UPS'. Unless I missed it?

            –--------
            This user has been carbon dated to the 8-bit era...

            1 Reply Last reply Reply Quote 0
            • D
              daplumber
              last edited by

              @ThorstenK:

              mmh- i recently worked in a similar area querying acpi wt sysctl.
              Ive seen that things like this were implemented a bit different.
              All the html is placed right directly in the widget, so everythings fine.
              But i dont see hows your widget is going to update the batterys state over time.

              If the NUT package is not an option, then you  may want to refactor your codes core functionality in functions.inc.php and return the data to the battery widget. If you are interested, then youll find some examples in system_information.widget.php.

              Oh and i see a missing gettext($dev_ident)  ;)
              But if you liked the experience of creating code and want to do the refactoring the i can help you
              wt updating your widgets data with ajax.js/getstatus.php and to display a pretty battery bar :)

              so - its up to you :)

              Er, no. :-) I'm dangerous when it comes to code. By all means show me how it should be done and made pretty!  8)

              I'm more of a lover than a fighter and more of a tester than a coder!  :D  ;D

              –--------
              This user has been carbon dated to the 8-bit era...

              1 Reply Last reply Reply Quote 0
              • rcfaR
                rcfa
                last edited by

                @daplumber:

                @rcfa:

                Did you check out the NUT package?

                Seems like that would also be a candidate to consider laptop batteries as "local UPS"…

                I had a quick look at nut, but I didn't see anywhere it addressed non-networked UPS'. Unless I missed it?

                I haven't used NUT yet myself, just installed it to have a look, because I'm considering getting some UPS for my network equipment, that said, however, if you go to the Services:NUT:NUT Settings tab, the first line in "General Settings" has a pop-up selector "UPS Monitoring" and among the choices is "Local UPS", and further down on the page are settings for local UPS devices, including USB devices, etc.

                I guess that would have to be extended to include "built-in" UPSs, i.e. laptop batteries and such, but that would likely have to be done at the NUT level, rather than in pfSense to be done properly, everything else would be a hack.

                http://www.networkupstools.org/docs/developer-guide.chunked/ar01s04.html

                If a hack were to be made, likely the way to do it would be to fake an SNMP UPS and then use a remote SNMP UPS, but that would be pretty ugly.

                1 Reply Last reply Reply Quote 0
                • stephenw10S
                  stephenw10 Netgate Administrator
                  last edited by

                  @daplumber:

                  BTW Do Not use the Yukon GbE port, disable it in the BIOS, it has a nasty habit of hanging *BSD and Linux

                  Quite a lot of work has gone into the msk(4) driver between FreeBSD 8.1 ans 8.3 including code to handle some watchdog errors. You may want to re-try it.
                  What chip is used in your laptop NIC?

                  Steve

                  1 Reply Last reply Reply Quote 0
                  • D
                    daplumber
                    last edited by

                    @stephenw10:

                    @daplumber:

                    BTW Do Not use the Yukon GbE port, disable it in the BIOS, it has a nasty habit of hanging *BSD and Linux

                    Quite a lot of work has gone into the msk(4) driver between FreeBSD 8.1 ans 8.3 including code to handle some watchdog errors. You may want to re-try it.
                    What chip is used in your laptop NIC?

                    Steve

                    It is (I quote): "Marvell Yukon 88E8053 PCI-E Gigabit Ethernet Controller"

                    Given that everything Open Source had to be reverse engineered (Thank you Marvell, Not!) I'm not convinced. Most of the hangs I've seen on various laptops of the era were IRQ handling related. But I'll give it a try and see.

                    –--------
                    This user has been carbon dated to the 8-bit era...

                    1 Reply Last reply Reply Quote 0
                    • D
                      daplumber
                      last edited by

                      @daplumber:

                      @stephenw10:

                      @daplumber:

                      BTW Do Not use the Yukon GbE port, disable it in the BIOS, it has a nasty habit of hanging *BSD and Linux

                      Quite a lot of work has gone into the msk(4) driver between FreeBSD 8.1 ans 8.3 including code to handle some watchdog errors. You may want to re-try it.
                      What chip is used in your laptop NIC?

                      Steve

                      It is (I quote): "Marvell Yukon 88E8053 PCI-E Gigabit Ethernet Controller"

                      Given that everything Open Source had to be reverse engineered (Thank you Marvell, Not!) I'm not convinced. Most of the hangs I've seen on various laptops of the era were IRQ handling related. But I'll give it a try and see.

                      Nope. Re-enabling the Yukon in the BIOS still hangs pfsense/FreeBSD 8.3 an indeterminate number of minutes after bringing the msk driver up.

                      Fortunately this laptop has an ExpressCard slot, so I've ordered a cheap Realtek 8111 based GbE card.

                      –--------
                      This user has been carbon dated to the 8-bit era...

                      1 Reply Last reply Reply Quote 0
                      • stephenw10S
                        stephenw10 Netgate Administrator
                        last edited by

                        Well that's disapointing.  :(
                        I updated the 'firmware' on that same chip which seemed to remove some trouble I was having. See:
                        http://forum.pfsense.org/index.php/topic,20095.msg207289.html#msg207289
                        Another user wrote up how to do it better than me!:
                        http://forum.pfsense.org/index.php/topic,20095.msg250430/topicseen.html#msg250430

                        What 'rev' do you have?

                        Steve

                        1 Reply Last reply Reply Quote 0
                        • D
                          daplumber
                          last edited by

                          So "sysctl hw.acpi.battery.life" has been returning "-1" for quite a few version of Beta0 now. Sorry to say I didn't notice when exactly. Any ideas on what broke?

                          –--------
                          This user has been carbon dated to the 8-bit era...

                          1 Reply Last reply Reply Quote 0
                          • First post
                            Last post
                          Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.