Android Question BLE Notification on TI Sensor Tag

AngeloDavalli

Member
Licensed User
Longtime User
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

}
 

AngeloDavalli

Member
Licensed User
Longtime User
thanks Erel,
Is it what I did but is not working, the code I wrote is:

'enable sensor
manager.WriteData("f000aa30-0451-4000-b000-000000000000","f000aa32-0451-4000-b000-000000000000","1".GetBytes("UTF8"))
' wait using msgbox
Msgbox("enable notify mag","M")
' enable notify locally
manager.SetNotify("f000aa30-0451-4000-b000-000000000000","f000aa31-0451-4000-b000-000000000000",True)

If I've well understood the Texas Instrument sample code after this is it necessary one more enabling level for notify, the remote level as described in the last code row in the sample (in red)
 
Upvote 0

AngeloDavalli

Member
Licensed User
Longtime User
First of all thanks for you support !!!

After the enabling sensor I haven't logs, so in the Manager_WriteComplete sub I display in a label the Characteristic and the status and I obtatain:
Charac.: f000aa32-0451-4000-b000-000000000000 staus:0 and if I read the status I get the correct value.
after the following step regarding the setnotify the logs are:
Setting descriptors.Success=true
writing descriptors.true

It's seem OK but I can't receive data from sensors.
What do you suggest me to do ?
 
Upvote 0

AngeloDavalli

Member
Licensed User
Longtime User
I've solved the problem !!!!!

The notification process was OK, while I've done a mistake enabling the sensor.
The right code is:
B4X:
Dim valoriByte(1) As Byte
    valoriByte(0)=1
    manager.WriteData("f000aa10-0451-4000-b000-000000000000","f000aa12-0451-4000-b000-000000000000",valoriByte)

Erel
Thanks you again
 
Upvote 0
Top