From fa9ef3ef250db8a68dd798e9fc583bfbc10cd9c8 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Sun, 5 Aug 2018 19:25:53 +0200 Subject: [PATCH] delay discovery restarts a bit so that we don't end up in a busy loop if the adapter is busy --- libnymea-app-core/discovery/bluetoothservicediscovery.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libnymea-app-core/discovery/bluetoothservicediscovery.cpp b/libnymea-app-core/discovery/bluetoothservicediscovery.cpp index 0dac9d68..9c211465 100644 --- a/libnymea-app-core/discovery/bluetoothservicediscovery.cpp +++ b/libnymea-app-core/discovery/bluetoothservicediscovery.cpp @@ -2,6 +2,8 @@ #include "discoverymodel.h" +#include + BluetoothServiceDiscovery::BluetoothServiceDiscovery(DiscoveryModel *discoveryModel, QObject *parent) : QObject(parent), m_discoveryModel(discoveryModel) @@ -45,7 +47,11 @@ void BluetoothServiceDiscovery::discover() qDebug() << "BluetoothServiceDiscovery: Start scanning for service" << m_nymeaServiceUuid.toString(); setDiscovering(true); m_serviceDiscovery->setUuidFilter(m_nymeaServiceUuid); - m_serviceDiscovery->start(QBluetoothServiceDiscoveryAgent::FullDiscovery); + + // Delay restarting as Bluez might not be ready just yet + QTimer::singleShot(500, this, [this]() { + m_serviceDiscovery->start(QBluetoothServiceDiscoveryAgent::FullDiscovery); + }); } void BluetoothServiceDiscovery::stopDiscovery()