BLE API Reference

Everything a developer needs to talk to the device over Bluetooth Low Energy.

Overview

The OSSM Lite firmware (ESP32, NimBLE stack) exposes a GATT server with four services. It is designed so that a plain web page using the Web Bluetooth API can do everything the official tooling does: control playback, stream positions, configure and provision a device, and update its Wi-Fi credentials.

Transport & connection

PropertyValue
RoleGATT peripheral (server)
Advertised nameThe configured device name (default CYBORGTOP, see Rename)
Advertised servicesOSSM, Legacy, Device Information, Fleshy (scan response enabled)
MTUServer requests a 512-byte MTU exchange on connect, so full state JSON and preset payloads fit in one packet
SecuritySecure Connections pairing flag set; no bonding, PIN or encryption is required for normal use

When is the device visible?

The firmware only advertises while it is at rest on an idle screen (menu.idle, wifi.idle or error.idle) and no client is connected. During boot, homing or active play the radio is invisible, and advertising resumes when the device returns to the menu. In practice: scan while the device is sitting on its menu screen, or shortly after boot.

What happens on disconnect

Safety first: when the last client drops, the device returns to the menu and, if it was moving, waits one second and then ramps speed to zero over two seconds with a sine ease. A reconnecting client always starts from a stopped, menu-state device.

Connecting from a web page

