【问题标题】:HC 05 Bluetooth Module Not Connecting with AndroidHC 05 蓝牙模块无法连接安卓
【发布时间】:2016-04-23 04:59:37
【问题描述】:

我正在为盲人做一个智能手杖伴侣项目,以引导他们走路避开他们路上的障碍物。 它涉及将 Android 手机与 HC 05 蓝牙模块配对。 HC 05 蓝牙模块连接到 Arudino UNO 板。 HC 05 未与 Android 连接。 这是我在android上编写的连接代码。 注意:本活动以列表视图的形式列出已配对的设备,设备的地址和名称是从上一个活动中获取的。

    import android.app.Activity;
        import android.bluetooth.BluetoothAdapter;
        import android.bluetooth.BluetoothDevice;
        import android.bluetooth.BluetoothSocket;
        import android.os.Bundle;
        import android.view.View;
        import android.widget.AdapterView;
        import android.widget.ArrayAdapter;
        import android.widget.ListView;
        import android.widget.Toast;

        import java.io.IOException;
        import java.util.UUID;

/**
 * Created by Stealth on 20-04-2016.
 */
public class PairingList extends Activity
{
    ListView lview;
    String paires[];
    String macs[];
    ArrayAdapter<String> adapter;
    String btdevices[];
    BluetoothSocket btSocket;
    BluetoothDevice device;
    BluetoothAdapter btadapter;
    int BLUETOOTH_REQUEST = 1;
    private static final UUID MY_UUID = UUID.fromString("a60f35f0-b93a-11de-8a39-08002009c666");
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.pairinglist);
        lview = (ListView)findViewById(R.id.listviewid);
        btadapter = BluetoothAdapter.getDefaultAdapter();
        Bundle bn = getIntent().getExtras();
        paires = bn.getStringArray("paires");
        macs = bn.getStringArray("macs");
        adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,paires);
        lview.setAdapter(adapter);
        lview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                String address = macs[position];
                device = btadapter.getRemoteDevice(address);
                try {
                    btSocket = device.createRfcommSocketToServiceRecord(MY_UUID);
                }
                catch (IOException e)
                {
                    Toast.makeText(getBaseContext(),"e" + "     "+ address,Toast.LENGTH_LONG).show();
                }
                btadapter.cancelDiscovery();
                try {
                    btSocket.connect();
                    Toast.makeText(getBaseContext(),"Connected to Device",Toast.LENGTH_LONG);
                }
                catch (IOException e1)
                {
                    Toast.makeText(getBaseContext(),"e1"+"     " + address,Toast.LENGTH_LONG).show();

                }


            }
        });

    }
}

问题是异常 e1 总是触发。 我在地址中有 HC 05 模块的 MAC 地址 MAC 地址为 98:D3:31:40:9A:D2 HC 05 仍然没有与 Android 连接任何帮助将不胜感激 谢谢你!!!

【问题讨论】:

  • 显然,要安装您的应用程序的盲人有一台带盲文显示器的设备。
  • 不,真的。你需要智能手机吗?连接到 Arduino NANO 的 IR 障碍物检测器(因为它比 Arduino UNO 小得多,并且可以放入手柄中)驱动蜂鸣器绰绰有余。
  • 我计划通过电话向此人提供音频更新,因此我需要将其与 HC 05 连接,所以如果你可以请帮帮我,非常感谢
  • 这真是一个宽泛的问题。我建议你找一些关于如何使 Android 和 Arduino 通过 BT 进行通信的教程。但我不倾向于相信盲人会购买智能手机。

标签: java android bluetooth arduino


【解决方案1】:

也许尝试将 UUID 更改为“00001101-0000-1000-8000-00805f9b34fb”?我过去曾使用此 uuid 将 HC-05 连接到 Android 设备。

或者您可以尝试使用 getUuids() 为蓝牙发现的每个设备查找所有已发布服务及其关联的 UUID 值,然后使用有效的 UUID。

【讨论】:

  • 最好发现附近设备的UUID,而不是提供预定义的。另请注意,每个设备都有不同的 UUID。因此,您的 UUID 对 OP 无效。
  • 我试过那个 UUID 。触发相同的异常
  • 我使用带有大写字母的 UUID 并没有连接,当我给小写字母时它正在连接 在所有在线代码中,我读到 UUID 包含大写字母非常感谢
猜你喜欢
  • 1970-01-01
  • 2022-01-22
  • 2017-07-22
  • 1970-01-01
  • 2020-11-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-02-19
相关资源
最近更新 更多