# cloud-printer-base-system **Repository Path**: huahua522/cloud-printer-base-system ## Basic Information - **Project Name**: cloud-printer-base-system - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-08-23 - **Last Updated**: 2025-08-23 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Cloud Printer BLE GATT Server BLE GATT Server implementation for Cloud Printer WiFi configuration via WeChat mini-program. ## Features - BLE advertisement with customizable device name - GATT service for WiFi configuration - JSON-based command protocol - Automatic data fragmentation/reassembly for large messages - Connection management with timeout protection - MTU negotiation support (20-512 bytes) - systemd service integration ## Requirements - Linux system with BlueZ 5.50+ - Python 3.8+ - DBus service running - Bluetooth hardware ## Installation 1. Install system dependencies: ```bash sudo apt-get update sudo apt-get install python3-dev python3-pip sudo apt-get install bluetooth bluez libbluetooth-dev sudo apt-get install libgirepository1.0-dev gcc sudo apt-get install python3-gi python3-gi-cairo gir1.2-gtk-3.0 ``` 2. Install Python packages: ```bash pip3 install -r requirements.txt ``` 3. Install the package: ```bash pip3 install -e . ``` ## Configuration Edit `config/ble_config.yaml` to customize: - Advertisement settings - Connection limits and timeouts - MTU settings - Performance limits - Logging configuration ## Usage ### Running directly: ```bash python3 -m src.ble.gatt_server ``` ### Using systemd service: 1. Copy service file: ```bash sudo cp systemd/cloud-printer-ble.service /etc/systemd/system/ ``` 2. Reload systemd and start service: ```bash sudo systemctl daemon-reload sudo systemctl enable cloud-printer-ble sudo systemctl start cloud-printer-ble ``` 3. Check service status: ```bash sudo systemctl status cloud-printer-ble ``` ## Testing Run unit tests: ```bash python -m pytest tests/ -v ``` Run with coverage: ```bash python -m pytest tests/ --cov=src --cov-report=html ``` ## Protocol ### Commands 1. **Ping** ```json Request: {"cmd": "ping"} Response: {"result": "pong", "device_id": "XXXX", "timestamp": "2025-01-06T10:00:00"} ``` 2. **Get Info** ```json Request: {"cmd": "get_info"} Response: { "result": "success", "info": { "device_id": "XXXX", "mtu": 185, "protocol_version": "1.0", "capabilities": ["wifi_config", "fragmentation"] } } ``` 3. **Set MTU** ```json Request: {"cmd": "set_mtu", "mtu": 185} Response: {"result": "success", "mtu": 185} ``` ## Troubleshooting ### Permission Issues Ensure the service user is in the bluetooth group: ```bash sudo usermod -a -G bluetooth $USER ``` ### Adapter Not Found Check Bluetooth status: ```bash sudo systemctl status bluetooth bluetoothctl show ``` ### DBus Connection Failed Verify DBus is running: ```bash sudo systemctl status dbus ``` ### Enable Debug Logging Set debug mode in config: ```yaml debug: enabled: true bluez_debug: true ``` ## Architecture ``` ┌─────────────────────────────────┐ │ WeChat Mini-Program │ └──────────┬──────────────────────┘ │ BLE ┌──────────▼──────────────────────┐ │ BLE GATT Server │ │ ┌────────────────────────┐ │ │ │ Connection Manager │ │ │ └────────────────────────┘ │ │ ┌────────────────────────┐ │ │ │ Protocol Handler │ │ │ └────────────────────────┘ │ │ ┌────────────────────────┐ │ │ │ GATT Service/Chars │ │ │ └────────────────────────┘ │ └──────────┬──────────────────────┘ │ DBus ┌──────────▼──────────────────────┐ │ BlueZ Service │ └─────────────────────────────────┘ ``` ## License MIT