# V-BLACK BLE Simulator A real BLE GATT server in Go that simulates a V-BLACK device using `tinygo.org/x/bluetooth`. ## Platform Support - **Linux**: Requires BlueZ 5.48+. May need `sudo` for BLE access. - **Windows**: Works out of the box with WinRT. - **macOS**: NOT SUPPORTED - CoreBluetooth doesn't allow peripheral mode. ## Building ```bash go build ./cmd/simulator ``` ## Running ```bash # Linux (may require root) sudo ./simulator # Windows simulator.exe ``` ## BLE UUIDs Uses **Nordic UART Service (NUS)** UUIDs - same as real V-BLACK sensors: | Characteristic | UUID | Properties | |----------------|------|------------| | Service | `6e400001-b5a3-f393-e0a9-e50e24dcca9e` | - | | Command (RX) | `6e400002-b5a3-f393-e0a9-e50e24dcca9e` | Write | | Notify (TX) | `6e400003-b5a3-f393-e0a9-e50e24dcca9e` | Read, Notify | ### Flutter Example ```dart const serviceUuid = "6e400001-b5a3-f393-e0a9-e50e24dcca9e"; const commandCharUuid = "6e400002-b5a3-f393-e0a9-e50e24dcca9e"; const notifyCharUuid = "6e400003-b5a3-f393-e0a9-e50e24dcca9e"; ``` ## Commands ### Global Commands | Command | Response | Description | |---------|----------|-------------| | `PROG_ON` | `PROG_MODE: ON` | Enable programming mode | | `PROG_OFF` | `PROG_MODE: OFF` | Exit programming mode | | `RESET` | `INFO: Uscita allarme resettata (BT).` | Reset alarm output | | `CALI` | `--- MODALITA CALIBRAZIONE ATTIVA ---` | Toggle calibration mode | | `FACTORY` | `FACTORY RESET DONE` | Restore factory defaults | ### Write Parameters (requires PROG_ON first) | Command | Range | Default | Description | |---------|-------|---------|-------------| | `W1 ` | 0-2000 | 1200 | Min threshold | | `W2 ` | 0-4095 | 4000 | Max threshold | | `W3 ` | 1-50 | 2 | Pulse count | | `W4 ` | 10-1000 | 40 | Time window (ms) | | `W20 ` | 0-255 | 128 | Gain (wiper) | ### Read Parameters (requires PROG_ON first) | Command | Response | |---------|----------| | `R1` | `PARAM: W1=` | | `R2` | `PARAM: W2=` | | `R20` | `PARAM: W20=` | ## Notifications The simulator sends sensor readings every 500ms: ``` SENSOR:2067 SENSOR:2063 SENSOR:2071 ``` ## Testing with nRF Connect 1. Run the simulator 2. Open nRF Connect app on your phone 3. Scan for "GO_SIMULATOR" 4. Connect to the device 5. Find service `6e400001-...` (Nordic UART Service) 6. Subscribe to notify characteristic `6e400003-...` (NUS TX) 7. You should see `SENSOR:xxxx` every 500ms 8. Write `PROG_ON` to command characteristic `6e400002-...` (NUS RX) 9. You should receive `PROG_MODE: ON` on notify ## Console Output ``` [INFO] BLE Simulator v1.0 [INFO] Advertising as GO_SIMULATOR... [INFO] Waiting for connections... [CONN] Client Connected: AA:BB:CC:DD:EE:FF [RX] Command: PROG_ON [TX] Response: PROG_MODE: ON [TX] Sending: SENSOR:2063 [TX] Sending: SENSOR:2071 [RX] Command: R1 [TX] Response: PARAM: W1=1200 [CONN] Client Disconnected ```