我从事的项目需要通过蓝牙连接 arduino Uno 和平板电脑 Android。
我搜索了两个星期如何使用 Qt 库来完成它。 目前我使用自定义库 ( http://qt-project.org/forums/viewreply/193094/ ),但这个库没有任何信号,所以我必须使用计时器来检查串行缓冲区上是否有数据。
我想使用“官方”Qt 库来访问信号/槽系统。
目前,我尝试将我的 arduino 设置为主设备和从设备,并据此设置 android,但没有任何效果。 我想在 android 上实现的目标:
启动应用
连接到已经配对的arduino(知道地址)
从arduino板接收到消息时得到一个信号
我想做的一件事是使用 QBluetoothSocket 连接到 arduino(arduino 作为从设备,android 作为服务器)但是 QBluetoothSocket 似乎只能在 android 的从模式下工作。 QBluetoothServer 无法让我从我的 Qt 应用程序连接到 arduino。
感谢您的帮助!
编辑:我试试这个:
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";
但是我明白了:
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.
最佳答案
终于成功了!
我必须使用这个 uuid :
static const QString serviceUuid(QStringLiteral("00001101-0000-1000-8000-00805F9B34FB"));
因为Bt盾有一个默认的。上面的代码现在可以工作了。
关于android - 在android上使用Qt蓝牙连接到arduino,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28231784/