Skip to content

Commit

Permalink
Merge pull request #36 from TheWeirdDev/rfcomm_experiment
Browse files Browse the repository at this point in the history
Experimental RFCOMM port finder
  • Loading branch information
TheWeirdDev authored Aug 5, 2020
2 parents 13af47a + 87cdfb3 commit 3e1a0b0
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions bluetooth_battery.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,28 @@ def getATCommand(sock, line, device):

return True

def find_rfcomm_port(device):
uuid="0000111e-0000-1000-8000-00805f9b34fb"
proto = bluetooth.find_service(address=device, uuid=uuid)
if len(proto) == 0:
print("Couldn't find the RFCOMM port number")
return 4
else:
for j in range(len(proto)):
if 'protocol' in proto[j] and proto[j]['protocol'] == 'RFCOMM':
port = proto[j]['port']
return port

def main():
if (len(sys.argv) < 2):
print("Usage: bl_battery.py <BT_MAC_ADDRESS_1>[.PORT] ...")
print(" Port number is optional (default = 4)")
print(" Port number is optional")
exit()
else:
for device in sys.argv[1:]:
i = device.find('.')
if i == -1:
port = 4
port = find_rfcomm_port(device)
else:
port = int(device[i+1:])
device = device[:i]
Expand Down

0 comments on commit 3e1a0b0

Please sign in to comment.