return mDeviceDiscoveryAgent->isActive();
}
+void Ble::errorHandle(QLowEnergyController::Error err)
+{
+ error((int)err);
+}
+
void Ble::deviceDiscovered(const QBluetoothDeviceInfo &device)
{
if(device.coreConfigurations() & QBluetoothDeviceInfo::LowEnergyCoreConfiguration)
{
+ leDeviceFound(device.name(), device.address().toString());
//qDebug() << "BLE device found: " << device.address().toString();
///We have a device. Let's scan to see if it supports the service Uuid's we want
connect(control, &QLowEnergyController::stateChanged, [control, this](QLowEnergyController::ControllerState state)
{
- //qDebug() << "Controller state changed for device: " << control->remoteAddress().toString() << state;
+ qDebug() << "Controller state changed for device: " << control->remoteAddress().toString() << state;
if(state == QLowEnergyController::DiscoveredState)
{
devicesChanged();
connect(control, &QLowEnergyController::disconnected, control, &QLowEnergyController::deleteLater); // if we disconnect, clean up.
connect(control, &QLowEnergyController::connected, [&control]()
{
- //qDebug() << "Device connected. Discovering services...";
+ qDebug() << "Device connected. Discovering services...";
control->discoverServices();
});
+ connect(control, SIGNAL(error(QLowEnergyController::Error)), this, SLOT(errorHandle(QLowEnergyController::Error)));
connect(control, &QLowEnergyController::serviceDiscovered, [&control, this, device](const QBluetoothUuid & uuid)
{
Q_FOREACH(ServiceIdentifier * service, services)
{
- //qDebug() << "checking if service uuid (" << uuid.toString() << ") matches the one we want (" << service->serviceUuid << ")";
+ qDebug() << "checking if service uuid (" << uuid.toString() << ") matches the one we want (" << service->serviceUuid << ")";
if(service->serviceUuid == uuid.toString())
{
service->service = control->createServiceObject(uuid, service);
}
}
});
+ qDebug() << "Attempting to connect...";
control->connectToDevice();
}
}
#include <QJSValue>
#include <QBluetoothDeviceInfo>
+#include <QLowEnergyController>
class QBluetoothDeviceDiscoveryAgent;
class QLowEnergyService;
class ServiceIdentifier : public QObject
{
Q_OBJECT
+ Q_PROPERTY(QString deviceName READ getDeviceName)
+ Q_PROPERTY(QString deviceName READ getDeviceAddress)
+
public:
ServiceIdentifier(const QString & s, const QString & r, const QString & t, QObject *parent = nullptr)
:QObject(parent), serviceUuid(s), rxUuid(r), txUuid(t), service(nullptr), isValid(false) {}
+
+ QString getDeviceName() { return deviceName; }
+ QString getDeviceAddress() { return deviceAddress; }
+
QString serviceUuid;
QString rxUuid;
QString txUuid;
Q_SIGNALS:
void scanningChanged();
void devicesChanged();
+ void leDeviceFound(QString name, QString address);
+ void error(int);
private Q_SLOTS:
-
+ void errorHandle(QLowEnergyController::Error err);
void deviceDiscovered(const QBluetoothDeviceInfo & device);
private: