[RFF]Interfacing BT4.0LE in OSX / Linux Goal of using Python
Dec 15, 2013 6:05:49 GMT
drobscure likes this
Post by ticpu on Dec 15, 2013 6:05:49 GMT
This was an interesting post from user csffsc from the burried RFduino forum.
This post / article is meant to be an information repository on understanding and communicating with Bluetooth 4.0 Low Energy devices, with the goal of using this data in Python.
As I quickly learned the RfDuino - which uses the Nordic nRF51822 chipset makes use of the BT 4.0 LE (or BT 4.0 Smart) protocol. Bluetooth 4.0 Smart is a subset of the full Bluetooth 4.0 protocol known as Smart Ready, or sometimes Dual Mode. In general, just about every computer, tablet, phone and usb dongle is going to be 'dual mode' or Smart Ready, if it says Bluetooth 4.0, it will be backwards compatible with BT 4/3/2.1/2/1 etc.
BT 4.0 LE works by broadcasting data - there is no pairing process. The device identifies itself thru it's UUID, as well as a few parameters which describe the data that is being sent. From what I understand there is a variety of agreed upon profiles, which define distribute data in a predictable way. I believe tagging your own data can be done by calling RFduino.advertisementData in void setup().
Currently all Bluetooth Low Energy devices use the Generic Attribute Profile (GATT), which can be defined by the following concepts (refer to Bluetooth Stack, article 2):
Client
A device that initiates GATT commands and requests, and accepts responses, for example a computer or smartphone.
Server
A device that receives GATT commands and requests, and returns responses, for example a temperature sensor.
Characteristic
A data value transferred between client and server, for example the current battery voltage.
Service
A collection of related characteristics, which operate together to perform a particular function. For instance, the Health Thermometer service includes characteristics for a temperature measurement value, and a time interval between measurements.
Descriptor
A descriptor provides additional information about a characteristic. For instance, a temperature value characteristic may have an indication of its units (e.g. Celsius), and the maximum and minimum values which the sensor can measure. Descriptors are optional - each characteristic can have any number of descriptors.
Collectively this information forms a Bluetooth 4.0 LE profile, generally defined using XML. While there is a variety of pre-defined profiles, they can be just as easily modified, or created from scratch. Profiles should be thought of as an agreed upon data structure. (refer to Bluetooth Stack, article 4)
At the moment, I do NOT know how-to easily receive BT 4.0LE data with Python, however it is programmatically possible with Objective-C in iOS & Android. I have however learned howto intercept the BT 4.0 LE data using my existing Bluetooth 4.0 dualmode chipsets (one was in my Macbook Retina, the other was a BT4.0 usb dongle) to monitor the bluetooth frequencies, and extract the RFduino's data.
If you have OSX, you can goto developer.apple.com and download the Hardware I/O toolkit (refer to OSX, article 1). This toolkit provides two tools designed for the job; Bluetooth Explorer and Packet Logger. Please look at the screenshots for details; they depict the captured data that the RFDuino's temperature sketch broadcasted.
If you have Linux, to interact with the data make sure you have the latest version of BlueZ, and investigate the commands; Hcitool, Hciconfig, lescan, and gatttool (refer to Linux article 1). It should also be noted, that VMWare (version 6) provides some access to the bluetooth chipset, but not enough access to do any meaningful scanning or packet capture. In my case I used a computer that boots into linux. I'm unsure if parallels would work.
I hope this was helpful, I plan to stay and continue to add to this thread & the forum in general. My goal is to convert a pre-existing arduino sketch that converts axial acceleration into angular motion (measured in degrees) to the RFDuino. Instructing the RFDuino to broadcast angular motion when it occurs, but otherwise be in sleep mode. Meanwhile using a python script to capture & graph the angular motion when it occurs.
Please review the links below, there is no shortage of available information on the topic. I spent most of the evening (and now morning) troubleshooting & compiling this information, so while this post might be a bit thin on procedure the resources below are all highly relevant.
Articles & Downloads for OSX:
1. Hardware I/O Tools for Xcode - developer.apple.com/downloads/index.action
2. Apple's Bluetooth Device Access Guide (*alot* of information) - developer.apple.com/library/mac/documentation/DeviceDrivers/Conceptual/Bluetooth/BT_Intro/BT_Intro.html
3. Sample OSX nRF51822 Code - github.com/Sproutling/nRF51822-OSX-Sample
Articles & Downloads for Linux:
1. Finding & interacting with Bluetooth 4.0 LE packets (hciitool lescan, gatttool) - joost.damad.be/2013/08/experiments-with-bluetooth-low-energy.html
2. BlueZ - www.bluez.org/about/
3. Great StackExchange reply w/links - stackoverflow.com/questions/17835469/using-bluetooth-low-energy-in-linux-command-line
Bluetooth Programming:
1. Bluetooth For Programmers - people.csail.mit.edu/rudolph/Teaching/Articles/BTBook-march.pdf
2. Bluetooth Design Guidelines (Low Energy begins @ pg20) - developer.apple.com/hardwaredrivers/BluetoothDesignGuidelines.pdf
Chipset Information:
1. Nordic nRF51822 Specifications - www.nordicsemi.com/eng/Products/Bluetooth-R-low-energy/nRF51822
2. Nordic nRF51822 SDK - devzone.nordicsemi.com/documentation/nrf51/4.4.1/html/group__nrf518__module.html
3. nRF51822 Development Wiki - robolabwiki.sdu.dk/mediawiki/index.php/Nordic_Semiconductor_nRF51822_development
Bluetooth Stack:
1. Bluetooth Protocol & Stack Information - en.wikipedia.org/wiki/Bluetooth#Bluetooth_Smart_.28v4.0.29
2. Bluetooth 4.0 Protocol & Stack Information - en.wikipedia.org/wiki/Bluetooth_low_energy
3. Texas Instruments BT 4.0 LE SensorTag User Guide - processors.wiki.ti.com/index.php/SensorTag_User_Guide
4. Bluetooth Profile Development - teleorigin.com/download/Bluetooth/Low%20Energy/Profile_development_BLE.pdf
5. Bluetooth 4.0 LE Video Training Series (Texas Instruments) - links.mkt102.com/servlet/MailView?ms=NDIxNzc2NTAS1&r=OTE2MzA3NDc4NAS2&j=MTk2NDExMjczS0&mt=1&rt=0
This post / article is meant to be an information repository on understanding and communicating with Bluetooth 4.0 Low Energy devices, with the goal of using this data in Python.
As I quickly learned the RfDuino - which uses the Nordic nRF51822 chipset makes use of the BT 4.0 LE (or BT 4.0 Smart) protocol. Bluetooth 4.0 Smart is a subset of the full Bluetooth 4.0 protocol known as Smart Ready, or sometimes Dual Mode. In general, just about every computer, tablet, phone and usb dongle is going to be 'dual mode' or Smart Ready, if it says Bluetooth 4.0, it will be backwards compatible with BT 4/3/2.1/2/1 etc.
BT 4.0 LE works by broadcasting data - there is no pairing process. The device identifies itself thru it's UUID, as well as a few parameters which describe the data that is being sent. From what I understand there is a variety of agreed upon profiles, which define distribute data in a predictable way. I believe tagging your own data can be done by calling RFduino.advertisementData in void setup().
Currently all Bluetooth Low Energy devices use the Generic Attribute Profile (GATT), which can be defined by the following concepts (refer to Bluetooth Stack, article 2):
Client
A device that initiates GATT commands and requests, and accepts responses, for example a computer or smartphone.
Server
A device that receives GATT commands and requests, and returns responses, for example a temperature sensor.
Characteristic
A data value transferred between client and server, for example the current battery voltage.
Service
A collection of related characteristics, which operate together to perform a particular function. For instance, the Health Thermometer service includes characteristics for a temperature measurement value, and a time interval between measurements.
Descriptor
A descriptor provides additional information about a characteristic. For instance, a temperature value characteristic may have an indication of its units (e.g. Celsius), and the maximum and minimum values which the sensor can measure. Descriptors are optional - each characteristic can have any number of descriptors.
Collectively this information forms a Bluetooth 4.0 LE profile, generally defined using XML. While there is a variety of pre-defined profiles, they can be just as easily modified, or created from scratch. Profiles should be thought of as an agreed upon data structure. (refer to Bluetooth Stack, article 4)
At the moment, I do NOT know how-to easily receive BT 4.0LE data with Python, however it is programmatically possible with Objective-C in iOS & Android. I have however learned howto intercept the BT 4.0 LE data using my existing Bluetooth 4.0 dualmode chipsets (one was in my Macbook Retina, the other was a BT4.0 usb dongle) to monitor the bluetooth frequencies, and extract the RFduino's data.
If you have OSX, you can goto developer.apple.com and download the Hardware I/O toolkit (refer to OSX, article 1). This toolkit provides two tools designed for the job; Bluetooth Explorer and Packet Logger. Please look at the screenshots for details; they depict the captured data that the RFDuino's temperature sketch broadcasted.
If you have Linux, to interact with the data make sure you have the latest version of BlueZ, and investigate the commands; Hcitool, Hciconfig, lescan, and gatttool (refer to Linux article 1). It should also be noted, that VMWare (version 6) provides some access to the bluetooth chipset, but not enough access to do any meaningful scanning or packet capture. In my case I used a computer that boots into linux. I'm unsure if parallels would work.
I hope this was helpful, I plan to stay and continue to add to this thread & the forum in general. My goal is to convert a pre-existing arduino sketch that converts axial acceleration into angular motion (measured in degrees) to the RFDuino. Instructing the RFDuino to broadcast angular motion when it occurs, but otherwise be in sleep mode. Meanwhile using a python script to capture & graph the angular motion when it occurs.
Please review the links below, there is no shortage of available information on the topic. I spent most of the evening (and now morning) troubleshooting & compiling this information, so while this post might be a bit thin on procedure the resources below are all highly relevant.
Articles & Downloads for OSX:
1. Hardware I/O Tools for Xcode - developer.apple.com/downloads/index.action
2. Apple's Bluetooth Device Access Guide (*alot* of information) - developer.apple.com/library/mac/documentation/DeviceDrivers/Conceptual/Bluetooth/BT_Intro/BT_Intro.html
3. Sample OSX nRF51822 Code - github.com/Sproutling/nRF51822-OSX-Sample
Articles & Downloads for Linux:
1. Finding & interacting with Bluetooth 4.0 LE packets (hciitool lescan, gatttool) - joost.damad.be/2013/08/experiments-with-bluetooth-low-energy.html
2. BlueZ - www.bluez.org/about/
3. Great StackExchange reply w/links - stackoverflow.com/questions/17835469/using-bluetooth-low-energy-in-linux-command-line
Bluetooth Programming:
1. Bluetooth For Programmers - people.csail.mit.edu/rudolph/Teaching/Articles/BTBook-march.pdf
2. Bluetooth Design Guidelines (Low Energy begins @ pg20) - developer.apple.com/hardwaredrivers/BluetoothDesignGuidelines.pdf
Chipset Information:
1. Nordic nRF51822 Specifications - www.nordicsemi.com/eng/Products/Bluetooth-R-low-energy/nRF51822
2. Nordic nRF51822 SDK - devzone.nordicsemi.com/documentation/nrf51/4.4.1/html/group__nrf518__module.html
3. nRF51822 Development Wiki - robolabwiki.sdu.dk/mediawiki/index.php/Nordic_Semiconductor_nRF51822_development
Bluetooth Stack:
1. Bluetooth Protocol & Stack Information - en.wikipedia.org/wiki/Bluetooth#Bluetooth_Smart_.28v4.0.29
2. Bluetooth 4.0 Protocol & Stack Information - en.wikipedia.org/wiki/Bluetooth_low_energy
3. Texas Instruments BT 4.0 LE SensorTag User Guide - processors.wiki.ti.com/index.php/SensorTag_User_Guide
4. Bluetooth Profile Development - teleorigin.com/download/Bluetooth/Low%20Energy/Profile_development_BLE.pdf
5. Bluetooth 4.0 LE Video Training Series (Texas Instruments) - links.mkt102.com/servlet/MailView?ms=NDIxNzc2NTAS1&r=OTE2MzA3NDc4NAS2&j=MTk2NDExMjczS0&mt=1&rt=0