# OhMiBod Device Protocol

> Integration documentation for OhMiBod interactive devices.

**Connection:** Bluetooth Low Energy (BLE) **App Integration:** OhMiBod Remote
app

---

## Overview

OhMiBod devices feature Bluetooth connectivity and music mode support. They can
respond to ambient sound or be controlled directly via the app/API.

### Supported Devices

| Device     | Type     | Features                    |
| ---------- | -------- | --------------------------- |
| Esca 2     | Vibrator | App-controlled, wearable    |
| Lovelife   | Vibrator | Basic vibration             |
| blueMotion | Vibrator | Multiple motors             |
| Club Vibe  | Vibrator | Music mode                  |
| Fuse       | Vibrator | Dual motors (Kiiroo collab) |

---

## Connection

### BLE Characteristics

OhMiBod devices use standard BLE GATT profile.

```typescript
const OHMIBOD_SERVICE_UUID = '0000fff0-0000-1000-8000-00805f9b34fb';
const OHMIBOD_WRITE_UUID = '0000fff2-0000-1000-8000-00805f9b34fb';
const OHMIBOD_READ_UUID = '0000fff1-0000-1000-8000-00805f9b34fb';
```

### Discovery

```typescript
async function discoverDevices(): Promise<BluetoothDevice[]> {
  const device = await navigator.bluetooth.requestDevice({
    filters: [{ services: [OHMIBOD_SERVICE_UUID] }],
  });
  return [device];
}
```

---

## Commands

### Vibration Control

```typescript
// Command format: [0x00, intensity]
// intensity: 0-255

function createVibrationCommand(intensity: number): Uint8Array {
  return new Uint8Array([0x00, Math.min(255, Math.max(0, intensity))]);
}
```

### Music Mode

```typescript
// Enable music mode: [0x01, sensitivity]
// sensitivity: 0-100

function createMusicModeCommand(sensitivity: number): Uint8Array {
  return new Uint8Array([0x01, Math.min(100, Math.max(0, sensitivity))]);
}
```

---

## Aphrodite Integration

```typescript
// libs/aphrodite/devices/src/ohmibod/service.ts
export class OhMiBodService extends EventEmitter {
  private devices: Map<string, BluetoothDevice> = new Map();
  private characteristics: Map<string, BluetoothRemoteGATTCharacteristic> =
    new Map();

  async connect(deviceId: string): Promise<void> {
    const device = await navigator.bluetooth.requestDevice({
      filters: [{ services: [OHMIBOD_SERVICE_UUID] }],
    });

    const server = await device.gatt?.connect();
    const service = await server?.getPrimaryService(OHMIBOD_SERVICE_UUID);
    const writeChar = await service?.getCharacteristic(OHMIBOD_WRITE_UUID);
    const readChar = await service?.getCharacteristic(OHMIBOD_READ_UUID);

    this.devices.set(deviceId, device);
    this.characteristics.set(deviceId, writeChar!);

    // Listen for battery updates
    await readChar?.startNotifications();
    readChar?.addEventListener('characteristicvaluechanged', (event) => {
      const value = (event.target as BluetoothRemoteGATTCharacteristic).value;
      const battery = value?.getUint8(0);
      this.emit('ohmibod.battery.updated', { deviceId, battery });
    });

    this.emit('ohmibod.device.connected', { deviceId });
  }

  async vibrate(deviceId: string, intensity: number): Promise<void> {
    const char = this.characteristics.get(deviceId);
    if (!char) throw new Error('Device not connected');

    const command = new Uint8Array([0x00, Math.round((intensity / 100) * 255)]);
    await char.writeValue(command);
    this.emit('ohmibod.vibration.sent', { deviceId, intensity });
  }

  async enableMusicMode(deviceId: string, sensitivity: number): Promise<void> {
    const char = this.characteristics.get(deviceId);
    if (!char) throw new Error('Device not connected');

    const command = new Uint8Array([0x01, sensitivity]);
    await char.writeValue(command);
  }

  async stop(deviceId: string): Promise<void> {
    await this.vibrate(deviceId, 0);
  }

  async disconnect(deviceId: string): Promise<void> {
    const device = this.devices.get(deviceId);
    device?.gatt?.disconnect();
    this.devices.delete(deviceId);
    this.characteristics.delete(deviceId);
    this.emit('ohmibod.device.disconnected', { deviceId });
  }
}
```

---

## Document History

| Date       | Version | Changes                       |
| ---------- | ------- | ----------------------------- |
| 2026-01-18 | 1.0.0   | Initial OhMiBod Protocol docs |
