Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/parisneo/bleak_ble_tools

A set of tools to use bluetooth devices with python
https://github.com/parisneo/bleak_ble_tools

Last synced: 21 days ago
JSON representation

A set of tools to use bluetooth devices with python

Awesome Lists containing this project

README

        

# BLE Data Logger

[![GitHub release](https://badgen.net/github/release/ParisNeo/Bleak_BLE_tools)](https://github.com/ParisNeo/Bleak_BLE_tools/releases)
[![GitHub license](https://badgen.net/github/license/ParisNeo/Bleak_BLE_tools)](https://github.com/ParisNeo/Bleak_BLE_tools/blob/master/LICENSE)

File: logger.py

Author: Saifeddine ALOUI + ChatGPT
## Description
This script uses the Bleak library to connect to a BLE device and logs data from a specific characteristic of the device. The logged data is saved to a CSV file. The script supports two modes:

Notification mode: The script subscribes to notifications from the characteristic and logs the data as it is received. The logging can be stopped by pressing 'q'.
Polling mode: The script periodically reads the characteristic and logs the data. This mode can be used when the characteristic does not support notifications.
Installation
The script requires the following libraries:

- asyncio
- argparse
- bleak
- struct
To install these libraries, use the following command:

```bash
pip install asyncio argparse bleak struct
```
## Usage
The script can be run from the command line by providing the following arguments:

- mac_address: The MAC address of the device.
- service_uuid: The UUID of the service that the characteristic belongs to.
- characteristic_uuid: The UUID of the characteristic to log data from.
- -p, --path: The path to the CSV file to be created. Default is ./log.csv.
- -t, --timeout: The timeout in seconds for the BLE device to respond. Default is 5.0.
- -f, --force_read: Forces the script to use polling mode even if the characteristic supports notifications.
- -e, --entry_format: The format of the data, defaults to ' [-p ] [-t ] [-f] [-e ] [-h ]
```

## Customization explaining
The end user can control the file header and the data format through the call arguments of the script logger.py. The arguments file_header and entry_format allow the user to specify the format of the data and the header of the csv file respectively.

For example, if the user wants to log data from a temperature sensor that sends data in the format of a float in degrees Celsius, the user can set file_header to "timestamp, temperature (C)" and entry_format to '