Вопрос:
Я пытаюсь подключиться к своему устройству Bluetooth, однако при подключении и обнаружении всех служб и характеристик я не могу продвинуться, потому что возвращенной информации недостаточно. Я не получаю ни идентификаторы UUID, ни типичные UUID.
Что мне нужно сделать, чтобы получить доступ к UUID, чтобы потом можно было читать из характеристик?
Что я пробовал:
Мое устройство после вызова device.discoverAllServicesAndCharacteristics();
возвращает:
{ _40: 0, _65: 0, _55: null, _72: null }
и когда я захожу device
я получаю:
06-23 16:36:54.758 4397 4597 I ReactNativeJS: { isConnectable: null,
06-23 16:36:54.758 4397 4597 I ReactNativeJS: rssi: null,
06-23 16:36:54.758 4397 4597 I ReactNativeJS: serviceData: null,
06-23 16:36:54.758 4397 4597 I ReactNativeJS: overflowServiceUUIDs: null,
06-23 16:36:54.758 4397 4597 I ReactNativeJS: mtu: 23,
06-23 16:36:54.758 4397 4597 I ReactNativeJS: localName: null,
06-23 16:36:54.758 4397 4597 I ReactNativeJS: manufacturerData: null,
06-23 16:36:54.758 4397 4597 I ReactNativeJS: txPowerLevel: null,
06-23 16:36:54.758 4397 4597 I ReactNativeJS: id: '00:1E:C0:65:D7:DB',
06-23 16:36:54.758 4397 4597 I ReactNativeJS: solicitedServiceUUIDs: null,
06-23 16:36:54.758 4397 4597 I ReactNativeJS: name: 'RND7DB',
06-23 16:36:54.758 4397 4597 I ReactNativeJS: serviceUUIDs: null,
06-23 16:36:54.758 4397 4597 I ReactNativeJS: _manager:
06-23 16:36:54.758 4397 4597 I ReactNativeJS: { _eventEmitter:
06-23 16:36:54.758 4397 4597 I ReactNativeJS: { _subscriber:
06-23 16:36:54.758 4397 4597 I ReactNativeJS: { _subscriptionsForType:
06-23 16:36:54.758 4397 4597 I ReactNativeJS: { appStateDidChange:
06-23 16:36:54.758 4397 4597 I ReactNativeJS: [ { subscriber: [Circular],
06-23 16:36:54.758 4397 4597 I ReactNativeJS: emitter:
06-23 16:36:54.758 4397 4597 I ReactNativeJS: { _subscriber: [Circular],
06-23 16:36:54.758 4397 4597 I ReactNativeJS: isAvailable: true,
06-23 16:36:54.758 4397 4597 I ReactNativeJS: _eventHandlers: { change: {}, memoryWarning: {} },
06-23 16:36:54.758 4397 4597 I ReactNativeJS: currentState: 'active' },
06-23 16:36:54.758 4397 4597 I ReactNativeJS: listener: [Function],
06-23 16:36:54.758 4397 4597 I ReactNativeJS: context: undefined,
06-23 16:36:54.758 4397 4597 I ReactNativeJS: eventType: 'appStateDidChange',
06-23 16:36:54.758 4397 4597 I ReactNativeJS: key: 0 } ],
06-23 16:36:54.758 4397 4597 I ReactNativeJS: websocketMessage: [ , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ],
06-23 16:36:54.758 4397 4597 I ReactNativeJS: websocketOpen: [ , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ],
06-23 16:36:54.758 4397 4597 I ReactNativeJS: websocketClosed: [ , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ],
06-23 16:36:54.758 4397 4597 I ReactNativeJS: websocketFailed: [ , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ],
06-23 16:36:54.758 4397 4597 I ReactNativeJS: didUpdateDimensions:
06-23 16:36:54.758 4397 4597 I ReactNativeJS: [ { subscriber: [Circular],
06-23 16:36:54.758 4397 4597 I ReactNativeJS: emitter:
06-23 16:36:54.758 4397 4597 I ReactNativeJS: { _subscriber: [Circular],
06-23 16:36:54.758 4397 4597 I ReactNativeJS: sharedSubscriber: [Circular],
06-23 16:36:54.758 4397 4597 I ReactNativeJS: _currentSubscription: null },
06-23 16:36:54.758 4397 4597 I ReactNativeJS: listener: [Function],
06-23 16:36:54.758 4397 4597 I ReactNativeJS: context: undefined,
06-23 16:36:54.758 4397 4597 I ReactNativeJS: eventType: 'didUpdateDimensions',
06-23 16:36:54.758 4397 4597 I ReactNativeJS: key: 0 } ],
06-23 16:36:54.758 4397 4597 I ReactNativeJS: hardwareBackPress:
06-23 16:36:54.758 4397 4597 I ReactNativeJS: [ { subscriber: [Circular],
06-23 16:36:54.758 4397 4597 I ReactNativeJS: emitter:
06-23 16:36:54.758 4397 4597 I ReactNativeJS: { _subscriber: [Circular],
06-23 16:36:54.758 4397 4597 I ReactNativeJS: sharedSubscriber: [Circular],
06-23 16:36:54.758 4397 4597 I ReactNativeJS: _currentSubscription: null },
06-23 16:36:54.758 4397 4597 I ReactNativeJS: listener: [Function],
06-23 16:36:54.758 4397 4597 I ReactNativeJS: context: undefined,
06-23 16:36:54.758 4397 4597 I ReactNativeJS: eventType: 'hardwareBackPress',
06-23 16:36:54.758 4397 4597 I ReactNativeJS: key: 0 } ],
06-23 16:36:54.758 4397 4597 I ReactNativeJS: collectBugExtraData:
06-23 16:36:54.758 4397 4597 I ReactNativeJS: [ { subscriber: [Circular],
06-23 16:36:54.758 4397 4597 I ReactNativeJS: emitter:
06-23 16:36:54.758 4397 4597 I ReactNativeJS: { _subscriber: [Circular],
06-23 16:36:54.758 4397 4597 I ReactNativeJS: sharedSubscriber: [Circular],
06-23 16:36:54.758 4397 4597 I ReactNativeJS: _currentSubscription: null },
06-23 16:36:54.758 4397 4597 I ReactNativeJS: listener: [Function: collectExtraData],
06-23 16:36:54.758 4397 4597 I ReactNativeJS: context: null,
06-23 16:36:54.758 4397 4597 I ReactNativeJS: eventType: 'collectBugExtraData',
06-23 16:36:54.758 4397 4597 I ReactNativeJS: key: 0 } ],
06-23 16:36:54.758 4397 4597 I ReactNativeJS: collectRedBoxExtraData:
06-23 16:36:54.758 4397 4597 I ReactNativeJS: [ { subscriber: [Circular],
06-23 16:36:54.758 4397 4597 I ReactNativeJS: emitter:
06-23 16:36:54.758 4397 4597 I ReactNativeJS: { _subscriber: [Circular],
06-23 16:36:54.758 4397 4597 I ReactNativeJS: sharedSubscriber: [Circular],
06-23 16:36:54.758 4397 4597 I ReactNativeJS: _currentSubscription: null },
06-23 16:36:54.758 4397 4597 I ReactNativeJS: listener: [Function: collectExtraData],
06-23 16:36:54.758 4397 4597 I ReactNativeJS: context: null,
06-23 16:36:54.758 4397 4597 I ReactNativeJS: eventType: 'collectRedBoxExtraData',
06-23 16:36:54.758 4397 4597 I ReactNativeJS: key: 0 } ],
06-23 16:36:54.758 4397 4597 I ReactNativeJS: url:
06-23 16:36:54.758 4397 4597 I ReactNativeJS: [ { subscriber: [Circular],
06-23 16:36:54.758 4397 4597 I ReactNativeJS: emitter: { _subscriber: [Circular] },
06-23 16:36:54.758 4397 4597 I ReactNativeJS: listener: [Function],
06-23 16:36:54.758 4397 4597 I ReactNativeJS: context: undefined,
06-23 16:36:54.758 4397 4597 I ReactNativeJS: eventType: 'url',
06-23 16:36:54.758 4397 4597 I ReactNativeJS: key: 0 },
06-23 16:36:54.758 4397 4597 I ReactNativeJS: { subscriber: [Circular],
06-23 16:36:54.758 4397 4597 I ReactNativeJS: emitter: { _subscriber: [Circular] },
06-23 16:36:54.758 4397 4597 I ReactNativeJS: listener: [Function],
06-23 16:36:54.758 4397 4597 I ReactNativeJS: context: undefined,
06-23 16:36:54.758 4397 4597 I ReactNativeJS: eventType: 'url',
06-23 16:36:54.758 4397 4597 I ReactNativeJS: key: 1 } ],
06-23 16:36:54.758 4397 4597 I ReactNativeJS: toggleElementInspector:
06-23 16:36:54.758 4397 4597 I ReactNativeJS: [ { subscriber: [Circular],
06-23 16:36:54.758 4397 4597 I ReactNativeJS: emitter:
06-23 16:36:54.758 4397 4597 I ReactNativeJS: { _subscriber: [Circular],
06-23 16:36:54.758 4397 4597 I ReactNativeJS: sharedSubscriber: [Circular],
06-23 16:36:54.758 4397 4597 I ReactNativeJS: _currentSubscription: null },
06-23 16:36:54.758 4397 4597 I ReactNativeJS: listener: [Function],
06-23 16:36:54.758 4397 4597 I ReactNativeJS: context: undefined,
06-23 16:36:54.758 4397 4597 I ReactNativeJS: eventType: 'toggleElementInspector',
06-23 16:36:54.758 4397 4597 I ReactNativeJS: key: 0 },
06-23 16:36:54.758 4397 4597 I ReactNativeJS: { subscriber: [Circular],
06-23 16:36:54.758 4397 4597 I ReactNativeJS: emitter:
06-23 16:36:54.758 4397 4597 I ReactNativeJS: { _subscriber: [Circular],
06-23 16:36:54.758 4397 4597 I ReactNativeJS: sharedSubscribe
На данный момент я не знаю, что делать, поскольку я не получил никакой ценной информации для дальнейшего получения информации от характеристики.
Согласно документам мне нужны UUID для чтения с моего устройства.
device.readCharacteristicForService(
serviceUUID: UUID,
characteristicUUID: UUID,
transactionId: ?TransactionId
): Promise<Characteristic>
Примечание. Когда я использую приложение Ble Scanner на Android, я могу получать все службы и характеристики с их UUID.
Фрагмент кода:
@action connect = (deviceName) => {
const device = this.devices.find(device=>device.name === deviceName);
if(device === undefined){
this.info = "Couldn't find device";
return;
}
this.manager.stopDeviceScan();
this.selectedDevice = device;
this.selectedDevice
.connect()
.then((device) => {
this.info = "Discovering services and characteristics";
return device.discoverAllServicesAndCharacteristics();
})
.then((device) => {
this.info = "Setting notifications";
return this.setupNotifications(device)
})
.then(() => {
this.info = "Listening..."
}, (error) => {
this.info = error.message;
})
};
async setupNotifications(device) {
console.log(device);
console.log(this.manager.servicesForDevice(device.id));
}
выпуск github # 293