【发布时间】:2013-11-04 08:09:16
【问题描述】:
我正在开发一个应用程序,我必须连接到 Android 4.3 上的蓝牙设备。
我想通过 Android 应用程序更改 CC2541 Keyfob 的名称。
我的想法是:
1.有一个纯文本,我可以在我的 Android 应用程序中输入我想要的名称。
2.输入姓名后,我按下按钮发送此文本。
3.如果CC2541从Android应用程序接收到此文本,它将改变keyfobdemo.c中以下代码的deviceName[]中的文本:
static uint8 deviceName[] =
{
// complete name
0x0b, // length of first data structure (11 bytes excluding length byte)
0x09, // AD Type = Complete local name
0x4b, // 'K'
0x65, // 'e'
0x79, // 'y'
0x66, // 'f'
0x6f, // 'o'
0x62, // 'b'
0x64, // 'd'
0x65, // 'e'
0x6d, // 'm'
0x6f, // 'o'
};
问题如下:
1.Android应用4.3如何将文本数据发送到CC2541 keyfob ??
2.CC2541端如何接收文本数据??
3.我需要使用任何个人资料吗?
对不起,我的英语和这些问题。
感谢您的指导。
编辑
我尝试使用 0x2A00 来获取设备名称服务,但是当我调用 Device_Name 函数时它发现它不起作用。
Name_Service 为空。
private static final UUID Device_Name_UUID = UUID.fromString("00002a00-0000-1000-8000-00805f9b34fb");
private static final UUID Write_UUID = UUID.fromString("00001800-0000-1000-8000-00805f9b34fb");
public void Device_Name(){
BluetoothGattService Name_Service = mBluetoothGatt.getService(Write_UUID );
if(Name_Service == null) {
Log.d(TAG, "Name_Service service not found!");
return;
}
BluetoothGattCharacteristic DeviceName = Name_Service.getCharacteristic(Device_Name_UUID);
if(DeviceName == null) {
Log.d(TAG, "DeviceName charateristic not found!");
return;
}
}
Log.v(TAG, "readCharacteristic(DeviceName) = " + mBluetoothGatt.readCharacteristic(DeviceName));
String i = "123";
DeviceName.setValue(i);
Log.v(TAG, "writeCharacteristic(DeviceName) = " + mBluetoothGatt.writeCharacteristic(DeviceName));
它显示以下日志:
V/BluetoothLeService( 3680): readCharacteristic(DeviceName) = true
V/BluetoothLeService( 3680): writeCharacteristic(DeviceName) = false
D/audio_hw_primary( 1752): found out /dev/snd/pcmC0D0p
W/audio_hw_primary( 1752): out_write() limiting sleep time 45351 to 23219
W/audio_hw_primary( 1752): out_write() limiting sleep time 34263 to 23219
W/audio_hw_primary( 1752): out_write() limiting sleep time 33696 to 23219
D/BtGatt.btif( 2646): btif_gattc_upstreams_evt: Event 3
I/BtGatt.btif( 2646): set_read_value unformat.len = 13
D/BtGatt.GattService( 2646): onReadCharacteristic() - address=90:59:AF:0B:8A:AB, status=0, length=13
D/BluetoothGatt( 3680): onCharacteristicRead() - Device=90:59:AF:0B:8A:AB UUID=00002a00-0000-1000-8000-00805f9b34fb Status=0
读取成功,我可以得到设备的名称。
我引用了 Bluetooth Page-Device Name ,格式是 UTF-8 字符串。 但它写特征为假。
【问题讨论】:
-
您的代码的问题是您无法使用非服务 UUID 执行 getService。设备名称属性总是在通用访问配置文件服务中找到(“00001800-0000-1000-8000-00805f9b34fb”)
-
@VegarWesterlund:我读过 Characteristic ,但 writeCharacteristic 写的是 false。你有建议吗??
标签: android bluetooth-lowenergy android-bluetooth android-4.3-jelly-bean