Two separate devices had to become one instrument. The EEG headset is the documented half: it has a developer platform and an open library to read as a reference. The light box is the undocumented half, so its commands had to be recovered by watching the app talk to it, one byte at a time, and then proving each one by looking at the hardware.
- Two separate devices are being brought together here. A Muse 2 EEG headset has a developer platform and an open library to use as a reference; a NeuroVizr light device has neither. The documented one shows what a usable interface looks like. The undocumented one is the work.
- The method is three steps. Sniff the link to get the bytes, log them without lying about how long they are, then decode them by proving each field on the hardware.
- A command is 16 bytes: an opcode, a configuration code, a duration, a start and end frequency, a sweep time, and two brightness levels.
- The first capture was wrong, and it was wrong in a way that looked like an answer. The phone's log buffer cut every 16-byte command down to 15, so what survived looked like a 3-byte command — and we believed that for months, because the log agreed with us.
- The fix is one field: record the true length in the capture, and a truncated packet announces itself instead of pretending to be a short one.
- The proof was physical. A second device was put on the link as the controller, one known frame was sent, and all nine LEDs lit for exactly 30 seconds and then went dark — exactly the fields that were sent.
- 126 tests run with no hardware at all, so anyone can check the software's behaviour without owning the box.
This page is written as a procedure someone else can run on a different device. The asymmetry is the whole story: the EEG headset had a developer platform and an open library to read as a reference, and the light device had neither — no vendor SDK, no published command set, nothing but the traffic between the app and the box. Three stages did the work. Sniff the link, log it without letting the capture lie about itself, and decode it by proving each byte on the hardware.
1. Prerequisites
The rig matters more than the tooling here, because almost every wrong answer in this project came from an instrument rather than from a bad guess. This is what was on the bench, and what each piece was for.
- target device
- NeuroVizr lightbox, nine LEDs, Nordic UART service — closed: no vendor SDK, no published command set
- reference device
- Muse 2 EEG headset — has a developer platform and an open library; used as a model of what a clean interface looks like, never as documentation of the light
- capture phone
- Android 12 MTK GSI debug build, rooted, Bluetooth HCI snoop log enabled, driven over USB with adb
- BLE explorer
- nRF Connect for Android (Nordic's own app) - connect, read the GATT table, write a characteristic by hand before writing any code
- analysis host
- tshark with btsnoop support (Wireshark 3.6 or newer) to read the ATT layer
- confirmation
- a programmable nRF52840 dongle acting as the central, and eyes on the box
- vendor app
- the lightbox's own phone app, obtained outside Google Play (see the note below)
- helpful, not required
- a second lightbox, to watch one while the other is driven
One prerequisite is not a tool, it is a workaround. The vendor's app is distributed through Google Play with a licensing check: launched on a device without a valid Play installation, it refuses to start no matter how healthy Bluetooth is. The app used here is an older build of the same software, published before that check existed and still hosted, which runs without it. Treat the version as part of the rig and record it — two builds of the same app are not the same instrument, and the service UUID on the GATT table is how you confirm you have the right one.
2. The starting position: what the link carries
BLE on this device carries control and session sync only. There is no data characteristic carrying audio or video. The entire interface is a small number of short writes to the Nordic UART Service, plus notifications back on the corresponding TX characteristic. Once that is understood, the problem reduces to: what are the bytes, how long is a frame, and what does each field do.
- service
- Nordic UART (NUS) - 6e400001
- device RX
- 6e400002 - writable
- device TX
- 6e400003 - notify
- frame length
- 16 bytes
- byte order
- big-endian numerics
- advertising
- generic NUS name, no service UUID (measured on this unit)
3. Sniff: what the app sends
Two independent capture paths were used. The first is the Android HCI snoop log on a rooted or debuggable phone: enable the log, drive the vendor app through a session, pull the btsnoop file, and filter it in tshark. The second is a dedicated sniffer dongle advertising as a BLE observer. The two paths disagreeing is what eventually exposed the bug.
tshark -r btsnoop_hci.log -Y 'btatt.opcode == 0x52 || btatt.opcode == 0x1b' \
-T fields -e frame.time_epoch -e btatt.handle -e btatt.valuePull every ATT write/notify out of an HCI capture, in order.
4. Log: the trap that made the capture lie
The first path ran on an Android 12 MTK GSI debug phone, reading the in-memory HCI ring out with dumpsys bluetooth_manager. That ring caps ACL records at 15 bytes. A 16-byte command therefore arrives in the capture as its first fifteen bytes - and once the header bytes are accounted for, what is left looks exactly like a three-byte command: 41 b1 b2. Replaying those three bytes does nothing, which was read as proof that the device was refusing short commands. The cap is a ring-buffer artifact, not an air-interface limit: the frames on the air were always 16 bytes.
That single artifact produced a whole theory: a three-byte instruction set, with the richer configuration apparently negotiated elsewhere and gated behind a cloud account. The theory was internally consistent, had log files behind it, and was false. It was false because the capture had silently dropped the last byte of every frame, and because a replay tool was writing len(frame) instead of the true 16, which hid the truncation from the one place that should have caught it.
The concrete fix is one field. The ring records a length; the pcap record was being written with the length of what had been copied rather than with that original length. Writing the ring's orig length into the pcap orig_len makes every truncation announce itself - tshark prints [Packet size remained truncated] - so the failure surfaces as a warning on the frame instead of as a plausible short frame downstream.
5. Decode: the instrument that settled it
The confirmation came from putting a programmable dongle on the link as the central: subscribe to the notify characteristic, wait for the initial handshake, then write one known 16-byte frame and watch the box. All nine LEDs lit for the full programmed duration and then went dark - exactly the fields that were sent.
41 01 1e 0064 0190 0190 05 50 14 00000000
| | | | | | | | +-- brightnessOff 20
| | | | | | | +----- brightnessOn 80
| | | | | | +-------- freqTime 5 s
| | | | | +------------ freqEnd 40.0 Hz (x10)
| | | | +----------------- freqStart 40.0 Hz (x10)
| | | +---------------------- rate 100 (0 on a blank frame)
| | +-------------------------- duration 30 s (floored)
| +----------------------------- configuration code 0x01 = ALL
+-------------------------------- opcode 0x41The confirmed frame. Sixteen bytes, every field accounted for, verified by looking at the box.
Three separate false conclusions died with that test: that commands were three bytes, that the richer configurations were gated behind a cloud service, and that a write with no notification back had been rejected. All three had been inferred from capture artifacts rather than measured.
6. What the bytes still cannot tell you
The protocol exposes configuration codes, not per-LED addressing. Eleven codes are confirmed on the wire, two are confirmed on the hardware as well, and five are named in the vendor app but were never captured as bytes. This distinction is carried in code so a guess can never be promoted to a fact by accident.
- 0x01 ALL
- confirmed on wire and on hardware - all nine LEDs
- 0x04 SL-CS
- confirmed on wire and on hardware - one LED, slow and dim
- 0x00 TRANSITION
- confirmed on wire - blank frame, rate field 0
- 0x05 / 0x0b / 0x0c / 0x0e / 0x12 / 0x13 / 0x16 / 0x1a
- confirmed on wire
- TLC-RP / TRC-CP / RCW-STM / BH / MV
- named in the app, byte never captured
Wire confirmation means the full 16-byte frame was captured and replayed. Hardware confirmation means the box was watched while it happened - the two are graded separately because a replay can be perfectly correct and still light nothing if the device is asleep.
Which code lights which LED cannot be decoded from the bytes at all. It has to be observed. So the app turns that into a procedure: sweep the code space, hold each code with a re-send (the firmware only holds a command for its own duration), and record how many LEDs lit. Every answer is written to disk immediately, so an interrupted sweep costs nothing, and the resulting map is a plain JSON file that can be read, diffed and edited. Codes that lit exactly one LED get names, and those names then work anywhere a configuration name works.
7. Behaviours that shaped the application
- The firmware replaces state on every write - it does not queue. A sequence must therefore be paced by each item's own duration. Streaming frames faster makes the headset flash through the composition in under a second and end dark.
- Because state is replaced rather than queued, two single-LED commands in a row do not light two LEDs. The only way to light several at once is a code observed lighting several.
- The link drops 38.5 seconds after connecting, regardless of traffic - measured three times on one rig with three different write patterns (1, 2 and 8 writes per session): absolute drops at 42.6, 42.6 and 42.7 s against connects at ~4.1 s. The vendor's own app opens two connections per session, which is how it survives the same hang-up. The app here reconnects, re-subscribes and re-sends the interrupted command, at the cost of a gap of about 4.5 seconds dominated by GATT rediscovery.
- Acknowledgement is not guaranteed. Two independent transports were observed writing complete 16-byte frames that the device accepted at the ATT layer while returning no notification at all. The app treats the echo as a bonus, never as proof of delivery - the LEDs are the confirmation.
- The box stops advertising while connected and sleeps after a disconnect, so a failed discovery is usually a sleeping device, not a bug.
- macOS CoreBluetooth exposes a per-host UUID and never a hardware address, so a target has to be matchable by UUID, name fragment or address - matching only on the address made any device picked from a scan impossible to connect to.
8. How it is tested
The rule held throughout: if it matters, it is a test, not a convention. The suite covers key handling, parameter clamps, frame parsing and pacing, protocol generation, the state estimator and its hysteresis, the closed loop's safety band, contrast checks, the strobe guard, the session log, the scope, source-mode switching, datastream parsing, device classification, the sequence catalogue and the LED map.
- 126 tests run with no hardware and no radio permissions: cargo test across the three crates (102 in the app, 15 in neurovizr-rs, 9 in muse-rs). The Bluetooth transports compile behind a feature flag, so the default build always runs.
- One test drives real hardware through the UI's own code path, and is excluded from the default run because it needs the box: connects_to_the_lightbox.
- --snapshot renders a single frame through ratatui's TestBackend and exits, so the interface can be diffed, screenshotted or asserted in CI. When a scan is running it waits for it to finish, bounded at 12 seconds - which is how the device page was verified against a real radio rather than against a mock.
- The interactive path was verified in a PTY: clean quit, alternate screen restored.
- The simulator is not a stub. It reproduces write echoing, the forced 38.5-second disconnect and the 1.5-second reconnect settle, so the resume path itself is testable with no radio attached.
- The photosensitivity exclusion is a test: no generated frame may land in the 15-20 Hz band, so a protocol generator cannot emit an unsafe frame even if a parameter is mistyped.
9. Reusing the method on another device
- Write the rig down before the first capture: device, phone build, whether it is rooted, which capture path, and what that path's record-size limit is. Most later doubts are settled by that list rather than by a new experiment.
- Establish the transport before the payload: which service, which characteristic is writable, which notifies. Confirm it on a GATT table, not on an advertised name - generic NUS is shared by thousands of devices.
- Determine the frame length from a second instrument, independently of your capture. If your capture path has a record cap, every frame looks shorter than it is and every theory you build will be a theory about the cap.
- Write a known frame from a central you control and confirm with your eyes, not with an acknowledgement. Devices routinely accept writes and say nothing back.
- Keep a confirmation ledger in code: on the wire, on the hardware, named-only. Never let a name in an app's UI become a byte in your protocol by assumption.
- Only then build the application. The app should look like the protocol you proved, not the one you assumed - the gaps become procedures instead of guesses.
- neurovizr-rs - wire format and the confirmation ledger · not yet public
- ftrst-tui - README, testing, datastream · not yet public
- ftrst-tui - docs/DATASTREAM.md · not yet public