This system automatically connects new web app users to the Bluetooth mesh network when they register.
Web App User Registration → Flask Backend → Client Manager → Bluetooth Mesh (Odin)
- Purpose: Manages multiple Bluetooth client connections
- Function: Automatically connects new users to Odin (D8:3A:DD:03:1E:77)
- API Port: 8001
- Features:
- Polls backend for new users every 10 seconds
- Creates individual MeshClient instances per user
- Handles connection lifecycle and error recovery
- Provides REST API for manual control
- New Endpoints:
GET /api/bluetooth/manager/status- Check client manager statusPOST /api/bluetooth/manager/connect/<user_id>- Manual user connectionPOST /api/bluetooth/manager/disconnect/<user_id>- Manual user disconnectionPOST /api/bluetooth/send- Send messages via Bluetooth mesh
- Auto-Connection: Automatically triggers Bluetooth connection when users register
- When a user registers in the web app, the system automatically:
- Creates user account in Flask backend
- Sends connection request to Client Manager
- Client Manager creates new MeshClient instance
- Connects user to Odin Bluetooth node
- Performs initial user scan
# Start the entire system
./start_bluetooth_system.sh# Terminal 1: Start Flask Backend
python3 blueQ-backend.py
# Terminal 2: Start Client Manager
cd web_application
python3 client_manager.py D8:3A:DD:03:1E:77 http://localhost:5000 8001# Custom Odin MAC address
python3 client_manager.py YOUR_ODIN_MAC http://localhost:5000 8001
# Custom backend URL and API port
python3 client_manager.py D8:3A:DD:03:1E:77 http://your-backend:5000 8002GET /api/status- Get status of all connectionsPOST /api/connect- Connect a user (JSON:{user_id, user_name})POST /api/disconnect- Disconnect a user (JSON:{user_id})POST /api/send- Send message (JSON:{user_id, destination, message})
GET /api/bluetooth/manager/status- Proxy to client manager statusPOST /api/bluetooth/manager/connect/<user_id>- Connect specific userPOST /api/bluetooth/send- Send Bluetooth message
- Odin MAC:
D8:3A:DD:03:1E:77 - Backend URL:
http://localhost:5000 - Client Manager Port:
8001 - Polling Interval: 10 seconds
- Connection Timeout: 10 seconds
You can override defaults via command line arguments:
python3 client_manager.py [ODIN_MAC] [BACKEND_URL] [API_PORT]- New users are automatically connected to Bluetooth mesh on registration
- No manual intervention required
- Immediate Bluetooth scan after connection
- Automatic reconnection attempts
- Graceful handling of Bluetooth connection failures
- Cleanup of disconnected users
- Real-time status via API endpoints
- Health checks and connection monitoring
- Detailed logging for debugging
- Manual connect/disconnect via API
- Send messages on behalf of users
- View connection status and statistics
- Check if port 8001 is available
- Verify Odin MAC address is correct
- Ensure Flask backend is running
- Check client manager logs
- Verify backend can reach client manager on port 8001
- Check Bluetooth permissions and availability
- Verify Odin node is powered on and discoverable
- Check Bluetooth adapter status:
hciconfig - Ensure proper Bluetooth permissions:
sudo usermod -a -G bluetooth $USER
- Check if services are running:
ps aux | grep python - Verify ports are not blocked by firewall
- Check network connectivity between components
- Extend
BluetoothClientManagerclass - Add new API endpoints in
setup_api() - Update Flask backend proxy endpoints if needed
- Test with manual API calls
# Check client manager status
curl http://localhost:8001/api/status
# Manually connect a user
curl -X POST http://localhost:8001/api/connect \
-H "Content-Type: application/json" \
-d '{"user_id": "test123", "user_name": "TestUser"}'
# Send a test message
curl -X POST http://localhost:8001/api/send \
-H "Content-Type: application/json" \
-d '{"user_id": "test123", "destination": "broadcast", "message": "Hello World"}'- User registration automatically triggers connection
- Contact refresh includes Bluetooth users
- Status indicators show connection health
- Each user gets individual connection to Odin
- Messages are properly formatted with user identity
- Automatic user discovery and synchronization
- Seamless API between web and Bluetooth layers
- Unified user management across platforms
- Real-time status synchronization