Bluetooth on Android
-
Hi, I have a problem with a bluetooth device and Android.
This is my code and after there is the log.
The problem is that I can connect to my external Rfcomm device. I see a blue led on to indicate an active bluetooth connection.
The problem is that, afet 2 / 4 seconds the connection will be closed.
Have you got any idea?void MainWindow::connected() { qDebug() << "connected()"; } void MainWindow::disconnected() { qDebug() << "disconnected()"; } void MainWindow::error(QBluetoothServiceDiscoveryAgent::Error error) { qDebug() << "finished()"; } void MainWindow::finished() { qDebug() << "finished()"; } void MainWindow::readyRead() { while (socket->canReadLine()) { qDebug() << socket->readLine().trimmed(); } } // Discovered service on "qID-17430018" "00:12:F3:30:8A:B8" void MainWindow::serviceDiscovered(const QBluetoothServiceInfo &info) { qDebug() << "Discovered service on" << info.device().name() << info.device().address().toString(); qDebug() << "\tService name:" << info.serviceName(); qDebug() << "\tDescription:" << info.attribute(QBluetoothServiceInfo::ServiceDescription).toString(); qDebug() << "\tProvider:" << info.attribute(QBluetoothServiceInfo::ServiceProvider).toString(); qDebug() << "\tL2CAP protocol service multiplexer:" << info.protocolServiceMultiplexer(); qDebug() << "\tRFCOMM server channel:" << info.serverChannel(); if (info.device().address().toString().compare("00:12:F3:30:8A:B8")== 0) { qDebug() << "connectToService()"; socket= new QBluetoothSocket(QBluetoothServiceInfo::RfcommProtocol); connect(socket, SIGNAL(connected()), this, SLOT(connected())); connect(socket, SIGNAL(disconnected()), this, SLOT(disconnected())); connect(socket, SIGNAL(readyRead()), this, SLOT(readyRead())); socket->connectToService(info); } }
D BluetoothAdapter: startDiscovery D BluetoothAdapter: startDiscovery = true D libuntitled.so: (null):0 ((null)): Discovered service on "qID-17430018" "00:12:F3:30:8A:B8" D libuntitled.so: (null):0 ((null)): Service name: "Serial Port Profile" D libuntitled.so: (null):0 ((null)): Description: "" D libuntitled.so: (null):0 ((null)): Provider: "" D libuntitled.so: (null):0 ((null)): L2CAP protocol service multiplexer: 0 D libuntitled.so: (null):0 ((null)): RFCOMM server channel: 0 D libuntitled.so: (null):0 ((null)): connectToService() D libuntitled.so: (null):0 ((null)): finished() D BluetoothUtils: isSocketAllowedBySecurityPolicy start : device null D BluetoothSocket: connect(): myUserId = 0 W BluetoothAdapter: getBluetoothService() called with no BluetoothManagerCallback D BluetoothSocket: getInputStream(): myUserId = 0 D BluetoothSocket: getOutputStream(): myUserId = 0 D libuntitled.so: (null):0 ((null)): connected() W System.err: java.io.IOException: bt socket closed, read return: -1 W System.err: at android.bluetooth.BluetoothSocket.read(BluetoothSocket.java:733) W System.err: at android.bluetooth.BluetoothInputStream.read(BluetoothInputStream.java:96) W System.err: at java.io.InputStream.read(InputStream.java:162) W System.err: at org.qtproject.qt5.android.bluetooth.QtBluetoothInputStreamThread.run(QtBluetoothInputStreamThread.java:86) D libuntitled.so: (null):0 ((null)): disconnected()
-
@mrdebug
to what kind of device are you connecting to?
My first guess is that the remote device requires pairing before data exchange? -
It is a rfid bluetooth reader.
Using the original app the reader works, so it isn't a pairing problem.
On Linux I can connect to it using rfcomm tool but not using Qt bluetooth stack.
On Linux I obtain this error://your code here ```Discovered service on "qID-17430018" "00:12:F3:30:8A:B8" Service name: "SPP" Description: "" Provider: "" L2CAP protocol service multiplexer: 0 RFCOMM server channel: 1 Ok connectToService() Discovered service on "qID-17430018" "00:12:F3:30:8A:B8" Service name: "SPP" Description: "" Provider: "" L2CAP protocol service multiplexer: 0 RFCOMM server channel: 5 Discovered service on "qID-17430018" "00:12:F3:30:8A:B8" Service name: "" Description: "" Provider: "" L2CAP protocol service multiplexer: -1 RFCOMM server channel: -1 finished() qt.bluetooth.bluez: void QBluetoothSocketPrivate::_q_readNotify() 12 error: -1 "Risorsa temporaneamente non disponibile" disconnected()
-
After much time spent on searching of what it is wrong I have implement bluetooth dev (Linux) directly.
In 50 lines of code now I have my bluetooth device working. The connection is very quicly.
I will write a java class to have the same on Android.
So how to use the Qt bluetooth framework it is not clear for me. -
hi @mrdebug,
your log seems to indicate a bug. can you create a report at bugreports.qt.io ? (and provide a link here)
thanks