背景

我正在研究通过蓝牙(带有HC-05模块的Arduino Uno)将Android应用程序与Arduino板连接的项目。因此,我从Arduino端开始开发,暂时使用Play商店上的Bluetooth Terminal应用程序来模拟我必须传输的任何数据。现在,我将其移至Android方面。

自然,我直接获取了BluetoothChat示例(https://developer.android.com/samples/BluetoothChat/index.html),以抢先一步。在网上搜寻时,似乎应该将连接到HC-05模块的BluetoothChat更改为一条线。

问题

所以我无法通过HC-05将BluetoothChat连接到Arduino。 Arduino项目应该可以正常运行,它可以很好地连接到Play商店中的各种Bluetooth终端应用程序。

我对BluetoothChat示例所做的唯一更改是更改了BluetoothChatService.java中的代码:



    // Unique UUID for this application
private static final UUID MY_UUID_SECURE =
        UUID.fromString("fa87c0d0-afac-11de-8a39-0800200c9a66");
private static final UUID MY_UUID_INSECURE =
        UUID.fromString("8ce255c0-200a-11e0-ac64-0800200c9a66");




// HC-05 UUID  "00001101-0000-1000-8000-00805F9B34FB"
private static final UUID MY_UUID_SECURE =
        UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
private static final UUID MY_UUID_INSECURE =
        UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");


我印象中这是我需要做的唯一更改,以使我的BluetoothChat示例能够开始移动。类似于(http://blog.onaclovtech.com/2012/04/modifying-bluetooth-chat.html)的东西,尽管它看起来是BluetoothChat的旧版本。

任何帮助将非常感激。谢谢!

最佳答案

我找到了自己的解决方案,有必要同时更改设备名称以匹配HC-05。如果我开箱即用地运行普通模块(在这种情况下不是),则需要设置:

// Name for the SDP record when creating server socket
private static final String NAME_SECURE = "BluetoothChatSecure";
private static final String NAME_INSECURE = "BluetoothChatInsecure";


至:

private static final String NAME_SECURE = "HC-05";
private static final String NAME_INSECURE = "HC-05";

07-25 22:07