Skip to content

Commit

Permalink
Merge pull request #4 from mtttz/multiple_devices
Browse files Browse the repository at this point in the history
add reset_on_start parameter to connect function and pass it through to pygatt
  • Loading branch information
Aritzherrero4 authored Apr 10, 2021
2 parents 6f7904d + 964dde1 commit 3cbda6b
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions trionesControl/trionesControl.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,23 @@
MAIN_CHARACTERISTIC_UUID = "0000ffd9-0000-1000-8000-00805f9b34fb"

log = logging.getLogger(__name__)
def connect(MAC):

def connect(MAC, reset_on_start=True):
"""
Create and start a new backend adapter and connect it to a device.
When connecting to multiple devices at the same time make sure to set reset_on_start
to False after the first connection is made, otherwise all connections made before are
invalidated.
:param string MAC: MAC address of the device to connect to.
:param bool reset_on_start: Perhaps due to a bug in gatttol or pygatt,
but if the bluez backend isn't restarted, it can sometimes lock up
the computer when trying to make a connection to HCI device.
"""
try:
adapter = pygatt.GATTToolBackend()
adapter.start()
adapter.start(reset_on_start=reset_on_start)
device = adapter.connect(MAC)
except pygatt.exceptions.NotConnectedError:
raise pygatt.exceptions.NotConnectedError("Device nor connected!")
Expand Down

0 comments on commit 3cbda6b

Please sign in to comment.