简体   繁体   English

配对至CC2540蓝牙LE设备

[英]Pairing to a CC2540 Bluetooth LE Device

I am trying to connect to a BLE devices based on CC2540 from TI (I have the keyfob from TI, and another device from connectblue OLP425) with my Motorola RAZR, the only succes I had so far is an app named Propagation on the market that I don't have access to the sources. 我正在尝试使用我的摩托罗拉RAZR连接基于TI CC2540的BLE设备(我拥有TI的钥匙扣,以及来自connectblue OLP425的另一设备),到目前为止,我获得的唯一成功是市场上一款名为Propagation的应用,我没有资源。

I tried to connect to the device with this code but the biggest thing I don't understand is the UUID, 我尝试使用此代码连接到设备,但我最不了解的是UUID,

I downloaded an app on a iPad 3 and I found a device has the following UUID 00000000-0000-0000-ff31-1a064f8c5966 我在iPad 3上下载了一个应用程序,发现一个设备具有以下UUID 00000000-0000-0000-ff31-1a064f8c5966

private static final UUID SPP_UUID = UUID.fromString("00000000-0000-0000-ff31-1a064f8c5966");
BluetoothDevice bd  =BluetoothAdapter.getDefaultAdapter().getBondedDevices().iterator().next();
//I only have I device paired that is the Bluetooth Low Energy Device so using the first Device returned by the iterator is fine.
    try {
        BluetoothSocket bs = bd.createRfcommSocketToServiceRecord(UUID);
        bs.connect();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

All I get is a Service discovery failed in logcat 我得到的只是在logcat中发现服务失败

In almost all the example everyone is using 在几乎所有人使用的所有示例中

00000000-0000-1000-8000-00805f9b34fb 00000000-0000-1000-8000-00805f9b34fb

If I go further in the app it syas that the battery service is UUID 0x180f 如果我在应用程序中走得更远,则表示电池服务为UUID 0x180f

I would just like to create an app the read the value of this service which is a simple decimal value 我只想创建一个应用,读取此服务的值,它是一个简单的十进制值

anyone has any succes pairing with a BLE device in the past? 过去有人与BLE设备配对成功吗?

thank you 谢谢

Jonathan 乔纳森

I've been able to connect to my CC2540 with the Heart Rate Monitor. 我已经能够通过心率监测器连接到CC2540。 I flashed the firmware using the CCDebugger and using 0000180d-0000-1000-8000-00805f9b34fbas the UUID i've been able to read a value. 我使用CCDebugger和0000180d-0000-1000-8000-00805f9b34fbas刷新了固件,而UUID我已经能够读取一个值。

Using the Motorola_BLE_profile sample app with some modifications. 使用Motorola_BLE_profile示例应用程序进行一些修改。

primaryServices = mGattService.getGattPrimaryServices(device);
if (primaryServices == null) {
  String message = "Connection failed !";
  Toast.makeText(mContext, message, Toast.LENGTH_SHORT).show();
  return;
}
for (i = 0; i < primaryServices.length; i++) {
  Log.v(TAG, "primary service " + primaryServices[i]);
  if (primaryServices[i].equalsIgnoreCase(hrmUUID)) {
    try {
      status = mGattService.connectGatt(device, hrmUUID, callback1);
      if (status == true){
        mDevice = device;
        mLeState = CONNECTING;
        BluetoothLeReceiver.isDevicePickerPending = false;
      } else {
        String message = "Connection failed !";
        Toast.makeText(mContext, message, Toast.LENGTH_SHORT).show();   
      }

} catch (Exception e) {
  Log.e(TAG,"Exception while calling gatt Connect");
}
return;
if (i == primaryServices.length) {
 Log.v(TAG,"Primary Service not found");
 String message = "Connection failed !";
 Toast.makeText(mContext, message, Toast.LENGTH_SHORT).show();

} }

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

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