I've to read the data from TI Sensor Tag. I've enabled the sensor and activated the notification locally using the BLE2 library (manager.writedata and manager.setnotify) but I can't undersatad how to implement the last 3 rows (in red).
Can anyone help me ?
The following code is from TexasInstruments
/*
* This is a self-contained function for turning on the magnetometer
* sensor. It must be called AFTER the onServicesDiscovered callback
* is received.
*/
private static void turnOnMagnetometer(BluetoothGatt bluetoothGatt) {
UUID magnetServiceUuid = UUID.fromString("f000aa30-0451-4000-b000-000000000000");
UUID magnetConfigUuid = UUID.fromString("f000aa32-0451-4000-b000-000000000000");
BluetoothGattService magnetService = bluetoothGatt.getService(magnetServiceUuid);
BluetoothGattCharacteristic config = magnetService.getCharacteristic(magnetConfigUuid);
config.setValue(new byte[]{1}); //NB: the config value is different for the Gyroscope
bluetoothGatt.writeCharacteristic(config);
}
/* The next step is enabling notifications. Enabling notifications is a two-part job, enabling it locally, and enabling it remotely. It can best be explained in code, see the following code snippet.
*/
private static void enableMagnetometerNotifications(BluetoothGatt bluetoothGatt) {
UUID magnetServiceUuid = UUID.fromString("f000aa30-0451-4000-b000-000000000000");
UUID magnetDataUuid = UUID.fromString("f000aa31-0451-4000-b000-000000000000");
UUID CCC = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb");
BluetoothGattService magnetService = bluetoothGatt.getService(magnetServiceUuid);
BluetoothGattCharacteristic magnetDataCharacteristic = magnetService.getCharacteristic(magnetDataUuid);
bluetoothGatt.setCharacteristicNotification(magnetDataCharacteristic, true); //Enabled locally
BluetoothGattDescriptor config = magnetDataCharacteristic.getDescriptor(CCC);
config.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
bluetoothGatt.writeDescriptor(config); //Enabled remotely
}
Can anyone help me ?
The following code is from TexasInstruments
/*
* This is a self-contained function for turning on the magnetometer
* sensor. It must be called AFTER the onServicesDiscovered callback
* is received.
*/
private static void turnOnMagnetometer(BluetoothGatt bluetoothGatt) {
UUID magnetServiceUuid = UUID.fromString("f000aa30-0451-4000-b000-000000000000");
UUID magnetConfigUuid = UUID.fromString("f000aa32-0451-4000-b000-000000000000");
BluetoothGattService magnetService = bluetoothGatt.getService(magnetServiceUuid);
BluetoothGattCharacteristic config = magnetService.getCharacteristic(magnetConfigUuid);
config.setValue(new byte[]{1}); //NB: the config value is different for the Gyroscope
bluetoothGatt.writeCharacteristic(config);
}
/* The next step is enabling notifications. Enabling notifications is a two-part job, enabling it locally, and enabling it remotely. It can best be explained in code, see the following code snippet.
*/
private static void enableMagnetometerNotifications(BluetoothGatt bluetoothGatt) {
UUID magnetServiceUuid = UUID.fromString("f000aa30-0451-4000-b000-000000000000");
UUID magnetDataUuid = UUID.fromString("f000aa31-0451-4000-b000-000000000000");
UUID CCC = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb");
BluetoothGattService magnetService = bluetoothGatt.getService(magnetServiceUuid);
BluetoothGattCharacteristic magnetDataCharacteristic = magnetService.getCharacteristic(magnetDataUuid);
bluetoothGatt.setCharacteristicNotification(magnetDataCharacteristic, true); //Enabled locally
BluetoothGattDescriptor config = magnetDataCharacteristic.getDescriptor(CCC);
config.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
bluetoothGatt.writeDescriptor(config); //Enabled remotely
}