Я начинаю играть с программированием bluetooth, чтобы подключить кнопку Flic к моему Ubuntu 16.04. Для этого я использую Qt и его библиотеку BLE. Однако, когда я пытаюсь подключиться к кнопке, я получаю эту ошибку:Qt Bluetooth LE - ресурс временно недоступен
qt.bluetooth.bluez: void QBluetoothSocketPrivate::_q_readNotify() 7 error: -1 "Resource temporarily unavailable"
Я также попытался подключиться непосредственно hcitool и gatttool на ту же кнопку, она работает в течение нескольких секунд, а затем я получаю ошибку
(gatttool:24877): GLib-WARNING **: Invalid file descriptor.
Если я пытаюсь с другой кнопкой у меня есть, я получаю ту же ошибку в Qt, но
Error: connect error: Connection reset by peer (104)
в командной строке.
Может ли кто-нибудь объяснить мне, что происходит? У меня Ubuntu 16.04, blueZ 5.37 и Qt 5.7. Вот минимальный пример моей программы:
main.cpp
#include <QCoreApplication>
#include "device.h"
#include "bledevice.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
//connecting to the device
BLEDevice theButton;
return a.exec();
}
bledevice.cpp
#include "bledevice.h"
#include <QBluetoothAddress>
#include <QBluetoothLocalDevice>
#include <QBluetoothServiceDiscoveryAgent>
#include <QLowEnergyController>
#include <QDebug>
BLEDevice::BLEDevice(QObject *parent) : QObject(parent)
{
QBluetoothAddress address((QString("xx:xx:xx:xx:xx:xx")));
controller = new QLowEnergyController(address);
connect(controller, SIGNAL(connected()),
this, SLOT(deviceConnected()));
connect(controller, SIGNAL(error(QLowEnergyController::Error)),
this, SLOT(errorReceived(QLowEnergyController::Error)));
connect(controller, SIGNAL(disconnected()),
this, SLOT(deviceDisconnected()));
qDebug() << "Trying to connect..." ;
qDebug() << QT_VERSION_STR;
controller->connectToDevice();
}
void BLEDevice::deviceConnected()
{
qDebug() << "Device connected";
}
void BLEDevice::deviceDisconnected()
{
qDebug() << "Device disconnected";
controller->disconnectFromDevice();
}
void BLEDevice::errorReceived(QLowEnergyController::Error /*error*/)
{
qWarning() << "Error: " << controller->errorString();
}
bledevice.h
#ifndef BLEDEVICE_H
#define BLEDEVICE_H
#include <QObject>
#include <QLowEnergyController>
class BLEDevice : public QObject
{
Q_OBJECT
public:
explicit BLEDevice(QObject *parent = 0);
protected:
QLowEnergyController *controller;
signals:
public slots:
void deviceConnected();
void deviceDisconnected();
void errorReceived(QLowEnergyController::Error);
};
#endif // BLEDEVICE_H
А вот команда на результаты из терминала:
$ sudo hcitool lescan
[sudo] password for jennifer:
LE Scan ...
xx:xx:xx:xx:xx:xx f022cpdk
xx:xx:xx:xx:xx:xx (unknown)
yy:yy:yy:yy:yy:yy f022cpGv
yy:yy:yy:yy:yy:yy (unknown)
$sudo gatttool -b xx:xx:xx:xx:xx:xx -I
[xx:xx:xx:xx:xx:xx][LE]> connect
Attempting to connect to xx:xx:xx:xx:xx:xx
Connection successful
[xx:xx:xx:xx:xx:xx][LE]>
(gatttool:24877): GLib-WARNING **: Invalid file descriptor.
[xx:xx:xx:xx:xx:xx][LE]>exit
$sudo gatttool -b yy:yy:yy:yy:yy:yy -I
[yy:yy:yy:yy:yy:yy][LE]> connect
Attempting to connect to yy:yy:yy:yy:yy:yy
Error: connect error: Connection reset by peer (104)
[yy:yy:yy:yy:yy:yy][LE]> exit
Заранее спасибо за вашу помощь.
Bluez 3. * - очень старая версия. Вы должны перейти на Bluez 5.46 – abhiarora
Я разработал свой собственный стек BLE от BLUEZ. Но по причинам, я должен использовать библиотеки Qt BLE. Вы решили свою проблему, потому что сейчас я столкнулся с ней. – abhiarora