Android Question BLE TI SensorTag

zvone

Member
Licensed User
Longtime User
Hi!

Can anyone help me with some sample code, how to read data from bluetooth TI SensorTag accelerator.

I used Erels example for BLE2 and work correctly. SensorTag is connected and get characteristics map, but I don't know, how to activate the acceleratior sensor.

I've got this data:
- service: f000aa10-0451-4000-b000-000000000000
- characteristics data: f000aa11-0451-4000-b000-000000000000
- characteristic config: f000aa12-0451-4000-b000-000000000000
- characteristic timer: f000aa13-0451-4000-b000-000000000000

Any advice?

Thank you
 

zvone

Member
Licensed User
Longtime User
Here are some useful links:

SensorTag user guide:
http://processors.wiki.ti.com/index.php/SensorTag_User_Guide

Evothings examples:
https://github.com/evothings/evothings-examples/tree/master/examples/ti-sensortag-accelerometer

Some similar basic example:
https://books.google.si/books?id=Xf...f000aa10-0451-4000-b000-000000000000"&f=false

All UUIDs (accelerator: 0xAA11 for data, 0xAA12 for config, 0xAA13 for period):
http://processors.wiki.ti.com/images/a/a8/BLE_SensorTag_GATT_Server.pdf

Example, how to read temperature (maybe similar for accelerator):
http://neatocode.tumblr.com/post/48928591866/esp-for-your-android-ti-sensortag

Thank you, Erel, for replay ...
 
Upvote 0

zvone

Member
Licensed User
Longtime User
Erel, I've used your example with BLE2 and work properly, but When I read Characteristics, I get an empty value.

In documentations write that the Accelerator sensor must be turn on, but I can't used methods WriteData or SetNotify. I tried with string "02" and chr(2) and code like this:

B4X:
Dim d as Byte
d = 2

But they don't work ...

I probably do not understand the operation of Bluetooth and how to switching sensors.

Any idea?

Thanks for help.
 
Upvote 0

AngeloDavalli

Member
Licensed User
Longtime User
Erel;
I've a similar problem because a can't enable notifications on sensor tag.
I've foud the following code to read the magnetometer and to use the notification.
can you help in the traslation in B4A code ?


/**
* 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
}
 
Upvote 0
Top