我用的是Windows10,使用的是华硕BT-400。
我已经成功地连接到我的设备,读取所有特征/属性,并写入特征。但是,我有一个想要订阅通知的特征(我已经验证了这个特征具有notify属性),但是我遇到了一个错误。
当我跟踪代码执行时,它看起来像是在gatt.js的notify函数中,我得到了一个与错误相关的操作码。
Gatt.prototype.notify = function(serviceUuid, characteristicUuid, notify) {
var characteristic = this._characteristics[serviceUuid][characteristicUuid];
this._queueCommand(this.readByTypeRequest(characteristic.startHandle, characteristic.endHandle, GATT_CLIENT_CHARAC_CFG_UUID), function(data) {
var opcode = data[0];
if (opcode === ATT_OP_READ_BY_TYPE_RESP) {
var type = data[1];
var handle = data.readUInt16LE(2);
var value = data.readUInt16LE(4);
var useNotify = characteristic.properties & 0x10;
var useIndicate = characteristic.properties & 0x20;
if (notify) {
if (useNotify) {
value |= 0x0001;
} else if (useIndicate) {
value |= 0x0002;
}
} else {
if (useNotify) {
value &= 0xfffe;
} else if (useIndicate) {
value &= 0xfffd;
}
}
var valueBuffer = new Buffer(2);
valueBuffer.writeUInt16LE(value, 0);
this._queueCommand(this.writeRequest(handle, valueBuffer, false), function(data) {
var opcode = data[0];
if (opcode === ATT_OP_WRITE_RESP) {
this.emit('notify', this._address, serviceUuid, characteristicUuid, notify);
}
}.bind(this));
}
}.bind(this));
};
回调中data的取值为:{ 1,8,54,0,10 }。
另外,以下是我要调用的特征:
Characteristic
descriptors: null
name: null
properties: (5) ["read", "writeWithoutResponse", "write", "notify", "indicate"]
type: null
uuid: "495353431e4d4bd9ba6123c647249616"
_events: {data: ƒ}
_eventsCount: 1
_noble: Noble {initialized: true, address: "5c:f3:70:94:4b:01", _state: "poweredOn", _bindings: NobleBindings, _peripherals: {…}, …}
_peripheralId: "3481f4141bf0"
_serviceUuid: "49535343fe7d4ae58fa99fafd205e455"
__proto__: EventEmitter
当我在这个特征上调用discoverDescriptors时:
Descriptor {
_noble:
Noble {
initialized: true,
address: '5c:f3:70:94:4b:01',
_state: 'poweredOn',
_bindings:
NobleBindings {
_state: 'poweredOn',
_addresses: [Object],
_addresseTypes: [Object],
_connectable: [Object],
_pendingConnectionUuid: null,
_connectionQueue: [],
_handles: [Object],
_gatts: [Object],
_aclStreams: [Object],
_signalings: [Object],
_hci: [Hci],
_gap: [Gap],
_events: [Object],
_eventsCount: 21,
onSigIntBinded: [Function: bound ],
_scanServiceUuids: [] },
_peripherals:
{ '574d3263441d': [Peripheral], '3481f4141bf0': [Peripheral] },
_services: { '574d3263441d': {}, '3481f4141bf0': [Object] },
_characteristics: { '574d3263441d': {}, '3481f4141bf0': [Object] },
_descriptors: { '574d3263441d': {}, '3481f4141bf0': [Object] },
_discoveredPeripheralUUids: [ '574d3263441d', '3481f4141bf0' ],
_events:
[Object: null prototype] {
warning: [Function: bound ],
newListener: [Function: bound ],
stateChange: [Function],
discover: [Function] },
_eventsCount: 4,
_allowDuplicates: undefined },
_peripheralId: '3481f4141bf0',
_serviceUuid: '49535343fe7d4ae58fa99fafd205e455',
_characteristicUuid: '495353431e4d4bd9ba6123c647249616',
uuid: '2902',
name: 'Client Characteristic Configuration',
type:
'org.bluetooth.descriptor.gatt.client_characteristic_configuration' }
为了进一步调试这个问题,我不确定如何解释传回的数据。
发布于 2019-05-31 07:08:17
您的数据是ATT响应。1:错误响应的操作码8:失败的请求的操作码(使用CCCD uuid按类型请求读取) 54 00:从句柄搜索10:错误代码“未找到属性”
因此,我猜该特征缺少客户端特征配置描述符。
https://stackoverflow.com/questions/56386067
复制相似问题