Runtime.getBatteryLevel

We want a simple method to get battery level if it exists on a system regardless if its Linux, Windows, or Mac OSX.

Turns out this is pretty messy as part of it relies on the OS vendor and part is really low-level hardware implementation details.  But I thought I got all 3 major operating systems covered.

I tested Windows 7  64 bit & Linux Ubuntu 14.04 64 bit - was all worky, but Gael had different results :(

What do you get ?


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kwatters's picture

win 10 64 bit no worky.

I tried here on win 10 , 64 bit.. but no worky   "None" was returned  (null)  

Not much debbuging info..  This was with a fresh install into a new folder with the latest.

Also of interested, the exception/stack trace showed up in the myrobotlab.log, but did NOT show up in the log service or in the java log in the python window..  not sure why the stack trace was supressed there... 

.................................................................................

[python] [INFO] exec(String) 
print Runtime.getBatteryLevel()
[python.interpreter.4] [INFO] execToString threw
.................................................................................
 
i suspect the issue is that it's not being found on the PATH ... 
 
The program is installed an available in the command prompt here:
 
C:\Windows\System32\wbem\WMIC.exe
 
but it seems like runtime is trying to find it in the current working directory for MRL.. and so it's fetting a file not found sort of exception looking in the current directory "." 
GroG's picture

Thanks Kwatters, I can see

Thanks Kwatters,

I can see "C:\WINDOWS\System32\Wbem;" is one of the entries in your PATH variable ... I would have expected Apache-common-exec 'by default' to execute in the same inherited environment for which mrl is running ....

We (Gael, You, and I) are :

  • using the same version of MR
  • have the same version of Windows
  • have this executable on our system
  • are running mrl from a jar
  • are using the same script

Sooooo...  by process of elimination IT MUST BE A JAVA 8 THING ! ... cuz I'm running Java 1.7 :)

Now I'm dumping the environment and did a slight code change :

from :
exec.execute(commandline);

to:
exec.execute(commandline, EnvironmentUtils.getProcEnvironment());

As per suggestions from here :
http://stackoverflow.com/questions/2693020/commons-exec-executing-a-prog...

Hopefully it worky !

 

hairygael's picture

Gee, I wouldn't have expected

Gee, I wouldn't have expected this to be so difficult to set up. I fact, I initially tried to set it up myself...

I'm so glad you are on it, otherwise I would be out of charge long before it would finally work.

:)

Mats's picture

Raspberry PI 2 with latest Jessie OS

It responds

None

I think that's OK since it doesn't have a battery

 

GroG's picture

Aye .. None for no battery is

Aye .. None for no battery is expected...

Alessandruino's picture

Worky on Mac in the

Worky on Mac in the debugger.... Got to see which version of Java i have...

Alessandruino's picture

UPDATE : i have java 1.7

UPDATE : i have java 1.7

GroG's picture

Worky on Mac !  A miracle !

Worky on Mac !  A miracle ! :D

Thanks :)

GroG's picture

Aight found the issue in

Aight found the issue in Windows Java 8 fixed