Skip to content

Commit

Permalink
refs and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
agnesk92 committed Dec 31, 2020
1 parent 79fa73d commit a294fd4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 28 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Samsung's RFCOMM protocol interpretation for battery info was used from https://github.com/ThePBone/GalaxyBuds-BatteryLevel.
35 changes: 7 additions & 28 deletions app/battery.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,10 @@
config_logger()
logger = logging.getLogger(__name__)

UUID = "00001101-0000-1000-8000-00805F9B34FB"

def get_battery_levels(bltooth_address):
uuid = "00001101-0000-1000-8000-00805F9B34FB"
service_matches = bluetooth.find_service(uuid=uuid, address=bltooth_address)

host = service_matches[0]["host"]
port = service_matches[0]["port"]

sock = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
sock.connect((host, port))

data = sock.recv(1024)
def parse_battery_info(data):
batterylife = None
while data[3] not in [96, 97] and len(data) != 0:
logger.info(f"Data battery elem: {data[3]}")
Expand All @@ -36,27 +28,14 @@ def get_battery_levels(bltooth_address):
return batterylife


if __name__ == "__main__":
"34:82:C5:31:5D:B1"
bltooth_address = "34:82:C5:31:5D:B1"
device_name = bluetooth.lookup_name(bltooth_address)

uuid = "00001101-0000-1000-8000-00805F9B34FB"
service_matches = bluetooth.find_service(uuid=uuid, address=bltooth_address)
def get_battery_levels(bltooth_address):
service_matches = bluetooth.find_service(uuid=UUID, address=bltooth_address)
host = service_matches[0]["host"]
port = service_matches[0]["port"]

sock = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
sock.connect((host, port))

data = sock.recv(1024)
batterylife = None
while data[3] not in [96, 97] and len(data) != 0:
logger.info(f"Data battery elem: {data[3]}")

data = sock.recv(1024)
if data[3] == 97:
batterylife = "{},{},{}".format(data[6], data[7], data[11])
if data[3] == 96:
batterylife = "{},{},{}".format(data[5], data[6], data[10])

logger.info(f"Batterylife: {str(batterylife)}")
batterylife = parse_battery_info(data)
return batterylife

0 comments on commit a294fd4

Please sign in to comment.