Proxy interface for transferring sensor data to a PostgreSQL database via Bluetooth Low Energy (BLE).
BLE_SQLAcquisition is an asynchronous Rust application that bridges a Bluetooth Low Energy (BLE) network device (e.g., ESP32) with a PostgreSQL database.
It continuously scans for a specified target device, connects to it, subscribes to its INDICATE characteristic, buffers incoming sensor data, and inserts full datasets into PostgreSQL.
The service is designed to run in Docker and automatically handles reconnections and buffering.
- Automatic scanning for BLE devices with a configurable name
 - Automatic connection and reconnection if the device becomes unavailable
 - Dynamic discovery of the BLE 
INDICATEcharacteristic - Data buffering until a full dataset of configurable size is received
 - Direct PostgreSQL integration for inserting sensor data
 - Configurable via environment variables
 - Designed to run as a container alongside a PostgreSQL service
 
- Docker and Docker Compose installed on the host system
 - A BLE adapter accessible from the container
 - An ESP32 (or compatible) broadcasting under the name specified in 
docker-compose.yaml 
The application expects the following table in PostgreSQL:
CREATE TABLE PG_TABLE (
    id SERIAL PRIMARY KEY,
    datapoints REAL[],
    timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);All parameters are set via environment variables. When running through Docker Compose, these are defined in docker-compose.yaml.
| Variable | Description | 
|---|---|
| PG_USER | PostgreSQL username | 
| PG_PASSWORD | PostgreSQL password | 
| PG_HOST | PostgreSQL host (container name in Compose) | 
| PG_DBNAME | Database name | 
| PG_PORT | PostgreSQL port | 
| PG_TABLE | Table to insert data | 
| BLE_DEVICE_NAME | Name of BLE device to connect | 
| DATA_SIZE | Number of datapoints per dataset | 
| VALUE_BYTE_SIZE | Number of bytes per value (1, 2, or 4) | 
- Build and start the services:
 
docker compose -f bleproxy-compose.yaml up --build- 
The container will start:
ble_proxy(Rust BLE acquisition service)
 - 
Ensure the
ble_proxycontainer has access to your BLE adapter by updating thedevicessection indocker-compose.yaml. Example: 
devices:
  - "/dev/bus/usb/001/005:/dev/bus/usb/001/005"Use lsusb or dmesg on the host to find the correct device path.
- The service retries automatically if the ESP32 disconnects or is unavailable
 - All collected datasets (e.g., 3648 datapoints) are inserted into the 
PG_TABLE - Values are parsed according to 
VALUE_BYTE_SIZE(1, 2, or 4 bytes) 
Early-stage implementation intended as a BLE-to-SQL proxy.
Planned improvements:
- Configurable characteristic types
 - Better error handling with exponential backoff
 - Support for multiple devices and concurrent acquisitions
 - Support for different database systems
 
This Project was entirely written by me. Because of defecites regarding documentation skills, this readme was written using AI