Skip to content

Commit

Permalink
Do not exit after pairing is finished
Browse files Browse the repository at this point in the history
Android performs additional service
discovery during pairing, otherwise
pairing fails.
  • Loading branch information
benquike committed Nov 12, 2023
1 parent 46d6242 commit cbe09e2
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions apps/pair.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ async def pair(
mitm,
bond,
ctkd,
linger,
io,
prompt,
request,
Expand Down Expand Up @@ -353,17 +354,20 @@ async def pair(
if address_or_name is not None:
print(color(f'=== Connecting to {address_or_name}...', 'green'))
connection = await device.connect(address_or_name)
pairing_failure = False

if not request:
try:
if mode == 'le':
await connection.pair()
else:
await connection.authenticate()
return
except ProtocolError as error:
pairing_failure = True
print(color(f'Pairing failed: {error}', 'red'))
return

if not linger or pairing_failure:
return
else:
if mode == 'le':
# Advertise so that peers can find us and connect
Expand Down Expand Up @@ -413,6 +417,7 @@ def emit(self, record):
help='Enable CTKD',
show_default=True,
)
@click.option('--linger', default=True, is_flag=True, help='Linger after pairing')
@click.option(
'--io',
type=click.Choice(
Expand Down Expand Up @@ -440,6 +445,7 @@ def main(
mitm,
bond,
ctkd,
linger,
io,
prompt,
request,
Expand All @@ -463,6 +469,7 @@ def main(
mitm,
bond,
ctkd,
linger,
io,
prompt,
request,
Expand Down

0 comments on commit cbe09e2

Please sign in to comment.