Skip to content

BLE Python program to scan and connect the SensorTile device and enable BLE notification.

Notifications You must be signed in to change notification settings

MatteoOrlandini/Bluepy-Python-Bachelor-Thesis

Repository files navigation

Bluepy-Python-Thesis

This repository contains Bluetooth 4.0 (BLE) Python programs to scan and connect to the SensorTile device and enable BLE notification used in my bachelor thesis. The library used is bluepy, a Python interface to Bluetooth LE on Linux.

1. Scan bluetooth devices

In 1. Scan bluetooth devices, the program scan_only_sensortile_salvataggio_file.py receives the advertising data of nearby Bluetooth devices and filters the SensorTile advertising data using the SensorTile MacAddres c0:83:1d:31:45:48. The data are saved in bluepyscanlog.txt file. To run this code cd '.\1. Scan bluetooth devices\' and python scan_only_sensortile_salvataggio_file.py.

2. Identify sensortile services and characteristics

In 2. Identify sensortile services and characteristics, the program characteristic_and_service.py receives the UUIDs of the SensorTile Bluetooth services and associated characteristics and saves them in the Lista dei servizi e caratteristiche SensorTile.txt file. To run this code cd '.\2. Identify sensortile services and characteristics\' and python characteristic_and_service.py.

3. Notification enable and data save

In 3. Notification enable and data save, the program gestione_notifiche.py enables or disables, depending on the user's choice, notifications relating to the characteristic of the temperature and pressure sensor and the characteristics of the accelerometer, gyroscope and magnetometer sensor. The data (not decrypted) are saved in the Dati sensori.txt file. The handles needed to enable notifications were found by trial and error. To run this code cd '.\3. Notification enable and data save\' and python gestione_notifiche.py.

4. Notification enable and MATLAB data save

In 4. Notification enable and MATLAB data save, the program gestione_notifiche_MATLAB.py enables or disables, epending on the user's choice, notifications relating to the characteristic of the temperature and pressure sensor and the characteristics of the accelerometer, gyroscope and magnetometer sensor. The program saves the decrypted data in the Dati sensori.txt file. The 3 files created are "Accelerometro MATLAB.txt", "Giroscopio MATLAB.txt" and "Magnetometro MATLAB.txt" in which the data are written in a table according to the form timestamp \t X-axis value \t Y-axis value \t Z-axis value \t\n to be used later in MATLAB to make graphs. Changelog from 3. Notification enable and data save: the handles needed to enable notifications were now found via software. The data sent by the SensorTile has been decrypted. To run this code cd '.\4. Notification enable and MATLAB data save\' and python gestione_notifiche_MATLAB.py.

5. Notification enable and MATLAB data save 2.0

In 5. Notification enable and MATLAB data save 2.0, the program gestione_notifiche_MATLAB.py enables or disables, epending on the user's choice, notifications relating to the characteristic of the temperature and pressure sensor and the characteristics of the accelerometer, gyroscope, magnetometer sensor and sensor fusion. The program saves the decrypted data in the Dati sensori.txt file. The 3 files created are "Accelerometro MATLAB.txt", "Giroscopio MATLAB.txt" and "Magnetometro MATLAB.txt" in which the data are written in a table according to the form timestamp \t X-axis value \t Y-axis value \t Z-axis value \t\n to be used later in MATLAB to make graphs. Changelog from 4. Notification enable and MATLAB data save: the user can activate the sensor fusion (compact) notification. To run this code cd '.\5. Notification enable and MATLAB data save 2.0\' and python gestione_notifiche_MATLAB.py.

6. Pitch and roll notification

In 6. Pitch and roll notification, the program Ricezione_pitch_roll.py enables or disables, depending on the user's choice, notifications relating to the characteristic of the temperature and pressure sensor, to the characteristic of the accelerometer, gyroscope and magnetometer sensor, to the characteristic of the sensor fusion or to the characteristic of pitch and roll. The program saves the decrypted data in the "Dati sensori.txt" file. The 5 files created are "Accelerometro.txt.", "Giroscopio.txt", "Magnetometro.txt", "Sensor Fusion.txt" and "Pitch e Roll.txt" in which the data is written in tabular form according to theform timestamp \t X-axis value \t Y-axis value \t Z-axis value \t\n to be used later in MATLAB to make graphs. Changelog from 5. Notification enable and MATLAB data save 2.0: activation of notifications of the new pitch and roll feature (uuid = 00EE0000000111e1ac360002a5d5c51b). To run this code cd '.\6. Pitch and roll notification\' and python Ricezione_pitch_roll.py.

7. Ricezione notifiche (programma finale)

In 7. Ricezione notifiche (programma finale), the program Ricezione_notifiche.py enables or disables, depending on the user's choice, notifications relating to the characteristic of the temperature and pressure sensor, to the characteristic of the accelerometer, gyroscope and magnetometer sensor, to the characteristic of the sensor fusion or to the characteristic of pitch and roll. The program saves the decrypted data in the "Dati sensori.txt" file. The 5 files created are "Accelerometro.txt.", "Giroscopio.txt", "Magnetometro.txt", "Sensor Fusion.txt" and "Pitch e Roll.txt" in which the data is written in tabular form according to theform timestamp \t X-axis value \t Y-axis value \t Z-axis value \t\n to be used later in MATLAB to make graphs. Changelog from 6. Pitch and roll notification: if the SensorTile disconnects, the program continues to search for it until it becomes "visible" again. To run this code cd '.\7. Ricezione notifiche (programma finale)\' and python Ricezione_notifiche.py.

Results

The figure below shows a comparison between the filtered pitch data, in blue, and the data simply obtained from the formulas in which are used the accelerometer axis values, in red.

The figure below shows a comparison between the filtered roll data, in blue, and the data simply obtained from the formulas in which are used the accelerometer axis values, in red.

About

BLE Python program to scan and connect the SensorTile device and enable BLE notification.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages