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

时间:2018-09-11 17:16:01

标签: android bluetooth bluetooth-lowenergy gatt bluetooth-gatt

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

找到了这个example,在读取电池电量(0x2A19 ,org.bluetooth.characteristic.battery_level)时返回了true,该电池电量被列为电池电量状态(0x2A1B)的说明中的“值”字段。

根据specs,电池电量状态“包括”电池电量:

Battery Level State Description

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

问题:

  1. 电池电量状态(0x2A1B)属于什么蓝牙服务?是成功返回false电池服务吗?其他StackOverflow question询问电池电源状态(0x2A1A),该状态也列在电池电量状态下。如何运作?
  2. falsetrue从读取特征返回时指示什么?

-

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

发现的服务和特征包括电池服务(0x180F)电池电量状态特征(0x2A1B)。还尝试根据Adafruit tutorial添加自定义特征以读取电池电量,但Android应用未找到新添加的特征。但是,使用AT命令读取特征是可行的-模块返回int

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

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

1 个答案:

答案 0 :(得分:2)

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