【问题标题】:Arduino HC-05 with Android BluetoothChat SampleArduino HC-05 与 Android 蓝牙聊天示例
【发布时间】:2015-08-21 00:23:43
【问题描述】:

背景

我正在做一个项目,通过蓝牙(带有 HC-05 模块的 Arduino Uno)将 Android 应用程序与 Arduino 板连接起来。所以我从 Arduino 端开始开发,暂时使用 Play Store 上的蓝牙终端应用程序来模拟我必须传输的任何数据。现在我正在转向它的 Android 端。

当然,我直接使用了 BluetoothChat 示例 (https://developer.android.com/samples/BluetoothChat/index.html) 来抢占先机。在网上搜索,似乎只有一行更改应该是连接到我的 HC-05 模块的 BluetoothChat。

问题

所以我无法使用 HC-05 将我的 BluetoothChat 连接到 Arduino。 Arduino 项目应该可以工作,它可以很好地连接到 Play 商店中的各种蓝牙终端应用程序。

我对 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。

任何帮助将不胜感激。谢谢!

【问题讨论】:

  • 你为什么选择那个特定的 UUID ?随便在 HC-05 UUID 服务号中找到任何信息?

标签: android bluetooth arduino android-bluetooth


【解决方案1】:

我找到了自己的解决方案,也需要更改设备名称以匹配 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";

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-22
    • 2018-02-19
    • 2018-03-10
    • 1970-01-01
    相关资源
    最近更新 更多