Hardware Reference
In-Depth Information
appealing way. In this case, we'll focus on getting the data and leave it up to the user to
determine how to process and present it.
One thing to be aware of when working with the SensorTag is that it's a mobile device.
It was designed to be low power, so the sensors are powered off by default. To read each
sensor, you have to write to a characteristic to turn it on. Once the sensor is enabled,
you can then read the data from it.
As discussed in “Characteristics” on page 59 , all operations related to user data are
effectuated through characteristics. To enable a sensor, you're first going to need to find
the service that contains the corresponding characteristic and the characteristic itself
(see “Service and Characteristic Discovery” on page 69 ), and then retrieve its value (as
described in “Reading Characteristics and Descriptors” on page 70 ). You then need to
modify the characteristic value to one that will enable the sensor and then write it back
to the device in the manner described in “Writing Characteristics and Descriptors” on
page 71 . This is called a read-modify-write operation.
You've already connected to the peripheral device and have the BluetoothGatt object
available to you. To retrieve the service, you're going to use a method inside the gatt
object called getService() . It takes a UUID argument, which means that you'll have
to provide the particular service UUID. These are all TI-specific UUIDs, but luckily, TI
provides the full list of service and characteristic UUIDs in Java source format in their
SensorTag source code.
You'll want to copy and paste the full UUID listing into your source code and make
them constants in your app. Here's an example of what it should look like:
private static final UUID
UUID_IRT_SERV = fromString ( "f000aa00-0451-4000-b000-000000000000" ),
UUID_IRT_DATA = fromString ( "f000aa01-0451-4000-b000-000000000000" ),
UUID_IRT_CONF = fromString ( "f000aa02-0451-4000-b000-000000000000" ),
UUID_ACC_SERV = fromString ( "f000aa10-0451-4000-b000-000000000000" ),
UUID_ACC_DATA = fromString ( "f000aa11-0451-4000-b000-000000000000" ),
UUID_ACC_CONF = fromString ( "f000aa12-0451-4000-b000-000000000000" ),
UUID_ACC_PERI = fromString ( "f000aa13-0451-4000-b000-000000000000" );
...
The service UUIDs have SERV suffix. Otherwise, the other UUIDs are characateristics.
Once you have these defined, you can write code to access the particular sensor's service
and characteristics.
Communicating with a remote device isn't quite as simple as reading a characteristic
and having the method return a value. You actually need to send ATT read and write
requests to the device, and the GATT server will then send responses to the requests
(these concepts are further explained in “ATT operations” on page 26 ). Only one request
can be handled at one time, and any other request that comes in while a request is being
Search WWH ::




Custom Search