From 871e2c0ce8f144d997a5e75f4dc56b4ea131b6df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Tue, 9 Dec 2025 15:06:49 +0100 Subject: [PATCH] Fix bluetooth wifi setup for bluez backends --- libnymea-app/wifisetup/bluetoothdiscovery.cpp | 5 ++++- libnymea-app/wifisetup/btwifisetup.cpp | 13 +++++++++-- .../android/platformpermissionsandroid.cpp | 10 +++++++-- nymea-app/ui/connection/ConnectionWizard.qml | 22 ++++++++++--------- 4 files changed, 35 insertions(+), 15 deletions(-) diff --git a/libnymea-app/wifisetup/bluetoothdiscovery.cpp b/libnymea-app/wifisetup/bluetoothdiscovery.cpp index eb185ebe..f1c20f55 100644 --- a/libnymea-app/wifisetup/bluetoothdiscovery.cpp +++ b/libnymea-app/wifisetup/bluetoothdiscovery.cpp @@ -166,10 +166,13 @@ void BluetoothDiscovery::onBluetoothHostModeChanged(const QBluetoothLocalDevice: connect(m_discoveryAgent, &QBluetoothDeviceDiscoveryAgent::deviceDiscovered, this, &BluetoothDiscovery::deviceDiscovered); #if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)) connect(m_discoveryAgent, &QBluetoothDeviceDiscoveryAgent::deviceUpdated, this, &BluetoothDiscovery::deviceDiscovered); +#elif (QT_VERSION >= QT_VERSION_CHECK(6, 2, 0)) + connect(m_discoveryAgent, &QBluetoothDeviceDiscoveryAgent::errorOccurred, this, &BluetoothDiscovery::onError); +#else + connect(m_discoveryAgent, SIGNAL(error(QBluetoothDeviceDiscoveryAgent::Error)), this, SLOT(onError(QBluetoothDeviceDiscoveryAgent::Error))); #endif connect(m_discoveryAgent, &QBluetoothDeviceDiscoveryAgent::finished, this, &BluetoothDiscovery::discoveryFinished); connect(m_discoveryAgent, &QBluetoothDeviceDiscoveryAgent::canceled, this, &BluetoothDiscovery::discoveryCancelled); - connect(m_discoveryAgent, SIGNAL(error(QBluetoothDeviceDiscoveryAgent::Error)), this, SLOT(onError(QBluetoothDeviceDiscoveryAgent::Error))); } if (m_discoveryEnabled && !m_discoveryAgent->isActive()) { start(); diff --git a/libnymea-app/wifisetup/btwifisetup.cpp b/libnymea-app/wifisetup/btwifisetup.cpp index ad153b65..e1f3d101 100644 --- a/libnymea-app/wifisetup/btwifisetup.cpp +++ b/libnymea-app/wifisetup/btwifisetup.cpp @@ -54,6 +54,10 @@ BtWiFiSetup::BtWiFiSetup(QObject *parent) : QObject(parent) { m_accessPoints = new WirelessAccessPoints(this); qRegisterMetaType("const BluetoothDeviceInfo*"); + + connect(this, &BtWiFiSetup::bluetoothStatusChanged, this, [this](){ + qCDebug(dcBtWiFiSetup()) << "Bluetooth status changed" << m_bluetoothStatus; + }); } BtWiFiSetup::~BtWiFiSetup() @@ -81,13 +85,18 @@ void BtWiFiSetup::connectToDevice(const BluetoothDeviceInfo *device) } m_btController = QLowEnergyController::createCentral(device->bluetoothDeviceInfo(), this); - connect(m_btController, &QLowEnergyController::connected, this, [this](){ - qCInfo(dcBtWiFiSetup()) << "Bluetooth connected"; + connect(m_btController, &QLowEnergyController::connected, this, [this, device](){ + qCInfo(dcBtWiFiSetup()) << "Bluetooth connected" << device->address() << device->name(); m_btController->discoverServices(); m_bluetoothStatus = BluetoothStatusConnectedToBluetooth; emit bluetoothStatusChanged(m_bluetoothStatus); }, Qt::QueuedConnection); + + connect(m_btController, &QLowEnergyController::stateChanged, this, [](QLowEnergyController::ControllerState state){ + qCInfo(dcBtWiFiSetup()) << "Bluetooth constroller state changed" << state; + }); + connect(m_btController, &QLowEnergyController::disconnected, this, [this](){ qCInfo(dcBtWiFiSetup()) << "Bluetooth disconnected"; m_bluetoothStatus = BluetoothStatusDisconnected; diff --git a/nymea-app/platformintegration/android/platformpermissionsandroid.cpp b/nymea-app/platformintegration/android/platformpermissionsandroid.cpp index d8f1e5dd..45fd8871 100644 --- a/nymea-app/platformintegration/android/platformpermissionsandroid.cpp +++ b/nymea-app/platformintegration/android/platformpermissionsandroid.cpp @@ -65,6 +65,8 @@ PlatformPermissions::PermissionStatus PlatformPermissionsAndroid::checkPermissio switch (platformPermission) { case PlatformPermissions::PermissionBluetooth: { QBluetoothPermission permission; + // Only request scan/connect access; advertising isn't needed and isn't declared in the manifest. + permission.setCommunicationModes(QBluetoothPermission::Access); const auto permissionStatus = qApp->checkPermission(permission); @@ -194,7 +196,10 @@ void PlatformPermissionsAndroid::requestPermission(PlatformPermissions::Permissi switch (platformPermission) { case PlatformPermissions::PermissionBluetooth: qCDebug(dcPlatformPermissions()) << "Requesting bluetooth permission"; - qApp->requestPermission(QBluetoothPermission{}, [platformPermission](const QPermission &permission) { + { + QBluetoothPermission permission; + permission.setCommunicationModes(QBluetoothPermission::Access); + qApp->requestPermission(permission, [platformPermission](const QPermission &permission) { if (permission.status() == Qt::PermissionStatus::Denied) { qCWarning(dcPlatformPermissions()) << "Bluetooth permission denied."; s_instance->m_requestedButDeniedPermissions.append(platformPermission); @@ -204,7 +209,8 @@ void PlatformPermissionsAndroid::requestPermission(PlatformPermissions::Permissi qCDebug(dcPlatformPermissions()) << "Bluetooth permission granted."; emit s_instance->bluetoothPermissionChanged(); - }); + }); + } break; case PlatformPermissions::PermissionLocation: { QLocationPermission locationPermission; diff --git a/nymea-app/ui/connection/ConnectionWizard.qml b/nymea-app/ui/connection/ConnectionWizard.qml index c309fcc4..c8e48337 100644 --- a/nymea-app/ui/connection/ConnectionWizard.qml +++ b/nymea-app/ui/connection/ConnectionWizard.qml @@ -297,7 +297,7 @@ WizardPageBase { callback: function() { var nymeaHost = hostsProxy.get(index); var connectionInfoDialog = Qt.createComponent("/ui/components/ConnectionInfoDialog.qml") - print("**", connectionInfoDialog.errorString()) + console.log("**", connectionInfoDialog.errorString()) var popup = connectionInfoDialog.createObject(app,{nymeaEngine: engine, nymeaHost: nymeaHost}) popup.open() popup.connectionSelected.connect(function(connection) { @@ -322,7 +322,7 @@ WizardPageBase { onNext: { var rpcUrl = manualEntry.rpcUrl; - print("Try to connect ", rpcUrl) + console.log("Try to connect ", rpcUrl) var host = nymeaDiscovery.nymeaHosts.createWanHost("Manual connection", rpcUrl); engine.jsonRpcClient.connectToHost(host) } @@ -390,8 +390,8 @@ WizardPageBase { BtWiFiSetup { id: wifiSetup - onBluetoothStatusChanged: { - print("status changed", status) + onBluetoothStatusChanged: (status) => { + console.log("status changed", status) switch (status) { case BtWiFiSetup.BluetoothStatusDisconnected: pageStack.pop(wirelessBluetoothDiscoveryPage) @@ -419,12 +419,12 @@ WizardPageBase { onCurrentConnectionChanged: { if (wifiSetup.currentConnection) { - print("**** connected!") + console.log("**** connected!") pageStack.push(wirelessConnectionCompletedComponent, {wifiSetup: wifiSetup}) } } onWirelessStatusChanged: { - print("Wireless status changed:", wifiSetup.networkStatus) + console.log("Wireless status changed:", wifiSetup.networkStatus) if (wifiSetup.wirelessStatus === BtWiFiSetup.WirelessStatusFailed) { pageStack.pop() } @@ -452,7 +452,9 @@ WizardPageBase { BusyIndicator { anchors.centerIn: parent - visible: bluetoothDiscovery.discovering && deviceInfosProxy.count == 0 && bluetoothDiscovery.bluetoothAvailable && bluetoothDiscovery.bluetoothEnabled && PlatformHelper.locationServicesEnabled + visible: bluetoothDiscovery.discovering && deviceInfosProxy.count === 0 && + bluetoothDiscovery.bluetoothAvailable && bluetoothDiscovery.bluetoothEnabled && + PlatformHelper.locationServicesEnabled } delegate: NymeaSwipeDelegate { @@ -609,7 +611,7 @@ WizardPageBase { } onClicked: { - print("Connect to ", model.ssid, " --> ", model.macAddress) + console.log("Connect to ", model.ssid, " --> ", model.macAddress) if (model.selectedNetwork) { pageStack.push(networkInformationPage, { ssid: model.ssid}) } else { @@ -642,7 +644,7 @@ WizardPageBase { onBack: pageStack.pop(); onNext: { - print("connecting to", ssidTextField.text, passwordTextField.password) + console.log("connecting to", ssidTextField.text, passwordTextField.password) wifiSetup.connectDeviceToWiFi(ssidTextField.text, passwordTextField.password, true) pageStack.push(wirelessConnectingWiFiComponent) } @@ -690,7 +692,7 @@ WizardPageBase { showNextButton: passwordTextField.isValidPassword onNext: { - print("connecting to", ssid, passwordTextField.password) + console.log("connecting to", ssid, passwordTextField.password) wifiSetup.connectDeviceToWiFi(ssid, passwordTextField.password) pageStack.push(wirelessConnectingWiFiComponent) }