Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email?
pfSense Forum
pfSense English Support
»
2.1 Snapshot Feedback and Problems
»
Laptop Battery Level Widget
Username:
Password:
1 Hour
1 Day
1 Week
1 Month
Forever
Home
Help
Search
Login
Register
Pages: [
1
]
Go Down
« previous
next »
Print
Author
Topic: Laptop Battery Level Widget (Read 1251 times)
0 Members and 1 Guest are viewing this topic.
daplumber
Jr. Member
Offline
Posts: 45
Laptop Battery Level Widget
«
on:
May 25, 2012, 02:53:13 am »
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:
Code:
<?php
require_once(
"guiconfig.inc"
);
require_once(
"pfsense-utils.inc"
);
require_once(
"functions.inc"
);
?>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="widgetsubheader"><b><center>
<?php
echo
gettext
(
"Battery"
)
?>
</center></b></td>
<td class="widgetsubheader"><b><center>
<?php
echo
gettext
(
"% Charge"
)
?>
</center></b></td>
</tr>
<?php
$dev_state
=
exec
(
"sysctl hw.acpi.battery.life | awk '{print $2}'"
);
## get battery life from sysctl
$dev_ident
=
"Internal"
;
echo
'<tr><td class="listr"><center>'
.
"\n"
;
echo
$dev_ident
;
echo
'</td>'
.
"\n"
;
echo
'<td class="listr"><center>'
;
if(
$dev_state
==
"100"
)
echo
"<span style=\"background-color:#00FF00\">
$dev_state
</span><br>"
;
else
echo
"<span style=\"background-color:#FF8080\">
$dev_state
</span><br>"
;
echo
'</td></tr>'
.
"\n"
;
?>
</table>
<center><a href="battery.php" class="navlink">Battery Charge</a></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...
«
Last Edit: May 25, 2012, 02:56:11 am by daplumber
»
Logged
----------
This user has been carbon dated to the 8-bit era...
rcfa
Sr. Member
Offline
Posts: 495
Re: Laptop Battery Level Widget
«
Reply #1 on:
May 25, 2012, 06:39:04 am »
Did you check out the NUT package?
Seems like that would also be a candidate to consider laptop batteries as "local UPS"...
Logged
ThorstenK
Guest
Re: Laptop Battery Level Widget
«
Reply #2 on:
May 25, 2012, 06:51:33 am »
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
«
Last Edit: May 25, 2012, 06:53:14 am by ThorstenK
»
Logged
daplumber
Jr. Member
Offline
Posts: 45
Re: Laptop Battery Level Widget
«
Reply #3 on:
May 25, 2012, 08:45:16 am »
Quote from: rcfa on May 25, 2012, 06:39:04 am
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?
Logged
----------
This user has been carbon dated to the 8-bit era...
daplumber
Jr. Member
Offline
Posts: 45
Re: Laptop Battery Level Widget
«
Reply #4 on:
May 25, 2012, 08:49:23 am »
Quote from: ThorstenK on May 25, 2012, 06:51:33 am
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!
I'm more of a lover than a fighter and more of a tester than a coder!
Logged
----------
This user has been carbon dated to the 8-bit era...
rcfa
Sr. Member
Offline
Posts: 495
Re: Laptop Battery Level Widget
«
Reply #5 on:
May 25, 2012, 01:54:56 pm »
Quote from: daplumber on May 25, 2012, 08:45:16 am
Quote from: rcfa on May 25, 2012, 06:39:04 am
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.
Logged
stephenw10
Hero Member
Online
Posts: 5081
Re: Laptop Battery Level Widget
«
Reply #6 on:
May 25, 2012, 05:24:32 pm »
Quote from: daplumber on May 25, 2012, 02:53:13 am
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
Logged
daplumber
Jr. Member
Offline
Posts: 45
Re: Laptop Battery Level Widget
«
Reply #7 on:
May 26, 2012, 09:34:47 pm »
Quote from: stephenw10 on May 25, 2012, 05:24:32 pm
Quote from: daplumber on May 25, 2012, 02:53:13 am
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.
Logged
----------
This user has been carbon dated to the 8-bit era...
daplumber
Jr. Member
Offline
Posts: 45
Re: Laptop Battery Level Widget
«
Reply #8 on:
May 26, 2012, 11:04:23 pm »
Quote from: daplumber on May 26, 2012, 09:34:47 pm
Quote from: stephenw10 on May 25, 2012, 05:24:32 pm
Quote from: daplumber on May 25, 2012, 02:53:13 am
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.
Logged
----------
This user has been carbon dated to the 8-bit era...
stephenw10
Hero Member
Online
Posts: 5081
Re: Laptop Battery Level Widget
«
Reply #9 on:
May 27, 2012, 01:21:42 am »
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
Logged
daplumber
Jr. Member
Offline
Posts: 45
Re: Laptop Battery Level Widget
«
Reply #10 on:
September 27, 2012, 01:28:07 pm »
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?
Logged
----------
This user has been carbon dated to the 8-bit era...
Pages: [
1
]
Go Up
Print
« previous
next »
Jump to:
Please select a destination:
-----------------------------
Administrative
-----------------------------
=> Forum rules
=> Messages from the pfSense Team
=> Feedback
-----------------------------
pfSense English Support
-----------------------------
=> Installation and Upgrades
=> General Questions
=> 2.1 Snapshot Feedback and Problems
=> Post a bounty
===> Completed Bounties
===> Expired/Withdrawn Bounties
=> Hardware
=> Firewalling
=> NAT
=> CARP/VIPs
=> Routing and Multi WAN
=> Traffic Shaping
=> DHCP and DNS
=> IPv6
=> IPsec
=> PPTP
=> PPPoE Server
=> Captive Portal
=> webGUI
=> Wireless
=> SNMP
=> Packages
=> Virtualization installations and techniques
=> OpenVPN
=> Gaming
-----------------------------
Development/Documentation
-----------------------------
=> Documentation
=> Development
-----------------------------
General Category
-----------------------------
=> General Discussion
-----------------------------
International Support
-----------------------------
=> Indonesian
=> Deutsch
=> Español
=> Français
=> Italiano
=> Russian
=> Nederlands
=> Norwegian
=> Portuguese
=> Polish
=> Romanian
=> Swedish
=> Turkish
-----------------------------
Retired
-----------------------------
=> 1.2.3-PRERELEASE-TESTING snapshots - RETIRED
=> 1.2.1-RC Snapshot Feedback and Problems-RETIRED
=> 2.0-RC Snapshot Feedback and Problems - RETIRED
=> DNS Server testing area - RETIRED
Loading...