mirror of
https://github.com/DanielPollithy/bluetooth_drone.git
synced 2025-10-16 11:45:38 +00:00
32 lines
728 B
Python
32 lines
728 B
Python
# this is the address of the hikey
|
|
HIKEY_BT_ADDRESS = '98:7B:F3:19:FE:57'
|
|
# raspy
|
|
RASPY_BT_ADDRESS = 'B8:27:EB:76:09:0B'
|
|
PEER_BT_ADDRESS = RASPY_BT_ADDRESS
|
|
BT_SLEEP = 0.01 # seconds
|
|
|
|
from subprocess import Popen, PIPE
|
|
import re
|
|
|
|
|
|
def get_own_bt_address():
|
|
p = Popen(['hcitool', 'dev'], stdin=PIPE, stdout=PIPE, stderr=PIPE)
|
|
output, err = p.communicate()
|
|
returncode = p.returncode
|
|
regex = r"([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})"
|
|
test_str = output
|
|
matches = re.finditer(regex, test_str)
|
|
|
|
numMatches = 0
|
|
bt_addresses = []
|
|
|
|
for match in matches:
|
|
numMatches+=1
|
|
bt_addr = '{match}'.format(match=match.group())
|
|
bt_addresses.append(bt_addr)
|
|
|
|
return bt_addresses[0]
|
|
|
|
|
|
|