简体   繁体   中英

Use Qt Bluetooth on android to connect to an arduino

I work on a project where I need to connect both arduino Uno and tablet Android via Bluetooth.

I search for two weeks now how to do it with the Qt library. For the moment I use a custom library ( http://qt-project.org/forums/viewreply/193094/ ) but this library doesn't have any signal, so I must use a timer to check if data are on the serial buffer.

I'd like to use the "official" Qt library to get access to the signals/slots system.

For the moment I try to set-up my arduino as master and slave, and android according, but nothing work. What I want to achieve on android :

Start app

Connect to an already paired arduino (know adress)

Get a signal when message is received from the arduino board

A thing I wanted to do is to use a QBluetoothSocket to connect to the arduino (arduino as slave, android as server) but QBluetoothSocket seem to work only on slave mode for android. And the QBluetoothServer can't let me connect to the arduino from my Qt app.

Thanks for help !

EDIT : I try this :

    socket = new QBluetoothSocket(QBluetoothServiceInfo::RfcommProtocol);
qDebug() << "Socket créé";
socket->connectToService(QBluetoothAddress("00:13:EF:00:06:4F"), QBluetoothUuid(serviceUuid), QIODevice::ReadWrite);
qDebug() << "Tentative de connection";

But I got this :

W/System.err( 4861): java.io.IOException: Service discovery failed W/System.err( 4861): at android.bluetooth.BluetoothSocket$SdpHelper.doSdp(BluetoothSocket.java:462) W/System.err( 4861): at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:240) W/System.err( 4861): at dalvik.system.NativeStart.run(Native Method) W/Qt ( 4861): (null):0 ((null)): qt.bluetooth.android: Falling back to workaround. W/Qt ( 4861): (null):0 ((null)): qt.bluetooth.android: Using found rfcomm channel -1 W/Qt ( 4861): (null):0 ((null)): qt.bluetooth.android: Invoke Resulted with error.

finally I get it worked !

I have to use this uuid :

static const QString serviceUuid(QStringLiteral("00001101-0000-1000-8000-00805F9B34FB"));

Because the Bt shield have a default one. the code above is working now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM