Bench-testing TwiistOff on your own pump¶
This is the onboarding doc if you have (or can get) a Twiist pump and want to help validate the protocol. TwiistOff is a first proof-of-concept for local bench testing and protocol research. Multi-unit confirmation is what turns "works on one pump" into "works on the pump."
Read the safety disclaimer in the README first. Nothing below overrides it.
1. Hard rules¶
- Off-body only. The pump must not be connected to any human being or animal — no infusion set or cannula attached to a body, nothing worn. Saline (or water) in the cassette, never insulin, for any delivery test.
- You own the hardware. Bond only to a pump you control. Use the PIN printed on that pump's label. Do not attempt to talk to anyone else's pump.
- Fail closed. If a result is surprising, stop and capture it. Do not "just try the next command" on a live delivery path until you understand the last one.
- No clinical use. TwiistOff is experimental research software. It is not a medical device and must not be used for therapy.
- Report facts, not guesses. A session export with hex beats a paraphrase. See §6.
2. What you need¶
| Item | Notes |
|---|---|
| A Twiist pump you own | Charged battery. For first pairing: no cassette attached, then remove and reinsert the battery |
| An Android phone | minSdk 28 (Android 9+), working BLE. A real device — emulators have no usable radio |
| The 6-digit PIN on the pump label | LE Secure Connections Passkey Entry |
| Your pump's registration secret (LTSS) | 16 (or 32) hex bytes. Established when the pump was registered with its official app. TwiistOff does not fetch this, makes no network calls, and has no hard-coded key — you enter your own value on the Connect page. There is no owner-usable way to obtain it outside the official app's registration yet (the project's headline gap); see Pairing and setup §4 and §7 |
| Optional: a cassette + saline | Needed for set-change, prime and delivery tests. Re-pairing with the official app typically forces a cassette change, so plan sessions |
Optional: a computer with adb |
For install, logcat and the debug-only REST bridge (adb forward tcp:8090 tcp:8090) |
Build:
git clone https://github.com/InfusionSet/TwiistOff.git
cd TwiistOff
./gradlew assembleDebug
./gradlew installDebug # phone attached
./gradlew testDebugUnitTest # crypto, payload, state and log-record unit tests
Or open the folder in Android Studio and run the app configuration. Debug builds start a
loopback-only HTTP bridge on 127.0.0.1:8090 (see bridge/RestBridge.kt); use
adb forward to reach it from a host. Release builds do not start the bridge.
3. First session (read-only)¶
Goal: bond, arm, decrypt status, get a serial back. No delivery.
- Put the pump in pairing mode (cassette off, remove and reinsert the battery; on an already-paired pump a ~5-second button hold re-opens advertising). If it is still bonded to another phone or the official app, unpair it there first. Full details: Pairing and setup §2.
- Open TwiistOff. Accept the bench-only disclaimer.
- Connect tab → Scan → the pump should be highlighted (serial-shaped name and/or
company ID
0x026B). Address rotation is normal; lock by name. Tap Connect. - Bond (or Advanced → GATT explorer → Subscribe all) → enter the label PIN. Details: Bonding and export.
- On the same Connect page, paste your LTSS and tap Arm channel. TwiistOff requests
MTU 247, reads session salt / start sequence, writes the arm byte, and starts decrypting
status. The checklist and "next action" update as each step completes; the bridge's
GET /setupshows the same thing. - Send
getPumpIdentification(0x0310). Expect a response with your serial. - Watch Monitor: battery %, self-test %, alarms, reservoir, pump state, loop. Confirm the loop is off (and no CGM paired) before any further work — and note that the status-based loop flag is not yet confirmed on the bench (Status fields §5).
- Menu → Export session. Keep the session
.txt.
If arming fails: confirm MTU 247, that you are bonded, that LTSS is the right length and value for this unit, and that the pump is still advertising / connected. A wrong LTSS yields frames that fail auth / CRC rather than a friendly error.
4. Suggested test matrix¶
Work top-down. Stop at the first failure and export.
| # | Test | What "pass" looks like | Risk |
|---|---|---|---|
| 1 | Bond + Export | Bonded; session file shares | none |
| 2 | Arm + decrypt status | Monitor populates; battery / self-test move when you make them move | none |
| 3 | getPumpIdentification |
Serial matches the label | none |
| 4 | Clear a known alert | e.g. pumpIdle after delivery has been stopped for the idle duration (clearPumpAlert 0x0400) |
low |
| 4b | Cassette removal + recovery (saline) | Remove the cassette while basal runs → alarm baseDetached, pump in cassette-change mode; reattach; POST /pump/alarm-reset → pump reboots and self-tests → commandPath back to PROVEN → verify + start basal on the same cassette, no prime (Setup and recovery §6.2) |
delivery |
| 5 | Settings write + verify | Write a pattern or limit; verifyTherapySettings returns 01 |
low (no delivery) |
| 6 | Settings readback from log | Reconstruct record matches what you wrote | none |
| 7 | History read | getLogRecord returns rows; History tab shows English titles |
none |
| 8 | Set-change + prime (saline) | Wizard completes; priming status moves; declared volume sticks | medium (pump motion) |
| 9 | startBasal / stopBasal (saline) |
Basal rate appears in status; stop drops to zero | delivery |
| 9b | Temp basal set + cancel (saline) | Adjust page temp basal (or POST /pump/temp-basal?rate=0.5&duration=30): status shows 0.50 U/h, 30/30 min, modifier 0; POST /pump/temp-basal/stop returns status to the programmed rate. A second set while one runs must be refused (cancel first). |
delivery |
| 10 | Bolus + stop (saline) | Requested/delivered match; STOP stops early | delivery |
| 11 | Closed-loop flag toggle | Adjust → Loop ON / OFF (setClosedLoop 0x8009); record status bytes 44–45 each way — this A/B is exactly what is missing to confirm the flag. Leave off when done |
low |
| 12 | Reconnect after link drop | Reconnect to the bonded address (no scan, no button) → re-arm → numbering recovers | none |
Amounts, CRCs and field offsets that TwiistOff already pins in unit tests do not need to be re-derived — but a second pump confirming the same bytes / behaviour is gold. In particular we want multi-unit confirmation of:
- Session salt / start-sequence layout on
e5332023/e5332024 - Therapy-number and Simple-vs-Therapy prefix rules
- The 42-byte verification record field widths
- Bolus amount endianness and UE2 scaling
- Alarm / alert bit → English mapping
- Anything on the status page
5. Safety checklist before any delivery command¶
- [ ] Cassette filled with saline, not insulin
- [ ] No infusion set / cannula attached to a body
- [ ] Closed loop off (written off with
setClosedLoop); no CGM paired to the pump - [ ]
GET /pump/readysayscanDeliverandcommandPathisPROVEN - [ ] One-button bolus off (or you are prepared to history-sync button boluses)
- [ ]
verifyTherapySettingsreturned01for the settings you intend - [ ] You know how you will stop (UI STOP button,
stopBasal/stopNormalBolus, or physically remove the battery) - [ ] Start with a tiny amount (≤ 0.5 U saline) and watch status bytes 52–57 move
TwiistOff asks for an on-screen confirmation before delivery-affecting commands. That dialog is a reminder, not a safeguard — the safeguard is the bench.
6. How to report findings¶
Useful reports look like this:
- Pump identity (non-secret): serial shape / region if you are willing, firmware / RIS message version if Monitor or a status decode shows it. Do not paste LTSS, PINs or bond keys into public issues or chat.
- What you did: short step list (bond → arm → opcode X with payload Y).
- What you expected vs what happened.
- The session export, or at least the log lines around the failure (hex payloads included).
- Phone: Android version, device model, TwiistOff version / commit.
Attachments: the Export share-sheet .txt is the preferred artefact. Redact anything you
consider identifying beyond the pump serial if you need to.
Open a GitHub issue on this repository, or otherwise send the export to the maintainer by a channel you both agree on.
7. What TwiistOff will not do for you¶
- It will not fetch or rotate LTSS.
- It will not bypass, patch or redistribute the official app.
- It will not make dosing decisions, read a CGM for you, or run any kind of closed loop.
- It will not talk to a pump that refuses to bond (still bonded elsewhere, wrong PIN, etc.).
- Debug REST bridge is loopback-only and debug builds only — do not expose it past
adb forwardon a machine you trust.
8. Further reading¶
| Doc | Contents |
|---|---|
| What a driver needs | Full wire reference (GATT, crypto, framing, status, settings, delivery, history, opcodes) |
| Bonding and export | On-phone bonding and session export |
| Self-diagnosis | Ordered pass/fail walk of the whole control path |
| Status | Status board and open questions |