Skip to content

What a driver needs

Bench hardware only. Everything here can start or change insulin delivery. Use it only with pump hardware that is not connected to any living subject. See bench testing.

This section describes what any looping driver needs from the Twiist pump: the session, the crypto, the status it must read, the alarms it must handle, set-up and recovery, delivery, history, the commands and a state model. It describes behaviour observed on one pump on an off-body saline bench; nothing here is manufacturer documentation. Field names are working names.

A real driver for AndroidAPS is being written against this reference; where it stands is on Real looping drivers.

Verification states and the TBD convention. Every claim in this section carries one of the tags below. Where something is genuinely unknown it is marked TBD with a one-line note of what is missing, so it is always clear what is known and where the gap is.

Tag Meaning
✅ Verified Exercised live on an off-body saline bench (one pump unit) with the expected result.
🟡 Partial Works, but the full range / all variants / durable effect is not yet mapped.
🧪 Identified Opcode and payload shape known; not yet accepted on the bench.
⛔ TBD Not solved. The adjacent note says exactly what is missing.

Pages in this section: BLE and session · Crypto and transport · Status fields · Alarms, alerts and NACKs · Setup and recovery · Delivery · History and log records · Command catalogue · State model. Open questions: Status.

Section numbers (§0–§9) are kept across the pages: §0 this page, §1–2 BLE and session, §3–4 crypto and transport, §5 status fields, §6 setup and recovery, §7 delivery, §8 history, §9 command catalogue.

What a driver must hold before it starts

  • The LTSS — a 16- or 32-byte per-pump registration secret. Every command frame is sealed with keys derived from it (§3). Minting one is ⛔ TBD: it is issued by the vendor's official app/cloud when the pump is registered. A driver consumes an LTSS already held for a pump you own; it cannot register a fresh pump. This is the single headline gap for every driver, and the reason none of them can be used beyond the bench by anyone else yet.
  • The 6-digit label PIN printed on the pump — the BLE passkey for bonding (§1).

Tested firmware

TwiistOff is tested on one pump firmware only: RIS messages 13.76, events 14.32. A pump on older or newer firmware may behave differently, and that could break TwiistOff in ways it cannot detect. New pumps may ship on older firmware, which the manufacturer's app updates when it pairs the pump. TwiistOff does not update pump firmware. On any other firmware it shows an untested pump firmware warning on the phone and in GET /status, GET /pump/ready, GET /pump/state and GET /pump/conditions; it still reads status.

A driver should read the version block (e5332001, Status fields) after every arm and treat any other firmware as untested. Every command, payload and status field in this reference was observed on 13.76 / 14.32. For the commands TwiistOff holds back below a minimum version, see Firmware gates.

What a driver needs, layer by layer

Each layer depends on the ones above it.

  1. BLE and bond (§1). Scan by name/company-ID 0x026B (the address is a rotating RPA — never lock to it), connect, negotiate ATT MTU 247 (required; without it the pump never streams), and bond with LE Secure Connections Passkey Entry using the label PIN.
  2. Crypto (§3). HKDF-SHA256 (RFC 5869), AES-CCM (RFC 3610, 16-byte tag), HMAC-SHA256 and CRC-16/MCRF4XX. appKey and risSigKey are derived from the LTSS and the session salt. The info strings are constants given in §3 — they are part of the spec.
  3. An armed session (§2). Read the salt and start sequence, write 0x01 to arm, and treat the session as armed only after a pumpStatus frame sealed with the new keys decrypts.
  4. Transport numbering (§3). The shared 8-byte packet counter and the 4-byte message seq, and the Simple-vs-Therapy split (§4): Therapy commands carry a 2-byte therapy number seeded from pumpStatus[12:13] and advanced by each accepted response (bolus is the exception; a NACK also rotates it — §4). Every reply is matched to its request by seq + opcode, and a therapy command is never resent blindly.
  5. Reboots and re-keys (§2.1). A pump reboot or a session re-key silently stops the old session answering commands; a driver detects it, re-arms on the same link, and proves the path with a read-only read before any therapy command.
  6. Status (§5). pumpStatus (0x0200) is the pump's only "screen". A driver decodes it before it sends anything that changes state — notably the closed-loop flag and the configuration state (the real delivery gate, §6).
  7. Alarms, alerts and NACKs (Alarms, alerts and NACKs). Alarms, alerts and notices arrive as bits in pumpStatus; refusals arrive as NACK codes. A driver shows each one and knows which recovery it needs.
  8. Settings, set-up and recovery (§6). Delivery is gated by the pump's configuration state, not by an in-session verifyTherapySettings; a battery-reset pump must have its therapy settings re-announced before it will deliver. Cassette set-up and alarm recovery are multi-step sequences.
  9. Delivery (§7). For an automated-delivery driver the useful primitive is temporaryOverrideBasal 0x8102 — an absolute U/h temporary rate, exactly the temp-basal form such apps command, with no percent math. Bolus is 0x8400; every delivery command has a stop path, known before it is sent.
  10. History (§8) for reconciliation: the pump's own log of what it delivered and raised.
  11. Commands (§9): the full opcode list with per-command verification states and firmware gates.
  12. A state model (State model): one answer to can I send a therapy command now, and will the pump act on it? Drivers fail closed: when the answer is not a clear yes, nothing is sent.

The REST bridge (REST API) is a reference implementation of all of the above: every route maps to one of these layers and shows the exact bytes on the wire, so it doubles as an executable spec a driver can be compared against.

Where the guessing still is: the ⛔ TBD items are collected on the Status page and tagged inline throughout. The big ones are LTSS provisioning (above) and whether a written replacement blob write from TwiistOff is adopted on the bench (the write format itself is known).