我在Windows 10上使用华硕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时:
在该特征上调用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' }
我不确定如何解释传递回的数据以进一步调试此问题。
答案 0 :(得分:0)
您的数据是ATT响应。 1:错误响应的操作码 8:失败的请求的操作码(使用CCCD uuid的按类型读取请求) 54 00:从句柄搜索 10:错误代码“找不到属性”
所以我猜想该特性缺少客户端特性配置描述符。