diff --git a/aa_wireless_dongle/package/aawg/src/bluetoothHandler.cpp b/aa_wireless_dongle/package/aawg/src/bluetoothHandler.cpp index ffc270f..31f143b 100644 --- a/aa_wireless_dongle/package/aawg/src/bluetoothHandler.cpp +++ b/aa_wireless_dongle/package/aawg/src/bluetoothHandler.cpp @@ -152,8 +152,15 @@ void BluetoothHandler::connectDevice() { std::shared_ptr bluezDevice = m_connection->create_object_proxy(BLUEZ_BUS_NAME, device_path); DBus::MethodProxy connectProfile = *(bluezDevice->create_method(INTERFACE_BLUEZ_DEVICE, "ConnectProfile")); + DBus::MethodProxy disconnect = *(bluezDevice->create_method(INTERFACE_BLUEZ_DEVICE, "Disconnect")); + + std::shared_ptr> deviceConnected = bluezDevice->create_property(INTERFACE_BLUEZ_DEVICE, "Connected"); try { + if (deviceConnected) { + Logger::instance()->info("Bluetooth device already connected, disconnecting\n"); + disconnect(); + } connectProfile(HSP_AG_UUID); Logger::instance()->info("Bluetooth connected to the device\n"); return;