In my last post on this subject, I documented how to set up your RPi for the purpose of connecting to a Sensor Tag by TI and then collect data through all its sensors.
In this second part of that journey I am going to show you how to accomplish the followings:
- Find the address of your Sensor Tag
- Connect manually to validate that Bluetooth works as expected
- Retrieve data from the sensors
Find Mac Address
There are a few commands that you will find useful in this quest of dealing with BT devices on Linux based systems.
With the following command, you can discover all the devices in discovery mode around you and their mac address. We’re interested into grabbing the one that reports “SensorTag”. Turn on your tag, launch the command and then Ctrl + C to stop as soon you spot it.
sudo hcitool lescan
Copy the associated address in the clipboard and then run this command
sudo hcitool leech <your address here>
Now let’s switch on the thermometer sensor and read its value through the use of the Gatt Tool.
gatttool -b 90:59:AF:0A:A8:4E –interactiveconnectchar-read-had 0x25disconnectexit
Now we’re going to download some Python code and test all out. Enter the folder that we created last time “andromeda” and use the following command
curl https://raw.githubusercontent.com/kywix/iamsblog/master/SensorTag/read_temp.py > read_temp.py
That will download from Github the code to retrieve temp data from the sensor. To run it just type
python read_temp.py <your_sendor_tag_address>
You should see something like this
And, if you do then you should be very happy because after this we can move to the next phase that is: build some code in Node js to retrieve and store data.