maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Applications (https://talk.maemo.org/forumdisplay.php?f=41)
-   -   [Announce] bnf - nifty little tool, allowing to have battery info at glance (https://talk.maemo.org/showthread.php?t=84452)

Wikiwide 2014-11-29 10:34

Re: [Announce] bnf - nifty little tool, allowing to have battery info at glance
 
Quote:

Originally Posted by speedonwilliam (Post 1449780)
I really dont understand why it doesnt work for me. I'v searched the forum and its like i'm d only one having this problem. When i type 'bnf' in xterm, I get the message
.Error: Read failed
usr/sbin/bnf-i2c: line 45: syntax error: * 3570 / 20 / 1000
sudo bnf does nothing.

Try:
$ sudo gainroot
# bnf

You need to have rootsh package installed :-)
http://wiki.maemo.org/Root

Best wishes.
~~~~~~~~~~~~~~~~~
Per aspera ad astra...

speedonwilliam 2014-11-30 13:23

Re: [Announce] bnf - nifty little tool, allowing to have battery info at glance
 
Quote:

Originally Posted by Wikiwide (Post 1449785)
Try:
$ sudo gainroot
# bnf

same error. I dont knw wot d problem is. Could it be a hardware problem?

Wikiwide 2014-11-30 23:11

Re: [Announce] bnf - nifty little tool, allowing to have battery info at glance
 
Quote:

Originally Posted by speedonwilliam (Post 1449916)
same error. I don't know what the problem is. Could it be a hardware problem?

No, it looks like a misprint in the /usr/sbin/bnf-i2c file.
Like 45 for me:
NAC=$( $NAC * 3570 / $RS / 1000 ) # NAC Nominal available capacity, mAh.
No idea what's wrong with your file.

Best wishes.

Mentalist Traceur 2014-12-01 06:26

Re: [Announce] bnf - nifty little tool, allowing to have battery info at glance
 
Ugh, initially I wrote: "Not bothering to look inside the script itself, but some comments which may help the next person to look zero in on the problem"... but then nooo... I just had to go digging.

Anyway, I looked at this and it looked wrong, so I figured it was a someone-wrote-out-what-they-thought-they-saw-instead-of-copy-pasting style of error. And sure enough, this is wrong, that is not what line 45 looks like:
Code:

NAC=$( $NAC * 3570 / $RS / 1000 )
^ Unless $NAC at that moment is defined as the name of a valid command, that's going to be a command-not-found error anyway...

Looking at the line as quoted, I would imagine you meant arithmetic expansion rather than command substition? If so, it would look like this:
Code:

NAC=$(($NAC * 3570 / $RS / 1000))
^ I went ahead and looked into the source code, and indeed, that's what it looks like. (Note the double '((' and '))' symbols.)

As a sidenote, this assumes $NAC and $RS will never have whitespace inside them (or be blank). I habitually double-quote any usage of $VAR_NAME unless I expressly know it's guaranteed to be unnecessary. So it would look like so:
Code:

NAC=$(("$NAC" * 3570 / "$RS" / 1000))
..though it's not a big deal because either way you'd get a syntax error if there's whitespace in either of those variables.

However, while we're at it, the dollar signs (and thus doublequotes) are actually redundant. Since this is an arithmetic expansion we're working with, we can just write:
Code:

NAC=$((NAC * 3570 / RS / 1000))
..because Bourne/POSIX shell syntax expects all non-number tokens inside the arithmetic expansion to be variable names anyway. (I suspect that this would be a miniscule bit more efficient, because this way the shell does not have to stop to expand the $VAR_NAMEs into text first, before proceeding with parsing the result of that expansion as part of the arithmetic expansion, and instead can do just the arithmetic expansion - one expansion instead of two, where the two expansions probably forces it to shuffle/rewrite some buffer contents.)

Anyway, back to the syntax error:
Quote:

usr/sbin/bnf-i2c: line 45: syntax error: * 3570 / 20 / 1000
This is happening because "$NAC" is an empty string (or just completely unset, which for this purpose is the same thing).

Here is an example test command replicating that kind of syntax error:
Code:

$ A= B=1; echo $(($A * $B))
sh: syntax error:  * 1

NOTE, this error is produced by the stock busybox ash shell.

The busybox-power ash shell will instead print:
Code:

-sh: arithmetic syntax error
Which is both surprising, and amusing (because I'd expect busybox-power to have the more informative error message, and I find the lack of error-causing-string to be less informative...).

Anyway, point is, we see that $NAC is defined on line 16 (of the same file, obviously) with the command:
Code:

i2cget -y 2 0x55 0x0c w
..since bnf-i2c is ran as root (because bnf itself is ran as root), you'd need to run the above command as root, and see what it returns.

So, speedonwilliam, try running the following and let us know what the result is:

Code:

sudo i2cget -y 2 0x55 0x0c w

Mentalist Traceur 2014-12-01 07:11

Re: [Announce] bnf - nifty little tool, allowing to have battery info at glance
 
Quote:

Originally Posted by Mentalist Traceur (Post 1450034)
[...]
However, while we're at it, the dollar signs (and thus doublequotes) are actually redundant. Since this is an arithmetic expansion we're working with, we can just write:
Code:

NAC=$((NAC * 3570 / RS / 1000))
[...]

Note, however, that if you do this change, the shell will swallow the syntax error of having a blank/unset value in any of the variables, instead of erroring out. To be honest though, I would be checking the return values of i2cget and returning out as soon as one returned an error value. Manpages online for i2cget seem to oh-so-helpfully not report what the return value will be in the event of a failure, but I imagine that, given Unix convention and the Linux kernel documentation on i2c that i2cget on the commandline returns 0 for success, something non-zero on failure, and I would hope i2cget takes care of printing its own errors to stderr....

So anyway, I would daisy-chain the VAR_NAME=$(i2cget [...]) commands with '&&', and stick them in a negated if check, so that you can abort out, like so:
Code:

if ! \ #
 VAR1=`i2cget [...]` &&
 VAR2=`i2cget [...]` &&
 [...]
 VARn=`i2cget [...]`
then
 #error out because one of the i2cget calls failed, for example:
 printf "i2cget failed to load one of the necessary values.\n" >&2
fi

And if i2cget fails to print useful errors to stderr, then you could wrap each i2cget call in a error-reporting wrapper e.g. something like:
Code:

i2cget_wrapperWithError()
{
 if i2cget "$@"
 then
  return $?
 else
  RET=$?
  printf "error: i2cget %s\n" "$*"
  return $RET
 fi
}

..then call that instead of i2cget directly. But I really think (and hope) i2cget prints errors properly.

Estel 2014-12-01 07:41

Re: [Announce] bnf - nifty little tool, allowing to have battery info at glance
 
@speedonwilliam
Sorry, I've, somehow, missed update on this thread. Anyway, thanks for trying to solve/solving Wikiwide and Mentalist - indeed, do as Mentalist said, and we will be able to proceed after getting a meaningful output. If the "sudo i2cget" thing doesn't produce output, try issuing it without sudo, but from root shell.

@Mentalist Traceur
Thanks for your insights on the "code", all dully noted, I'll experiment with upgrading the script when I'll have some free time. BTW, that happens, when someone with actual knowledge inspects totally "noobishly" written code :p Well, at least I seem to *do* understand the mechanics behind your suggestions, and that is something, already...

/Estel

Mentalist Traceur 2014-12-01 13:57

Re: [Announce] bnf - nifty little tool, allowing to have battery info at glance
 
Quote:

Originally Posted by Estel (Post 1450042)
@Mentalist Traceur
Thanks for your insights on the "code", all dully noted, I'll experiment with upgrading the script when I'll have some free time. BTW, that happens, when someone with actual knowledge inspects totally "noobishly" written code :p Well, at least I seem to *do* understand the mechanics behind your suggestions, and that is something, already...

Happy to help. I spent an unhealthy amount of time figuring out Bourne/POSIX shell scripting details in the last half year. (I tend towards depth-first perfectionism when I do anything, so with increasing competence in shell scripting, came more and more digging into shell scripting nuance.)

"But will this one-off shell script break if a user has a newline in their input?" are the kinds of questions which keep me up at night.

Mentalist Traceur 2014-12-01 19:34

Re: [Announce] bnf - nifty little tool, allowing to have battery info at glance
 
Woops, I made an error, right here:
Quote:

Originally Posted by Mentalist Traceur (Post 1450034)
As a sidenote, this assumes $NAC and $RS will never have whitespace inside them (or be blank). I habitually double-quote any usage of $VAR_NAME unless I expressly know it's guaranteed to be unnecessary. So it would look like so:
Code:

NAC=$(("$NAC" * 3570 / "$RS" / 1000))
..though it's not a big deal because either way you'd get a syntax error if there's whitespace in either of those variables.

The above will also be a syntax error. Apparently, arithmetic expansion is one of those places where field splitting is not done when expanding variables to start with... So if you do have the double quotes there, the double quotes are treated as literals instead of as escapes around the variable contents.

Consequently, I am less confident about my assertion that $(($SOME_VAR + 1)) would be any less efficient than $((SOME_VAR + 1)). I guess I don't remember the parsing rules with regard to arithmetic expansion as well as I thought I did.

speedonwilliam 2014-12-03 20:42

Re: [Announce] bnf - nifty little tool, allowing to have battery info at glance
 
Thank you all for your help. I really appreciate it but d truth is i'm a noob :-D so I really dont understand what you guys are saying. Anyway thanks once again.

Quote:

Originally Posted by Estel (Post 1450042)
@speedonwilliam
If the "sudo i2cget" thing doesn't produce output, try issuing it without sudo, but from root shell.

Tried the command below as root:
sudo i2cget -y 2 0x55 0x0c w
nothing happens. Also follöwed your instruction and tried it without sudo but from the root shell n i get thesame message:
Error: Read failed

Estel 2014-12-04 07:25

Re: [Announce] bnf - nifty little tool, allowing to have battery info at glance
 
OK, so for some reasons, your chip doesn't report nominal available capacity, at all... Now I just need to refresh my memory about what it means ;D

supergaban 2014-12-14 16:21

Re: [Announce] bnf - nifty little tool, allowing to have battery info at glance
 
1 Attachment(s)
hi, estel
since a week a go, BNF on my device simply doesn't work, when i click it from desktop.

and if i try from terminal it shown bellow :
http://talk.maemo.org/attachment.php...1&d=1418573924

i had try to reinstal using "apt-get install --reinstall bnf" but it doesn't fix it.
any clue..?
Thank In Advance.

handaxe 2014-12-15 18:11

Re: [Announce] bnf - nifty little tool, allowing to have battery info at glance
 
Quote:

Originally Posted by supergaban (Post 1452181)
hi, estel
since a week a go, BNF on my device simply doesn't work, when i click it from desktop.
.

Taking a flying guess, I believe your battery needs calibration. It can become "uncalibrated" and I remember bnf ceasing to give info when that happened to me.

Estel 2014-12-18 02:32

Re: [Announce] bnf - nifty little tool, allowing to have battery info at glance
 
To be precise, it's not BNF ceasing t work per se, but bq27x00_battery kernel module (courtesy of Pali) ceasing to give proper info for one important parameter, making calculations fail. Mentalist suggested work around to at least determine if that happen and then throw some useful error.

If you're unsure, you can just "modprobe -r bq27x00_battery" as root, and try again with BNF. Without bq27x00_battery, BNF fall-back to raw i2c read (aka does, in user-space, exactly the same reading from chip that bq27x00_battery module does in kernel side), which doesn't fail.

There are exactly 0 reasons why bq27x00_battery stops giving full info when battery is not calibrated - its job is to report values from chip to sysnodes, not "censor" them, basing on module's own judgment if info is still useful. Hoever, Pali decided otherwise and can be quite stubborn on some things - I tried to convince him few times, to no avail, so I just ceased doing so.

For people interested in technical details - when battery is uncalibrated, value reported as max capacity resets to default 2048. Thus, if you see 2048 mAh (or something around it), you can be quite sure that you just need to re-calibrate. Hoever, Pali decided that giving default value is wrong, and sysnode entry giving that info just gets read error, if battery is uncalibrated (instead of, obediently, report what chip says, no matter if it's wrong or good). I don't see how error'ing read is better than giving default data, but we're stuck with it, unless someone forks that module (or kernel-power, making, for example, kernel-powernn_bq27x00_battery-fixed, for every release).

/Estel

supergaban 2014-12-18 04:31

Re: [Announce] bnf - nifty little tool, allowing to have battery info at glance
 
Quote:

Originally Posted by Estel (Post 1452628)
To be precise, it's not BNF ceasing t work per se, but bq27x00_battery kernel module (courtesy of Pali) ceasing to give proper info for one important parameter, making calculations fail. Mentalist suggested work around to at least determine if that happen and then throw some useful error.

If you're unsure, you can just "modprobe -r bq27x00_battery" as root, and try again with BNF. Without bq27x00_battery, BNF fall-back to raw i2c read (aka does, in user-space, exactly the same reading from chip that bq27x00_battery module does in kernel side), which doesn't fail.

There are exactly 0 reasons why bq27x00_battery stops giving full info when battery is not calibrated - its job is to report values from chip to sysnodes, not "censor" them, basing on module's own judgment if info is still useful. Hoever, Pali decided otherwise and can be quite stubborn on some things - I tried to convince him few times, to no avail, so I just ceased doing so.

For people interested in technical details - when battery is uncalibrated, value reported as max capacity resets to default 2048. Thus, if you see 2048 mAh (or something around it), you can be quite sure that you just need to re-calibrate. Hoever, Pali decided that giving default value is wrong, and sysnode entry giving that info just gets read error, if battery is uncalibrated (instead of, obediently, report what chip says, no matter if it's wrong or good). I don't see how error'ing read is better than giving default data, but we're stuck with it, unless someone forks that module (or kernel-power, making, for example, kernel-powernn_bq27x00_battery-fixed, for every release).

/Estel

Thank you Estelle, i'm not sure if i understand all your explanation. since english is not my native language, and google translator seem give me terrible translating :D. ...But i had been try "modprobe -r bq27x00 battery" and it bring bnf work again. then i can draw conclusion the problem was from power kernel side.

I've use compatible battery for 2 and half or less months. at first calibrating it show 1596 mAH and now it show only 1557 mAH. is it normal.? i mean it is callibration matter or my battery capacity quickly decrease..?

handaxe 2014-12-18 10:19

Re: [Announce] bnf - nifty little tool, allowing to have battery info at glance
 
Quote:

Originally Posted by supergaban (Post 1452634)
at first calibrating it show 1596 mAH and now it show only 1557 mAH. is it normal.? i mean it is callibration matter or my battery capacity quickly decrease..?

Quite normal and the exactly values determined can vary slightly and battery capacity does decline. For now, I would not worry.

Was it a polarcell made battery, as around 1550 mAH is good capacity?

supergaban 2014-12-18 10:57

Re: [Announce] bnf - nifty little tool, allowing to have battery info at glance
 
Quote:

Originally Posted by handaxe (Post 1452658)
Quite normal and the exactly values determined can vary slightly and battery capacity does decline. For now, I would not worry.

Was it a polarcell made battery, as around 1550 mAH is good capacity?

oh, ok if it normal :)
i'm not using polarcell but "flashpower", i'm sure this is not international brand, because it hard to find any information related to this battery on the website. the company must be import unbranded battery from chinese, than they print their own brand on it. spesification was great "double power, double IC, 2800mAH :D, but real capacity is only 1596 mAH.

handaxe 2014-12-18 11:47

Re: [Announce] bnf - nifty little tool, allowing to have battery info at glance
 
Quote:

Originally Posted by supergaban (Post 1452662)
....spesification was great "double power, double IC, 2800mAH :D, but real capacity is only 1596 mAH.

Such "lies" are common but usually the capacity comes in REALLY low 1100, or some such. If calibrated correctly, your battery has the max that can be packed into a battery of that size.

supergaban 2014-12-18 11:56

Re: [Announce] bnf - nifty little tool, allowing to have battery info at glance
 
Quote:

Originally Posted by handaxe (Post 1452665)
Such "lies" are common but usually the capacity comes in REALLY low 1100, or some such. If calibrated correctly, your battery has the max that can be packed into a battery of that size.

Agree, i have one, with same spesification double power..blah..blah, :) with only show 1150mAH. branded "gold.." battery., then i never use it again

sebar 2015-12-16 14:05

Re: [Announce] bnf - nifty little tool, allowing to have battery info at glance
 
Hey guys. I'd love to use BNF to have its output written in a battery log. Is there a way to display the output values in the terminal or an output file?

Edit:
Just realized that the bq27200.sh that's included in the battery calibration tutorial could be used for this purpose. It produces a lot of information. It can be run periodically and its output written to a log.

skojevac 2016-08-26 09:32

Re: [Announce] bnf - nifty little tool, allowing to have battery info at glance
 
Hi everyone, need a little help here with battery calibration, i just upgraded to v53 kernel and lost info on the battery.
So I tried step-by-step calibration guide but I ran into a problem.
I copied bq27200.sh to usr/bin and chmod +x it, than copied i2cget to ./ but all I got was "need i2cget", tried "which i2cget" but got no response. So I red trough bunch of posts and tried copying i2cget to the same folder with bq27200 and also chmod +x it and when I run the script i now get
"Reading valuesError: could not set address to 0+55: device or resource bussy"
I also installed bnf, but I got a blur when running from desktop (meaning I need sudo rights for desktop), bu also when I run it from terminal I get "No data available" meaning battery needs calibration, but no matter what I do I fail. What is it that I do wrong? tnx

skojevac 2016-08-26 11:32

Re: [Announce] bnf - nifty little tool, allowing to have battery info at glance
 
Found the answer.
This did the trick

https://talk.maemo.org/showpost.php?...&postcount=257

dovf 2016-09-05 20:32

Re: [Announce] bnf - nifty little tool, allowing to have battery info at glance
 
Hi!

I recently got a new battery, and it's behaving very nicely, but battery eye and the status-area battery icon don't show its information correctly. I've been doing the calibration procedure for the past few weeks, probably gone through at least 6-8 cycles (of which at least 3-4 were definitely successful -- I actually saw EDV1 switch to 1), bnf consistently shows a charge of ~1570 mAh, and I'm getting 2-3 days worth of my normal use (which is pretty light) from each charge -- but battery eye just won't show a full charge of more than 1300 mAh, and for the first part of each discharge it doesn't show any information on the graph at all; and the status-area indicator doesn't match either bnf or battery eye, but is somewhere in between.

As far as I can tell, I'm using stock BME -- I switched to kp53 about a month before getting the new battery (and didn't notice anything wrong until I switched batteries), but never explicitly installed BME replacement, and 'lsmod | grep batte' shows only 'rx51_battery' (which I assume is stock BME?).

Are the discrepancies I'm seeing between bnf and battery eye to be expected? Is this supposed to be solved by switching to BME replacement?

Thanks!


All times are GMT. The time now is 07:29.

vBulletin® Version 3.8.8