简体   繁体   English

在Android上使用Qt蓝牙连接到arduino

[英]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. 我在一个项目中需要通过蓝牙连接arduino Uno和平板电脑Android。

I search for two weeks now how to do it with the Qt library. 我现在搜索了两个星期如何使用Qt库。 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. 目前,我使用一个自定义库( http://qt-project.org/forums/viewreply/193094/ ),但是该库没有任何信号,因此我必须使用计时器来检查数据是否在串行上缓冲。

I'd like to use the "official" Qt library to get access to the signals/slots system. 我想使用“官方” Qt库来访问信号/插槽系统。

For the moment I try to set-up my arduino as master and slave, and android according, but nothing work. 目前,我尝试将arduino设置为master和slave,并根据android进行设置,但没有任何效果。 What I want to achieve on android : 我想在android上实现什么:

Start app 启动应用

Connect to an already paired arduino (know adress) 连接到已经配对的arduino(知道地址)

Get a signal when message is received from the arduino board 从arduino板收到消息时获取信号

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. 我想做的一件事是使用QBluetoothSocket连接到arduino(arduino作为从设备,android作为服务器),但是QBluetoothSocket似乎仅在android的从设备模式下工作。 And the QBluetoothServer can't let me connect to the arduino from my Qt app. 而且QBluetoothServer不能让我从我的Qt应用程序连接到arduino。

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 / System.err(4861):java.io.IOException:服务发现失败W / System.err(4861):在android.bluetooth.BluetoothSocket $ SdpHelper.doSdp(BluetoothSocket.java:462)W / System.err( 4861):在android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:240)W / System.err(4861):在dalvik.system.NativeStart.run(Native Method)W / Qt(4861):(null): 0((null)):qt.bluetooth.android:退回到解决方法。 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. W / Qt(4861):(null):0((null)):qt.bluetooth.android:使用找到的rfcomm通道-1 W / Qt(4861):(null):0((null)):qt。 bluetooth.android:调用导致错误。

finally I get it worked ! 终于我明白了!

I have to use this uuid : 我必须使用这个uuid:

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

Because the Bt shield have a default one. 因为Bt防护罩具有默认防护罩。 the code above is working now. 上面的代码现在可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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