A simple Bluetooth monitoring service which continuously scans for nearby devices, stores detection data in SQLite, and provides a web-based dashboard for analytics, visualization and data download. A collection of API endpoints are also supported.
Note: This software is designed for monitoring Bluetooth devices in environments where you have permission to do so. Please respect privacy and comply with local regulations regarding device monitoring.
- Continuous Bluetooth Scanning: Automatically discovers nearby Bluetooth devices
- Data Persistence: Stores device detection data with timestamps and RSSI values
- Web Dashboard: Real-time analytics with interactive timeline visualization
- APIs: Basic APIs to access data and perform operations via external tools
- CSV Export: Download scan data for analysis in external tools
- Configuration Management: Runtime configuration updates via web interface
- Docker Support: Containerized deployment with health checks
- Timeline Visualization: Gantt chart-style view of device presence over time
- Database Management: Clear data and export capabilities
The web dashboard provides:
- Real-time summary statistics
- Interactive device timeline (Gantt chart)
- Recent scan results table
- Configuration management
- Data export and database management tools
- Python 3.8+
- Bluetooth adapter (built-in or USB)
- Linux/macOS (Windows support via Docker)
bluetoothpackagelibbluetooth-devpkg-configgcc(for compiling native extensions)
# Build the image
docker build -t bluemon .
# Run with persistent data storage
docker run -d
--name bluemon
--privileged
-p 8080:8080
-v bluemon-data:/app/data
bluemon
The --privileged flag is required for Bluetooth access in containers.
-
Clone the repository
git clone <repository-url> cd bluemon
-
Install system dependencies (Ubuntu/Debian)
sudo apt-get update sudo apt-get install bluetooth libbluetooth-dev pkg-config gcc
-
Create virtual environment
python3 -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate
-
Install Python dependencies
pip install -r requirements.txt
-
Run the application
python bluemon.py
After installation, start Bluemon:
python bluemon.pyThe service will:
- Initialize and test Bluetooth connectivity
- Create a SQLite database (bluemon.sqlite)
- Start the web interface on http://localhost:8080
- Begin continuous Bluetooth scanning
Navigate to http://localhost:8080 to access the dashboard:
- Summary: View total records, unique devices, and top detected devices
- Configuration: Adjust scan parameters in real-time
- Device Timeline: Interactive Gantt chart showing device presence over time
- Recent Scans: Table of latest device detections
- Database Management: Export data to CSV or clear the database
The service uses a JSON configuration file (config.json) with the following parameters:``` json
{
"scan_duration": 5, // How long each scan lasts (seconds)
"scan_interval": 3, // Time between scans (seconds)
"sleep_duration": 1, // Main loop sleep duration (seconds)
"db_path": "bluemon.sqlite", // SQLite database path
"host": "0.0.0.0", // Web interface bind address
"port": 8080 // Web interface port
}
Configuration can be modified:
- Via the web interface (runtime changes) - by editing config.json directly (requires restart) Using environment variable BLUEMON_CONFIG to specify config file path
Bluemon exposes several REST API endpoints:
GET /api/health - Health check for monitoring
GET /api/summary - Analytics summary
GET /api/recent?limit=N - Recent scan results
GET /api/timeline?hours=N - Timeline data for visualization
GET /api/config - Current configuration
POST /api/config - Update configuration
GET /api/export-csv?hours=N - Export data as CSV
POST /api/clear-data - Clear all scan data
Export scan data in CSV format:
-
Use the web interface "Database Management" section
-
Select time range (1 hour to all time)
-
Click "Download CSV"
-
Or use the API directly (for example):
# Export last 24 hours
curl "http://localhost:8080/api/export-csv?hours=24" -o export.csv
# Export all data
curl "http://localhost:8080/api/export-csv" -o export_all.csvbluemon/
├── bluemon.py # Main application entry point
├── module/
│ ├── bluetooth_scanner.py # Bluetooth scanning logic
│ ├── config.py # Configuration management
│ ├── store.py # SQLite database operations
│ └── web.py # Flask web interface
├── static/
│ └── style.css # Web interface styling
├── requirements.txt # Python dependencies
└── Dockerfile # Container configuration
Key Components
- BluetoothScanner: Handles device discovery using the bleak library
- Store: SQLite database operations and data persistence
- Web Interface: Flask-based dashboard with real-time updates
- Configuration: JSON-based configuration with runtime updates
Running in Development Mode``` bash
pip install -r requirements.txt
PYTHONPATH=. python bluemon.py
The modular architecture makes it easy to extend:
- New scan data fields: Modify BluetoothDevice dataclass and database schema
- Additional visualizations: Add new API endpoints and frontend components
- Custom exporters: Extend the Store class with new export methods
- Integration: Use the API endpoints to integrate with other systems
Common Issues encountered.
- Ensure Bluetooth is enabled: sudo systemctl start bluetooth
- Check adapter status: bluetoothctl show
- Permission denied errors
- Add user to bluetooth group: sudo usermod -a -G bluetooth $USER Or run with sudo (not recommended for production)
- Ensure --privileged flag is used
- Host Bluetooth service must be running
- Check if port 8080 is available
- Verify firewall settings
- Check application logs for binding errors
- Application logs are printed to stdout
- Use docker logs bluemon for containerized deployments
- Enable debug logging by modifying the logging level in bluetooth_scanner.py
- Scan frequency: Higher frequency provides more data but uses more resources
- Database size: Monitor SQLite file size; use CSV export and clear for maintenance
- Memory usage: Long-running instances accumulate scan data in memory
- Concurrent access: SQLite handles multiple readers but single writer
- Web interface has no authentication (design for local/trusted networks)
- SQLite database contains device MAC addresses and names
- Consider network isolation for production deployments
- Regular data exports and cleanup recommended for privacy
- Fork the repository
- Create a feature branch
- Make changes with appropriate tests
- Submit a pull request with clear description
Please ensure:
- Code follows existing style conventions
- New features include appropriate documentation
- Changes are tested on target platforms
When sharing or modifying this code, please maintain attribution to the original authors and include the above license notice.
- Built with bleak for cross-platform Bluetooth LE support
- Web interface powered by Flask
- Production WSGI server via Waitress
- Data persistence with SQLite
- Written in Python 3.12 by Kasp0r
For issues, feature requests, or questions:
- Check the troubleshooting section above
- Search existing issues in the repository
- Create a new issue with detailed information about your environment and problem
