rattqv99
Posts: 1
Joined: Thu May 11, 2017 12:40 pm

Battery level of nearby Bluetooth devices ..

Thu May 11, 2017 12:41 pm

Hi,

I've found various scripts for scanning for Bluetooth devices, and made a fairly comprehensive logger.

I binned it off because the scanning interfered with playback over airplay in my project.

I'd know like to know how you could retrieve the devices battery levels and, eventually output to HTML. A standard scan will retrieve the device's address. Once the known device addresses (my phone, work phone, Mrs' phone) are gathered, I'd like the battery status of these devices.

I found a similar Reddit thread, but no answers. Any ideas?

Thanks,,,

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: Battery level of nearby Bluetooth devices ..

Thu May 11, 2017 3:51 pm

Disclaimer: before your question, I had no idea if you could do this so I've been having fun on Google...

Based on this answer on stackoverflow, it seems that you can get the battery level if the device implements the Bluetooth Battery Service.

So, I then searched for using Bluez to get Battery Service info which led me to this answer which says that you need to be able to read Bluetooth characteristics. It seems that there's a bluez command line tool called gattool which could help (if that works you could call the command from python).

However, I wanted to see if there was a python implementation and I found this which may be of interest.

Hopefully there's enough info here to let you have a go at trying to do this.

Alternatively, someone else will post and tell me that everything I've just said is complete rubbish!
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

User avatar
davef21370
Posts: 897
Joined: Fri Sep 21, 2012 4:13 pm
Location: Earth But Not Grounded

Re: Battery level of nearby Bluetooth devices ..

Thu May 11, 2017 3:55 pm

Apple say... Monkey do !!

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: Battery level of nearby Bluetooth devices ..

Thu May 11, 2017 4:02 pm

Well, I wasn't wrong, but that looks simpler!
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

User avatar
davef21370
Posts: 897
Joined: Fri Sep 21, 2012 4:13 pm
Location: Earth But Not Grounded

Re: Battery level of nearby Bluetooth devices ..

Thu May 11, 2017 4:08 pm

elParaguayo wrote:Disclaimer: before your question, I had no idea if you could do this so I've been having fun on Google...
I had the same fun on Google and read something about not being able to access this on Android phones because of some security issue. Hmmmm...?

Dave.
Apple say... Monkey do !!

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: Battery level of nearby Bluetooth devices ..

Thu May 11, 2017 5:20 pm

Yes. That was one of the answers on the first link I posted I think.

I guess the message for the OP is to give it a go and report back with their results.
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

TheMiddle36
Posts: 21
Joined: Sun Apr 23, 2017 2:25 pm

Re: Battery level of nearby Bluetooth devices ..

Wed Aug 30, 2017 11:20 am

Hi,

Really interesting thread!
I’ve been looking for a way to ping BLE devices in the house and return the alias and battery level, with a view to outputting the information on my PHP Notification Center page... This will show which devices are nearby and whose will need charging.

I must say I’ve gotten in a right mess with Bluetooth and gone round in circles a few times. I now have Bluez4.11 but am still unable to access the battery service characteristic!

The links above are very helpful in writing a python script, but I think there’s is a problem in getting the core functionality to work, I’m trying out in Terminal before Python as its one less thing for me to get wrong!

HCItool seems to be deprecated, but I have some luck with GATTCTL...
has anyone made any progress here, specifically with iOS?

Cheers,
Nick

Return to “Python”