Arduino HC-05 with Android BluetoothChat Sample

13,097

And I found my own solution, it's necessary to change the name of the device as well to match the HC-05. If I'm running a plain module out of the box (not in this case) you need to set:

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

To:

private static final String NAME_SECURE = "HC-05";
private static final String NAME_INSECURE = "HC-05";
Share:
13,097
user3787031
Author by

user3787031

Updated on June 04, 2022

Comments

  • user3787031
    user3787031 almost 2 years

    Background

    I'm working on a project to connect an Android app with an Arduino board through bluetooth (Arduino Uno with an HC-05 module). So I started development from the Arduino side, temporarily using the Bluetooth Terminal apps on the Play Store to simulate any data I have to transfer. Now I'm moving onto the Android side of it.

    Naturally, I went straight for the BluetoothChat sample (https://developer.android.com/samples/BluetoothChat/index.html) to get a head start. Googling online, it seems a one line change should get to BluetoothChat connected to my HC-05 module.

    Problem

    So I can't connect my BluetoothChat to the Arduino with HC-05. The Arduino project should work, it connects fine to a variety of Bluetooth Terminal apps on the Play Store.

    The only change I have made to the BluetoothChat sample is changing the code in BluetoothChatService.java:

    From

        // 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");
    

    To

    // 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");
    

    I was under the impression that was the only change I needed to make to allow my BluetoothChat sample to start moving. Something like this (http://blog.onaclovtech.com/2012/04/modifying-bluetooth-chat.html), albeit it looks to be an older version of BluetoothChat.

    Any help would be much appreciated. Thanks!