QLowEnergyController not working
Mobile and Embedded
2
Posts
2
Posters
1.2k
Views
2
Watching
-
Hi all!
I'm trying to get services from my device.void BluetoothService::FindDevices() { discoveryAgent = new QBluetoothDeviceDiscoveryAgent(); connect(discoveryAgent, SIGNAL(deviceDiscovered(const QBluetoothDeviceInfo&)), this, SLOT(foundDevice(const QBluetoothDeviceInfo&))); connect(discoveryAgent, SIGNAL(error(QBluetoothDeviceDiscoveryAgent::Error)), this, SLOT(deviceScanError(QBluetoothDeviceDiscoveryAgent::Error))); connect(discoveryAgent, SIGNAL(finished()), this, SLOT(scanFinished())); connect(discoveryAgent, SIGNAL(canceled()), this, SLOT(scanCanseled())); qWarning() << "\nStart searshing for devices!"; discoveryAgent->start(); } void BluetoothService::foundDevice(const QBluetoothDeviceInfo &info) { qWarning() << "Found device: " << info.address() << " " << info.name(); if (info.coreConfigurations() & QBluetoothDeviceInfo::BaseRateAndLowEnergyCoreConfiguration ) { qWarning() << "This device is BLE"; if (info.address().toString() == QString("F8:84:F2:0A:DC:3D")){ qWarning() << "This is our device!"; CheckServices(info.address()); } } } void BluetoothService::CheckServices(QBluetoothAddress address) { qWarning() << "Discovering services from device: " << address; m_control = new QLowEnergyController(address, this); connect(m_control, SIGNAL(serviceDiscovered(QBluetoothUuid)), this, SLOT(serviceDiscovered(QBluetoothUuid))); connect(m_control, SIGNAL(discoveryFinished()), this, SLOT(serviceScanDone())); connect(m_control, SIGNAL(error(QLowEnergyController::Error)), this, SLOT(controllerError(QLowEnergyController::Error))); connect(m_control, SIGNAL(connected()), this, SLOT(deviceConnected())); connect(m_control, SIGNAL(disconnected()), this, SLOT(deviceDisconnected())); m_control->connectToDevice(); } void BluetoothService::serviceDiscovered(QBluetoothUuid serviceID) { qWarning() << "Found service: " << serviceID; } void BluetoothService::serviceScanDone() { qWarning() << "Service scan done!"; } void BluetoothService::controllerError(QLowEnergyController::Error) { qWarning() << "Controller error!"; } void BluetoothService::deviceConnected() { qWarning() << "Device connected!"; m_control->discoverServices(); } void BluetoothService::deviceDisconnected() { qWarning() << "Device disconnected!"; }
And then nothing. Slots doesn't calling.
Console output:
Compiled with Qt Version 5.5.0 Start searshing for devices! Found device: "F8:84:F2:0A:DC:3D" "Test Galaxy S5" This device is BLE This is our device! Discovering services from device: "F8:84:F2:0A:DC:3D" Found device: "6F:EE:DC:16:3E:99" "6F-EE-DC-16-3E-99" This device is BLE Found device: "90:00:DB:30:FC:38" "Test Galaxy Tab S " This device is BLE Scan finished Wanna restart? (Y/N): n root@edison:~# Hub Compiled with Qt Version 5.5.0 Start searshing for devices! Found device: "6F:EE:DC:16:3E:99" "6F-EE-DC-16-3E-99" This device is BLE Found device: "90:00:DB:30:FC:38" "Test Galaxy Tab S " This device is BLE Found device: "F8:84:F2:0A:DC:3D" "Test Galaxy S5" This device is BLE This is our device! Trying connect to device: "F8:84:F2:0A:DC:3D"
-
Hi all!
I'm trying to get services from my device.void BluetoothService::FindDevices() { discoveryAgent = new QBluetoothDeviceDiscoveryAgent(); connect(discoveryAgent, SIGNAL(deviceDiscovered(const QBluetoothDeviceInfo&)), this, SLOT(foundDevice(const QBluetoothDeviceInfo&))); connect(discoveryAgent, SIGNAL(error(QBluetoothDeviceDiscoveryAgent::Error)), this, SLOT(deviceScanError(QBluetoothDeviceDiscoveryAgent::Error))); connect(discoveryAgent, SIGNAL(finished()), this, SLOT(scanFinished())); connect(discoveryAgent, SIGNAL(canceled()), this, SLOT(scanCanseled())); qWarning() << "\nStart searshing for devices!"; discoveryAgent->start(); } void BluetoothService::foundDevice(const QBluetoothDeviceInfo &info) { qWarning() << "Found device: " << info.address() << " " << info.name(); if (info.coreConfigurations() & QBluetoothDeviceInfo::BaseRateAndLowEnergyCoreConfiguration ) { qWarning() << "This device is BLE"; if (info.address().toString() == QString("F8:84:F2:0A:DC:3D")){ qWarning() << "This is our device!"; CheckServices(info.address()); } } } void BluetoothService::CheckServices(QBluetoothAddress address) { qWarning() << "Discovering services from device: " << address; m_control = new QLowEnergyController(address, this); connect(m_control, SIGNAL(serviceDiscovered(QBluetoothUuid)), this, SLOT(serviceDiscovered(QBluetoothUuid))); connect(m_control, SIGNAL(discoveryFinished()), this, SLOT(serviceScanDone())); connect(m_control, SIGNAL(error(QLowEnergyController::Error)), this, SLOT(controllerError(QLowEnergyController::Error))); connect(m_control, SIGNAL(connected()), this, SLOT(deviceConnected())); connect(m_control, SIGNAL(disconnected()), this, SLOT(deviceDisconnected())); m_control->connectToDevice(); } void BluetoothService::serviceDiscovered(QBluetoothUuid serviceID) { qWarning() << "Found service: " << serviceID; } void BluetoothService::serviceScanDone() { qWarning() << "Service scan done!"; } void BluetoothService::controllerError(QLowEnergyController::Error) { qWarning() << "Controller error!"; } void BluetoothService::deviceConnected() { qWarning() << "Device connected!"; m_control->discoverServices(); } void BluetoothService::deviceDisconnected() { qWarning() << "Device disconnected!"; }
And then nothing. Slots doesn't calling.
Console output:
Compiled with Qt Version 5.5.0 Start searshing for devices! Found device: "F8:84:F2:0A:DC:3D" "Test Galaxy S5" This device is BLE This is our device! Discovering services from device: "F8:84:F2:0A:DC:3D" Found device: "6F:EE:DC:16:3E:99" "6F-EE-DC-16-3E-99" This device is BLE Found device: "90:00:DB:30:FC:38" "Test Galaxy Tab S " This device is BLE Scan finished Wanna restart? (Y/N): n root@edison:~# Hub Compiled with Qt Version 5.5.0 Start searshing for devices! Found device: "6F:EE:DC:16:3E:99" "6F-EE-DC-16-3E-99" This device is BLE Found device: "90:00:DB:30:FC:38" "Test Galaxy Tab S " This device is BLE Found device: "F8:84:F2:0A:DC:3D" "Test Galaxy S5" This device is BLE This is our device! Trying connect to device: "F8:84:F2:0A:DC:3D"
@avrik I know this post is 10 months old, anyway it might help:
I have rather the same approach as yours, with a difference, when you write:
m_control = new QLowEnergyController(address, this);you call QLowEnergyController constructor with a BT address, which you retreived earlier from info.address().
On my side, I call like this:
m_control = new QLowEnergyController( info, this );
passing the whole QBluetoothDeviceInfo instead oh just the address.
It works for meHope this can help