1. Introduction
Bluetooth Low Energy [
1] (BLE henceforth) wearable fitness devices have become more and more ubiquitous and inexpensive in the later years [
2]. These devices have become great and inexpensive tools to conduct clinical studies due to their capability to gather daily activity and sleep data without limiting the study subjects’ freedom [
3].
Non clinical-oriented devices are intended for a rather individual use, making the user pair a single device to it’s personal smartphone instead of being able to collect the raw data from multiple wearable devices from a computer.
Despite the limitations imposed by commercial lower-end wearable devices, they are already being used in experiments in fields such as pediatrics and gerontology with satisfying results [
4]. The main issue is that these limitations impose a cap to how many subjects can take part in an experiment as working with one-to-one pairing and without having methods to automatically extract the required data, this has to be done manually.
2. Objectives
The main objective is to reverse engineer an inexpensive, common and lower-end fitness device, the Mi Band 2 by the Chinese manufacturer XiaoMi and develop a library that is able to seamlessly connect to this kind of device and gather data from many of them at a time to enable these devices for research use. Associated to this library there will be some other tools to expose its core functionality and be able to develop software on top of it. Namely, these tools would be:
Shell: A command line to interact with the surrounding devices and command the computer to fetch the raw data from them
REST API: A simple API to expose the funcionality of the library to other technologies and be able to integrate it in more complex projects.
3. Materials and Methods
The first stage of the project was getting to know the profile of the Mi Band 2 as a BLE Peripheral and the commands that need to be issued in order to connect, authenticate and fetch the activity data from the device. This was done through the use of Android development tools and a Bluetooth Sniffing device alongside with the official Mi Fit smartphone application to register the most important ones. After this, we were able to obtain a full specification of all the endpoints of the Mi Band 2 and at least the relevant commands and response codes to perform the functionality we were aiming for. These commands were later implemented in Python to create our own independent library with the aid of the Python module “bluePy” to avoid implementing low-level Bluetooth functionality. Mi Band 2 devices were modeled in a Python Class that inherited from bluePy’s generic own BLE Peripheral Class and then the extracted BLE commands and responses were implemented as Class methods of our Mi Band 2 Class.
As for the library-related tools, the SHELL was developed alongside the library to test it’s functionality and conduct early prototype tests, while the API was developed once the main methods for authentication, connection and activity data fetching worked as expected. The REST API was finally used to integrate the library with the GeriaTIC project through a module inside their own platform: ClepITO.
Initially, we proposed a fully distributed architecture to integrate the library with the ClepITO platform. The library would run inside a Data Automatic Acquisition Server in a Linux System and then would connect to the platform’s own database to read and store data, while the ClepITO platform would control the Acquisition Server through HTTP requests making use of the REST API.
Due to some limitations of the project, we ended up using a fully integrated architecture, implementing the server inside a Linux virtual machine running in the same server as the ClepITO platform, and connecting both systems through a host-only network that provided bidirectional access to both systems, allowing for the same functionality as in a distributed environment but encapsulating everything under the same physical system. (See
Figure 1)
4. Results and Conclusions
To test the library’s capabilities, two field tests were conducted during two visits to one of the centers associated with the GeriaTIC project located at Carballo, A Corunna. The first one was done early in the development of the library, making use of the Shell developed to test the library, while the second one made use of the REST API. Both tests resulted successful, and we were able to seamlessly gather data from all of the study participants. The first test took a few minutes to connect and fetch all of the data from the devices, but this time was greatly improved to less than a minute per device for the second test.
The data extracted by hand from the Mi Fit application is previously aggregated by the application’s own algorithms, while being able to autonomously fetch the data from these devices provide us with a minute-by-minute data feed that we can manipulate and interpret at will, resulting in an improvement of the data quality. To conclude, we were able to develop a complete novel system capable of communicating a computer with a closed-source wearable device, the Mi Band 2, and improved the data gathering process in effort and time. By doing so, we have not only improved the methods and results of the GeriaTIC project but also have enabled other similar projects to perform better than before and it’s our hope that we have encouraged them to use inexpensive wearable devices such as the Mi Band 2 to improve these studies.
This work is, in the end, a proof of concept about BLE devices and how we can communicate with them in ways that they were not initially meant to, and how these same devices can help in health-care areas. This research also manifests the need of more accessible and open wearable devices so researchers can conduct more and better studies without having to crack open closed devices for that mean. As both the Mi Band 2 and the Mi Fit application are closed-source, we lack the ability to know for sure if our implementation of the commands to communicate with the device is complete, or if our way of interpreting and aggregating the data is completely correct, so there is still work and tests that need to be done in order to assure that these are as good or better than the originals.