def _ble_init_connect()

in src/ble/ble_uart_peripheral.py [0:0]


    def _ble_init_connect(self):
        '''
        Initilise the BLE connection to the Peripheral device
        Note: Will disconect and kill any existing connections / Peripheral device objects.
        '''

        try:
            # Create the BLE Peripheral device and configure 
            log.info('Connecting to BLE Device: {}'.format(self.ble_mac))
            
            # Clear any previously initilised ble_peripheral (and updates connection state).
            self._disconect_ble()

            # re/initialise the ble_peripheral and connect to the device
            self._ble_peripheral = btle.Peripheral(self.ble_mac)
            self._ble_peripheral.setMTU(5000)

            log.info('Getting _uart_service for BLE device: {}'.format(self.ble_mac))
            self._uart_service = self._ble_peripheral.getServiceByUUID(_UART_SERVICE_UUID)
            log.info('_uart_service: {}'.format(self._uart_service))

            # get the _uart_rx characteristic, should only ever get one in list against UUID
            log.info('Getting _uart_service Rx Characteristic for BLE device: {}'.format(self.ble_mac))
            self._uart_rx = self._uart_service.getCharacteristics(forUUID=_UART_RX_CHAR_UUID)[0]
            log.info('_uart_service Rx Characteristic: {}'.format(self._uart_rx))

            # get the _uart_tx characteristic, should only ever get one in list against UUID
            log.info('Getting _uart_service Tx Characteristic for BLE device: {}'.format(self.ble_mac))
            self._uart_tx  = self._uart_service.getCharacteristics(forUUID=_UART_TX_CHAR_UUID)[0]
            log.info('_uart_service Tx Characteristic: {}'.format(self._uart_tx))

            # Once the BLE Peripheral is initialised then add the RX Delegate. 
            self._ble_peripheral.withDelegate(BleUartDelegate(self.ble_mac, self.ble_proxy_topic, self.receive_message_router))
        
        except Exception as err:
            #  Log the failed BLE connection to this peripheral
            log.info('EXCEPTION Connection state error for BLE device: {} - ERROR-MESSAGE: {}'.format(self.ble_mac, err))

        finally:
            # Update the connection state variable and return
            self._set_ble_connection_state()
            log.info('Connection state for BLE device: {} - {}'.format(self.ble_mac, self._conn_state))