in src/ble/ble_uart_controller.py [0:0]
def connect_ble_device(self, ble_mac):
'''
Creates a connection to the given BLE MAC address and initialises the BleUartPeripheral
instance that holds the connection and BLE notification receive loop.
Note: Is recommended to scan and verify a BLE device exists and is reachable before
calling this method as takes ~40 secs for the connect to fail and return a response.
'''
######################################################
# Create a BleUartPeripheral object for the requested BLE device and connect
log.info('Connecting the BLE Device: {}'.format(ble_mac))
# Normalise ble-mac to all upper case.
ble_mac = ble_mac.upper()
######################################################
# Get existing or create a new BLE Peripheral object for this BLE Mac
ble_device = None
if ble_mac in self.ble_devices:
ble_device = self.ble_devices[ble_mac]
else:
# Create the BleUartPeripheral class for this device and save to local variable
ble_device = BleUartPeripheral(ble_mac, self.receive_message_router, self.ble_state_change_callback)
self.ble_devices[ble_mac] = ble_device
if not ble_device.is_alive():
log.info('Starting Tx/Rx thread for BLE Device: {}'.format(ble_mac))
ble_device.start()