Connect a bluetooth device with QBluetooth?
How can i connect a bluetooth device with QBluetooth? Is it possible?
I saw some examples about the connection and how to connect to the server from another device playing the client role by using a QBluetoothSocket.
But how can i connect to a HC-06 module or to any other bluetooth device?
I also would like to know.
On the client side you start a service discovery searching for the UUID advertised by your HC-06 and once you have found it you use the resulting QBluetoothServiceInfo instance together with QBluetoothSocket and connect to the device. Hereby I am assuming that your HC-06 offers an rfcomm server.
I suggest you have a look at http://qt-project.org/doc/qt-5/qtbluetooth-btchat-example.html. The example demonstrates the client and server code.
Were you able to connect the module HC-06, using BluetoothService and BluetoothSocket? Applications made on ai2 quite friendly with the module HC-06, but in QML achieve data exchange fails.
Have anyone of you managed to connect to HC-06 ( or any other bluetooth-uart module ) ?
I am working on it for a couple of days now and still have no good results.
I tried to configure my app as server, create a socket immitating hc-06 and connect it to my app but this fails. I have also tried to connect to hc-06 as a slave but hc-06 provides no services so it cannot work as a master in a communication.
The HC-06 is a slave device. Once it is paired (e.g. via the control panel of Android with password 1234) you can simply connect to it. I know for sure that it works, because I played around with that module a few hours ago.
But I know that some phones and tablets do not support the RfComm protocol. The Acer Iconia B1 of my Son is one of them that dont work.
So you should first check the capabilities of the Android device. I would suggest to try the following very small and simple Java Example (in Googles Eclipse SDK) http://stefanfrings.de/avr_io/BtTest.zip
If it cannot connect, you will get an error message on screen and in the LogCat view.
Once you are sure that your Android device can connect to the HC-06 module, you may try my alternative AndroidRfComm class (which is for Qt) http://stefanfrings.de/android_qt/AndroidBluetooth.zip It calls the Java API via JNI almost in the same way as the official classes from Qt but does not use extra Threads and does not need the Signal/Slot stuff. So it's a bit simpler and may be easier to debug.
By the way: I did not try the new Bluetooth classes of QT 5.3. I started using Bluetooth with version 5.0 which did not have these classes. Since my own alternative class works fine, I did not feel the need to try the official classes.
Oh Mate, you really made my day! This your library works flawless! The issues u mention about RFCOMM support on specific Android devices is an already known issue for me, my Samsung gt-p3110 is working and can easily connect to hc-06 as it could using pure android interface and not qt-android interface. However i also have Lenovo IdeaTabS6000-F and it is having problems with connecting to HC-06 both from native android API and from Qt-Android interface. However it does make HC-06 led stop blinking as it should if it was connected, but qDebug returns connection errors. I'm going to investigate it further and will let You all know how are things.
Nevertheless this http://stefanfrings.de/android_qt/AndroidBluetooth.zip works really fine. Lots of dozens of thanks s.frings74 !
I’m going to investigate it further and will let You all know how are things.
Yes please keep us up to date. I would like to know why the Qt classes don't work for many people (maybe all?).
The bluetooth chat example (of Qt 5.3) works fine on my Netbook with Ubuntu 14.04 and a HC-06 module. I only had to enter another UUID in chat.cpp:
static const QLatin1String serviceUuid("00001101-0000-1000-8000-00805F9B34FB");
Edit: It works fine also on my mobile phone, which is an Huawei G525 with Android 4.1.2.
The only thing that I don't like is that I must run the lengthly discovery process in order to list the names of available devices.