Web Bluetooth needs Chrome or Edge, a secure context (https:// or localhost) and a user gesture. Filtering by the OSSM service UUID is the reliable way to find the device, since its name is user-configurable:

const OSSM_SERVICE = "4f53534d-0000-0000-0000-000000000000";

const device = await navigator.bluetooth.requestDevice({
  filters: [{ services: [OSSM_SERVICE] }],
});

device.addEventListener("gattserverdisconnected", () => {
  console.log("device went away");
});

const server = await device.gatt.connect();
const ossm = await server.getPrimaryService(OSSM_SERVICE);

Value conventions

Fun fact that helps when reading UUID tables: the OSSM UUIDs are hex-encoded ASCII. 4f53534d-436f-6e66-6967-486F6D696E67 decodes to "OSSMConfigHoming":

function decodeUuid(uuid) {
  const bytes = Uint8Array.fromHex(uuid.replaceAll("-", ""));
  return new TextDecoder().decode(bytes);
}
decodeUuid("4f53534d-436f-6e66-6967-486F6D696E67"); // "OSSMConfigHoming"

Service map

ServiceUUIDPurpose
OSSM 4f53534d-0000-0000-0000-000000000000 Modern API: one characteristic per setting, plus configuration/provisioning and Advanced Penetration
Legacy 522b443a-4f53-534d-0001-420badbabe69 Text command channel + state JSON broadcast, kept for older clients
Fleshy 0000ffe0-0000-1000-8000-00805f9b34fb Binary "FTS" position streaming (servo-style payloads)
Device Information 0000180a-0000-1000-8000-00805f9b34fb Manufacturer, model, firmware version (standard SIG service)

Property abbreviations used below: R read, W write (with response), WNR write (no response), N notify, I indicate. Unless noted, every OSSM-service characteristic created by the firmware is R + W + WNR + N.

The command mechanism

The Legacy service exposes a single command characteristic — a line-oriented text protocol. This is the simplest integration path: one write fires one action, and the device tells you whether it worked.

UUID522b443a-4f53-534d-1000-420badbabe69
PropertiesR + W + WNR

Flow

  1. You write a command string (e.g. set:speed:35).
  2. The firmware validates it against the grammar below. Invalid commands are rejected immediately: the command characteristic's value becomes fail:<your command> — read it back to see the rejection.
  3. Valid commands are queued and executed by the state machine within milliseconds. After execution, the Legacy state characteristic value is set to ok:<your command>. This ack is not notified — read the state characteristic to collect it.

The queue is only drained while a client is connected, so commands never execute "offline". Values in set: commands must match (\d|\.)+ — digits and decimal point only, no signs — and must fall in 0–100.

Grammar

go:(strokeEngine|streaming|menu)
set:(max|min|speed|stroke|depth|sensation|buffer|pattern):(\d|\.)+
set:wifi:[^|]+\|.+
stream:(\d|\.)+:\d+

Command reference

CommandEffect
go:menuEmergency-stops motion and returns to the main menu (any unknown go: target also lands here)
go:strokeEngineEnters the Stroke Engine play mode (via the menu selection)
go:streamingEnters Streaming play mode
set:speed:XSets BLE speed 0–100 (percent). This is the speed source used while playing; the physical knob can optionally act as a limit (see Speed Knob)
set:max:XSets max position (depth) 1–100
set:min:XSets min position 0–99; stroke is recomputed as max − min
set:depth:XLegacy alias: sets max = X (1–100) and shifts min = X − stroke
set:stroke:XLegacy: sets stroke length, min = max − X
set:sensation:XSensation 0–100 — a pattern-specific parameter (see pattern table)
set:buffer:XLatency-compensation buffer 0–100 (a number; distinct from the boolean Buffer toggle)
set:pattern:XSelects stroke pattern by index (taken modulo the pattern count, 14)
set:wifi:SSID|PASSWORDAccepted by the grammar but ignored on the command channel — Wi-Fi provisioning is done through the dedicated WiFi characteristic
stream:POS:TIMEQueues a move to position POS (0–100) over TIME milliseconds; switches the device into Streaming mode. Send a sequence of these to puppet the rail

Example

const LEGACY_SERVICE = "522b443a-4f53-534d-0001-420badbabe69";
const COMMAND_UUID   = "522b443a-4f53-534d-1000-420badbabe69";
const STATE_UUID     = "522b443a-4f53-534d-2000-420badbabe69";

const encoder = new TextEncoder();
const decoder = new TextDecoder();

const legacy  = await server.getPrimaryService(LEGACY_SERVICE);
const command = await legacy.getCharacteristic(COMMAND_UUID);
const state   = await legacy.getCharacteristic(STATE_UUID);

// Fire a command, then read the ack.
await command.writeValue(encoder.encode("set:speed:35"));
console.log(decoder.decode(await state.readValue())); // "ok:set:speed:35"

// A bad command is rejected into the command characteristic itself.
await command.writeValue(encoder.encode("set:speed:banana"));
console.log(decoder.decode(await command.readValue())); // "fail:set:speed:banana"

OSSM service — runtime characteristics

These are the play-time controls on the OSSM service (4f53534d-0000-0000-0000-000000000000). All values are strings; positions and speeds are percentages of the measured rail (0–100). Unless a row says otherwise, properties are R + W + WNR + N, and a read returns the current live value.

CharacteristicUUIDWriteRead / notify
Speed 4f53534d-436f-6d6d-6f6e-005370656564 Float 0–100 → BLE speed setpoint Current effective speed (may differ while ramping or knob-limited)
Max Depth 4f53534d-436f-6d6d-6f6e-4d6178446570 Float 0–100; forced to at least min + 1 Current max position
Min Depth 4f53534d-436f-6d6d-6f6e-4d696e446570 Float 0–100; forced to at most max − 1 Current min position
Sensation 4f53534d-456e-6769-6e65-536174696f6e Float 0–100 Current sensation
Pattern 4f53534d-456e-6769-6e65-50617465726e Integer pattern index (mod 14). Side effect: switches the device into Stroke Engine mode Current pattern index. Reading also starts Stroke Engine mode
Pattern List (R + W only) 4f53534d-456e-6769-6e65-5061744c7374 Integer index → value becomes "Name:Description" (empty string if out of range) Before any write: the pattern count ("14"). After: the last Name:Description
Stream 4f53534d-436f-6d6d-6f6e-53747265616d "POS:TIME" (position 0–100, milliseconds). Side effect: switches into Streaming mode and queues the move "Ready" — and starting Streaming mode
Buffer (latency compensation toggle) 522b443a-4f53-534d-1030-420badbabe69 ⚠ see quirks Boolean — enable/disable latency compensation for streamed positions (not persisted) Boolean
Offset (R + N only) 4f53534d-436f-6d6d-6f6e-4f6666736574 — (read-only) The current latency buffer number (the value set:buffer:X writes)
State 4f53534d-5374-6174-654d-616368696e65 — (read-only, notify) Current state-machine name, e.g. "strokeEngine.idle". Initial value "ok:boot". See State & notifications

OSSM service — configuration characteristics

These are the provisioning settings — everything a setup tool needs to commission a fresh device. Values are persisted to flash (NVS) unless noted. All are R + W + WNR + N except WiFi (R + W). A read always returns the currently stored value.

SettingUUIDValueDefaultNotes
Device name 4f53534d-436f-6e66-6967-52656e616D65 String, truncated to 8 chars CYBORGTOP Also the BLE advertised name (applies after restart). Rate-limited: writes within 1 s of the last are dropped
Homing type 4f53534d-436f-6e66-6967-486F6D696E67 Integer enum: 0 None, 1 Default, 2 SingleSided, 3 DoubleTap 2 How the rail finds its zero position
Rail length 4f53534d-436f-6e66-6967-4c656e677468 Float, mm; clamped to 50–500 (or the current value if already longer) 400 Physical travel of the rail
Re-home between modes 4f53534d-436f-6e66-6967-5265486F6D65 Boolean false Force a homing run when switching play modes
Invert direction 4f53534d-436f-6e66-6967-496e76657274 Boolean false Flips rail orientation (motor mounting)
Max acceleration 4f53534d-436f-6e66-6967-4d414343454c Float, mm/s² 10000 Not clamped — write sane values
Motor max RPM 4f53534d-436f-6e66-6967-4d415852504d Float 300 Motor/belt geometry. Steps-per-mm is derived as stepsPerRev / (pulleyTeeth × beltPitch); max belt speed as rpm / 60 × pulleyTeeth × beltPitch
Steps per revolution 4f53534d-436f-6e66-6967-535445505052 Float 800
Pulley teeth 4f53534d-436f-6e66-6967-50554c4c4559 Float 30
Belt pitch 4f53534d-436f-6e66-6967-425049544348 Float, mm 5
Sensor limit 4f53534d-436f-6e66-6967-53656e736f72 Float 2.5 Homing sensor trigger distance
Speed curve 4f53534d-436f-6e66-6967-537064437276 Float exponent 0.8 Maps the 0–100 speed percentage onto actual motor speed: (1 − (1 − x)^e)^(1/e)
Homing speed 4f53534d-436f-6e66-6967-537064486f6d Float, clamped 10–40 25 Speed used while searching for the home sensor
GPIO 4f53534d-436f-6e66-6967-20204750494f "N:high" / "N:low" (also 1/0), N ∈ 1–3 — Auxiliary output pins; see below
WiFi 4f53534d-436f-6e66-6967-202057694669 "set:wifi:SSID|PASSWORD" — Credentials + status; see below

GPIO details

WiFi details

Advanced Penetration characteristics

"Advanced Penetration" (AP) is the layered motion mode: per-direction depth/speed/acceleration controls plus a step-based modifier, with named presets stored in flash. It lives on the OSSM service as four characteristics. Writing to Control automatically switches the device into AP mode.

CharacteristicUUIDPropertiesPurpose
Control 4f53534d-6164-7661-6e63-6564636f6e74 R + W + WNR Send value changes
Status 4f53534d-6164-7661-6e63-656473746174 R + N Current values, notified on change while in AP mode
Config 4f53534d-6164-7661-6e63-6564636f6e66 R Self-describing list of control names and min/max ranges
Presets 4f53534d-6164-7661-6e63-656470727374 R + W Save / load / delete named presets

Control grammar

A write is a list of comma-terminated segments. Each segment is either <id>:<value>, or <id>:<modifierId>:<value>,. The trailing comma is what tells the firmware the segment is complete — text after the last comma is kept in a buffer and prepended to your next write, so you can even split segments across packets. Values are clamped to the control's range. If a write contains no comma at all, it fails and the characteristic value becomes "fail:<cmd>".

Base idControlRangeDefault
0Max Depth0–10010
1Min Depth0–1000
2In Speed1–100100
3Out Speed1–100100
4In Accel0–10040
5Out Accel0–10040
6Speed (master)0–1000
Modifier idModifierRangeDefault
0Amplitude0–100100 (off)
1Steps to Min1–251
2Steps at Min0–250
3Steps to Max1–251
4Steps at Max0–250
5Offset0–1000

Modifiers attach to a base control and vary it over a cycle of strokes (amplitude < 100 with a nonzero step count means "active"). Examples:

"6:35,"          // master speed 35%
"0:80,1:10,"     // max depth 80, min depth 10
"0:0:50,"        // Max Depth modifier: amplitude 50
"0:1:4,0:2:2,"   // Max Depth modifier: 4 steps down to min, pause 2 strokes

Status format (read / notify)

Seven comma-separated values, always in this order: maxDepth,minDepth,inSpeed,outSpeed,inAccel,outAccel,speed. If a control has an active modifier, its value is followed by six more colon-separated numbers: amplitude:stepsToMin:stepsAtMin:stepsToMax:stepsAtMax:offset.

"10,0,100,100,40,40,0"                  // plain
"15:50:2:1:2:1:0,0,100,100,40,40,35"    // max depth 15 with active modifier, speed 35

Config format (read-only)

The same seven controls, but self-describing: Name(min/max) per control, with modifier ranges appended to Max Depth. Handy for building UIs without hard-coding ranges:

"Max Depth(0/100):Amplitude(0/100):Steps to Min(1/25):Steps at Min(0/25):Steps to Max(1/25):Steps at Max(0/25):Offset(0/100),Min Depth(0/100),In Speed(1/100),Out Speed(1/100),In Accel(0/100),Out Accel(0/100),Speed(0/100)"

Presets

A read returns the comma-separated preset name list, e.g. "Simple,Teasing,Pounding,Robo,…,Knot (50%),". A write is a one-character opcode plus a name:

WriteEffect
>MyNameSave the current settings as preset MyName. Empty name (>) auto-names it "User Pattern N"
<MyNameDelete the preset
:MyNameLoad the preset (its payload is fed through the Control grammar)
^Factory-reset all presets back to the built-in set

Legacy service characteristics

Service UUID 522b443a-4f53-534d-0001-420badbabe69. Kept for backwards compatibility with older clients — new integrations should prefer the OSSM service, but the command/state pair is still the nicest way to drive the device with one characteristic.

CharacteristicUUIDPropertiesBehaviour
Command 522b443a-4f53-534d-1000-420badbabe69 R + W + WNR Text command channel — see The command mechanism
State 522b443a-4f53-534d-2000-420badbabe69 R + N Initial value "ok:boot". Notified with the full state JSON whenever the device state changes; set to "ok:<cmd>" after each queued command (not notified — read it)
Speed Knob 522b443a-4f53-534d-1010-420badbabe69 R + W + WNR + N Boolean, not persisted (resets to false on boot). When true, the physical speed knob acts as a limit on BLE speed. Invalid writes → "error:invalid_value"
Buffer 522b443a-4f53-534d-1030-420badbabe69 R + W + WNR + N Boolean latency-compensation toggle — same handler and same UUID as the OSSM-service Buffer characteristic (see quirks)
Patterns 522b443a-4f53-534d-3000-420badbabe69 R Static JSON array of all stroke patterns: [{"name":"Simple Stroke","idx":0},…]
Pattern Data 522b443a-4f53-534d-3010-420badbabe69 R + W Write a pattern index (wraps with modulo) → the value becomes that pattern's description; read returns the last description. Does not change the active pattern

Fleshy service (binary streaming)

A compatibility path for clients that speak the old servo-style "FTS" binary protocol (e.g. Funscript-style senders). Service 0000ffe0-0000-1000-8000-00805f9b34fb, characteristic 0000ffe1-0000-1000-8000-00805f9b34fb, properties R + W + WNR + N + I. This is the only binary characteristic in the API.

ByteMeaning
0Position, 0–180 "servo degrees". Converted internally to a percentage: byte / 1.8
1–2Duration in milliseconds, uint16 big-endian

Writes shorter than 3 bytes are ignored. Each write enqueues a timed move on the same queue the stream: command uses, so the device behaves like Streaming mode.

// Move to 50% (90 "degrees") over 500 ms:
const fleshy = await server.getPrimaryService("0000ffe0-0000-1000-8000-00805f9b34fb");
const fts = await fleshy.getCharacteristic("0000ffe1-0000-1000-8000-00805f9b34fb");
await fts.writeValue(new Uint8Array([90, 500 >> 8, 500 & 0xff]));

Device Information service

Standard SIG service 0x180A, all characteristics read-only:

CharacteristicUUIDValue
Manufacturer Name0x2A29"Kinky Makers"
Model Number0x2A24"OSSM Lite"
Firmware Version0x2A26Semver string, e.g. "1.6.2" — check this before relying on any behaviour documented here
const info = await server.getPrimaryService("0000180a-0000-1000-8000-00805f9b34fb");
const fw = await info.getCharacteristic("00002a26-0000-1000-8000-00805f9b34fb").readValue();
console.log(decoder.decode(fw)); // "1.6.2"

State & notifications

While a client is connected, the firmware polls its own state roughly every 100 ms and builds a fingerprint from: state-machine name, speed, min position, max position, sensation and pattern (numbers truncated to integers). When the fingerprint changes, it notifies:

State JSON payload (single packet thanks to the 512-byte MTU):

{
  "timestamp": 123456,        // ms since boot
  "state": "strokeEngine.idle",
  "speed": 35.0,              // effective speed, %
  "minPosition": 10.0,        // %
  "maxPosition": 80.0,        // %
  "depth": 80.0,              // alias of maxPosition
  "stroke": 70.0,             // maxPosition - minPosition
  "sensation": 50.0,          // %
  "buffer": 0.0,              // latency buffer number
  "pattern": 3                // pattern index
}

State machine names

Useful for gating UI (e.g. only show play controls when homed). Dotted names are sub-states:

Bootidle, hello, homing, homing.run, measure.run
Menumenu, menu.idle
Stroke EnginestrokeEngine, strokeEngine.preflight, strokeEngine.idle, strokeEngine.stopping, strokeEngine.pattern, strokeEngine.speedCheck, usercalibration
Streamingstreaming, streaming.preflight, streaming.idle
Advanced PenetrationadvancedPenetration, advancedPenetration.preflight, advancedPenetration.idle, advancedPenetration.presets
Wi-Fi / errorwifi, wifi.idle, error, error.idle, restart

Subscribing

const legacy = await server.getPrimaryService("522b443a-4f53-534d-0001-420badbabe69");
const state = await legacy.getCharacteristic("522b443a-4f53-534d-2000-420badbabe69");

state.addEventListener("characteristicvaluechanged", (event) => {
  const text = decoder.decode(event.target.value);
  if (text.startsWith("{")) {
    console.log("state:", JSON.parse(text));
  } else {
    console.log("command ack:", text); // "ok:…" after a queued command
  }
});
await state.startNotifications();

Stroke pattern reference

The 14 built-in StrokeEngine patterns. Use the index with set:pattern:X, the Pattern characteristic, or Pattern Data. The meaning of sensation (0–100) is per pattern:

IdxNameDescription (sensation effect)
0Simple StrokeAcceleration, coasting, deceleration equally split; sensation adds randomness in stroke
1Teasing PoundingSpeed shifts with sensation; balances faster strokes
2Robo StrokeSensation varies acceleration; from robotic to gradual
3Half'n'HalfFull and half depth strokes alternate; sensation affects speed
4Half'n'OutFull and half depth strokes alternate on pull out; sensation affects speed
5DeeperStroke depth increases per cycle; sensation sets count
6Stop'n'GoPauses between strokes; sensation adjusts length
7InsistStroke length decreases per cycle to set depth; sensation sets count
8Progressive StrokeStrokes are made of substrokes controlled by sensation
9Knot StrokeSplits stroke into three parts by sensation
10Slap StrokeSlapping style stroke with a delay determined by sensation
11Random StrokeRandom stroke; sensation controls maximum randomness from current location
12Go to PointMoves to a point between depth and stroke based on sensation
13Stroke CalibrationCalibration entry point — never drives the rail; used by the on-device min/max calibration flow

Prefer fetching this at runtime over hard-coding: the Legacy Patterns characteristic returns the names as JSON, and the OSSM Pattern List characteristic returns "Name:Description" per index.

Quirks & gotchas

Things that will bite you if you don't know them:

  1. The OSSM-service Buffer characteristic has a Legacy UUID. A duplicated #define BUFFER_UUID in the firmware headers means the OSSM service's buffer toggle is created with 522b443a-4f53-534d-1030-420badbabe69 — the intended 4f53534d-436f-6d6d-6f6e-427566666572 is never registered. Both services expose a characteristic with that UUID, backed by the same setting. (Older docs referencing the …427566666572 UUID are stale.)
  2. Two different "buffers". The Buffer characteristic is a boolean (latency compensation on/off); set:buffer:X and the Offset characteristic deal with the number used for that compensation.
  3. Offset returns the buffer number. Reading Offset gives the latency-buffer value set by set:buffer:X, not a positional offset.
  4. Reads can have side effects. Reading Pattern or Stream switches the device into Stroke Engine / Streaming mode respectively. Writing AP Control switches into Advanced Penetration mode.
  5. Acks are not notified. ok:…/fail:…/error:… responses are written into characteristic values silently — you must read the characteristic back.
  6. Rate limits. Device-name writes and AP preset writes are ignored if they arrive less than a second after the previous one.
  7. Command numbers are unsigned. The command grammar accepts digits and dots only — no negative numbers, no exponents. Values are expected in 0–100.
  8. Advertising pauses while busy. You can't connect (or reconnect) while the device is homing or playing — it must be on an idle screen. Plan provisioning flows accordingly.
  9. Notifications are change-driven. There's no periodic telemetry other than on state change; poll with reads if you need continuous values (e.g. speed while ramping).
  10. Config writes persist immediately. Every configuration characteristic write goes straight to flash — avoid hammering them from sliders; write on release.

Putting it together: a minimal provisioning session

// 1. Connect (must be inside a user gesture, e.g. a button click)
const device = await navigator.bluetooth.requestDevice({
  filters: [{ services: ["4f53534d-0000-0000-0000-000000000000"] }],
});
const server = await device.gatt.connect();
const ossm = await server.getPrimaryService("4f53534d-0000-0000-0000-000000000000");

const encoder = new TextEncoder();
const decoder = new TextDecoder();

// Small helper: write a string, read back whatever the device stored
async function writeAndCheck(uuid, text) {
  const c = await ossm.getCharacteristic(uuid);
  await c.writeValue(encoder.encode(text));
  return decoder.decode(await c.readValue());
}

// 2. Name the device (8 chars max, 1 write/second)
await writeAndCheck("4f53534d-436f-6e66-6967-52656e616d65", "MYOSSM");

// 3. Motor geometry for this build
await writeAndCheck("4f53534d-436f-6e66-6967-4d415852504d", "300");
await writeAndCheck("4f53534d-436f-6e66-6967-535445505052", "800");

// 4. Rail + homing
await writeAndCheck("4f53534d-436f-6e66-6967-4c656e677468", "400");
await writeAndCheck("4f53534d-436f-6e66-6967-486f6d696e67", "2"); // SingleSided

// 5. Wi-Fi for OTA updates (slow — blocks up to ~10 s while it connects)
console.log(await writeAndCheck(
  "4f53534d-436f-6e66-6967-202057694669",
  "set:wifi:MyNetwork|supersecret",
)); // "ok:wifi:connected"