Getting started with TI BLE Sensor Tag + noble

I’ve been exploring the TI BLE sensor tag for our final and since other people might use it, here are some useful tips on how to get started.

1. Setting up Noblehttps://github.com/sandeepmistry/noble
It wasn’t easy to setup noble. First, because it has lots of dependencies and the package.json didn’t work for me. I had to create my own, and you can try if you want (includes async, index, noble – which are required – and express, socket.io and open that are not, but I needed in my project: https://github.com/mariapaulasaba/CDNI-magical-backpack/blob/master/package.json

Second, because after setting up, I couldn’t run the examples. And the reason is there is an error in the first line: “var noble = require(‘../index’);”
That is wrong. Just change to: “var noble = require(‘noble’);” and you should be fine.

2. Running the examples
The advertisement-discovery.js prints out all devices it is able to find, but does not connect to any of them. You can use it to see if your server can read your TI BLE Sensor Tag. (Tip: it won’t read if you don’t press the “wake up” button). I’m not sure the name appears, you might have to find it by the UUID. If you don’t know its UUID, download the Light Blue app and take note of it.

The other example peripheral-explorer.js will take the UUID as an argument, look for that specific peripheral, connect, print out all the data about services and characteristics, disconnect and quit the program. That’s probably not what you want. When disconnect, you want it to connect it again. You can change that in this function:

peripheral.on(‘disconnect’, function() {
process.exit(0); //when disconnect, quit the program
});

to the following:

peripheral.on(‘disconnect’, function() {
noble.startScanning(); //when disconnect, start scanning again
});

This example is useful to get specific services and characteristics UUIDs. In this way, I could know which UUID referred to the accelerometer, for example.

3. Reading a characteristic
There is no complete example of reading specific characteristics, but if you look at the Wiki page, there is a getting started page with all code you need:
https://github.com/sandeepmistry/noble/wiki/Getting-started

First thing I did was trying to read the accelerometer data it was tricky too. The accelerometer service has 3 characteristics:
Data: F000AA11 * 0x2D Read/Notify X : Y : Z (3 bytes)
Configuration: F000AA12 * 0x31 R/W 1 byte
Period: F000AA13 * 0x34 R/W 1 byte Period = [Input*10]ms

I started accessing the Data one. In the example code, the line console.log(data.toString(‘utf8’)); didn’t print anything. Because my data was all zeros. When I console.log(data), I got only Buffer 00 00 00. So talking to Tom, and looking the Sensor Tag User Guide (yes, there is one!), we learned that in order to get sensor data, we have to enable it, which basically means wake it up by writing 1 to the Configuration characteristic. It is also possible to change the frequency the data is sent, by writing to the Period characteristic.

(I will complete this post as I continue the project, but I already foresee two things I will have to deal with):

4. Notifying (TBD)

5. Using multiple Sensor Tags at the same time (TBD)

2 thoughts on “Getting started with TI BLE Sensor Tag + noble

  1. Thank you for posting Maria.
    I have few things to add.

    1. peripheral uuid issue
    As I asked you, the uuid I got from advertising-discover.js example(noble) and the one from Light Blue was different. But it turns out that I have to use the one from the advertising-discover.js example for trying peripheral-explorer.js. That was the right one for me. It was interesting because I check if the Light Blue one reading key status, and it worked well. But had different UUID(servieces and charicteristics’ uuids are same.)

    2. Reading a characteristic in the easy way
    I was also stuck in this part, but I was able to find this library.
    https://github.com/sandeepmistry/node-sensortag
    It gives me logs in a readable shape. like,

    readAccelerometer
    x = -0.1 G
    y = 0.2 G
    z = 1 G

    I have to look over this more, but love to share this in advance.

Leave a Reply