电池电量状态 (0x2A1B) 蓝牙规范是什么意思?

What does Battery level state (0x2A1B) Bluetooth specification mean?

电池电量状态 (0x2A1B) 未在蓝牙文档的 Battery Service 规范下列出,只有 电池电量 (0x2A19) 是。但是,在电池服务下读取特性 电池电量状态 (0x2A1B) 时,会找到 0x2A1B 特性并返回 false,而不是错误或 null .

找到这个example,其中读取电池电量(0x2A19,org.bluetooth.characteristic.battery_level)时返回true,列为电池电量状态 (0x2A1B) 描述中的值字段之一。

电池电量状态 "includes" 电池电量,根据 specs:

编辑:使用 Nordic Connect Android 应用程序读取 电池电量状态 (0x2A1B) 时,这是值:Invalid data syntax: (0x) 64, "d"

问题:

  1. 电池电量状态 (0x2A1B) 属于什么蓝牙服务?是 Battery Service,因为 false 成功返回了吗?其他 Whosebug question 询问 Battery Power State (0x2A1A),它也在 Battery Level State 下列出。这是如何工作的?
  2. falsetrue 表示从读取特征返回的是什么?

-

背景: 我正在尝试通过来自 nRF51822 模块的 Android 应用程序读取电池电量(基于 Adafruit Bluefruit 32u4 LE)。

已发现的服务和特征包括电池服务 (0x180F)电池电量状态特征 (0x2A1B)。还尝试根据 Adafruit tutorial 添加自定义特征以读取电池电量,但 Android 应用程序找不到新添加的特征。然而,使用 AT 命令读取特性是有效的——模块 returns 和 int

我正在阅读 onServicesDiscovered 中的 0x2A1B 特征。我可以成功阅读的其他特征。这是 Android 应用程序中的代码,基于 this thread:

static String BATTERY_SERVICE_UUID = "0000180f-0000-1000-8000-00805f9b34fb";
static String BATTERY_LEVEL_UUID = "00002a1b-0000-1000-8000-00805f9b34fb";

@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
    if (status == BluetoothGatt.GATT_SUCCESS) {
        //Read the battery level
        getbattery(gatt);
    } 
}

void getbattery(BluetoothGatt mGatt) {
    BluetoothGattService batteryService = mGatt.getService(BATTERY_SERVICE_UUID);
    if(batteryService == null) {
        Log.i("BATTERYX", "Battery service not found!");
        return;
    }
    Log.i("BATTERYX", "Battery service found!");

    BluetoothGattCharacteristic batteryLevel = batteryService.getCharacteristic(BATTERY_LEVEL_UUID);
    if(batteryLevel == null) {
        Log.i("BATTERY", "Battery characteristic not found!");
        return;
    } Log.i("BATTERYX", "Battery characteristic found!");
    Log.i("BATTERYX", String.valueOf(mGatt.readCharacteristic(batteryLevel)));
}

这是已发现服务和特征的完整列表。

## SERVICES
[{UUID=00001800-0000-1000-8000-00805f9b34fb, NAME=Service Unknown}, 
{UUID=00001801-0000-1000-8000-00805f9b34fb, NAME=Service Unknown}, 
{UUID=00001530-1212-efde-1523-785feabcd123, NAME=Service Unknown}, 
{UUID=0000180a-0000-1000-8000-00805f9b34fb, NAME=Service Unknown}, 
{UUID=6e400001-b5a3-f393-e0a9-e50e24dcca9e, NAME=SERIAL_TRANSFER_SERVICE_UUID}, 
{UUID=0000180f-0000-1000-8000-00805f9b34fb, NAME=BATTERY_SERVICE_UUID}]


## CHARACTERISTICS
[[{UUID=00002a00-0000-1000-8000-00805f9b34fb, NAME=Characteristic Unknown}, //Device
{UUID=00002a01-0000-1000-8000-00805f9b34fb, NAME=Characteristic Unknown},   //Appearance
{UUID=00002a04-0000-1000-8000-00805f9b34fb, NAME=Characteristic Unknown}],  //Peripheral Preferred Connection Parameters
[{UUID=00002a05-0000-1000-8000-00805f9b34fb, NAME=Characteristic Unknown}], //Service Changed

[{UUID=00001532-1212-efde-1523-785feabcd123, NAME=Characteristic Unknown}, 
{UUID=00001531-1212-efde-1523-785feabcd123, NAME=Characteristic Unknown}, 
{UUID=00001534-1212-efde-1523-785feabcd123, NAME=Characteristic Unknown}],

[{UUID=00002a29-0000-1000-8000-00805f9b34fb, NAME=Characteristic Unknown}, //Manufacturer Name String
{UUID=00002a24-0000-1000-8000-00805f9b34fb, NAME=Characteristic Unknown},  //Model Number String
{UUID=00002a28-0000-1000-8000-00805f9b34fb, NAME=Characteristic Unknown},  //Software Revision String
{UUID=00002a26-0000-1000-8000-00805f9b34fb, NAME=Characteristic Unknown},  //Firmware Revision String
{UUID=00002a27-0000-1000-8000-00805f9b34fb, NAME=Characteristic Unknown}], //Hardware Revision String

[{UUID=6e400003-b5a3-f393-e0a9-e50e24dcca9e, NAME=SERIAL_TRANSFER_CHARACTERISTIC}, 
{UUID=6e400002-b5a3-f393-e0a9-e50e24dcca9e, NAME=Characteristic Unknown}],

[{UUID=00002a1b-0000-1000-8000-00805f9b34fb, NAME=Characteristic Unknown}]] //Battery level state

电池电量状态应该为您提供 0 到 64 (100) 个百分比的电池电量