Skip to content

Identify beacons by 0x2080 service data; battery, rate colors, UI rework - #5

Merged
jappeace merged 8 commits into
jappeace:masterfrom
jappeace-sloth:feat/ext-data-identity-ui
Jul 14, 2026
Merged

jappeace merged 8 commits into
jappeace:masterfrom
jappeace-sloth:feat/ext-data-identity-ui

Conversation

@jappeace-sloth

Copy link
Copy Markdown

Stacked on #4 (includes its commits until that merges). Pins hatter at the jappeace-sloth feat/ble-advertisement-payloads branch (jappeace/hatter#239); repoint the pin at hatter master after #239 merges.

Identity via service data (hatter #238 payoff)

  • identifyScanResult now takes the 0x2080 service data payload and treats it as the primary KKM signal, exactly like KKM's own library. MAC-prefix and factory-name fallbacks stay for payload-less frames (e.g. a slot broadcasting pure iBeacon).
  • kkmExtDataBattery / kkmExtDataMac parse the payload per KBAdvPacketHandler.java/.swift: byte 0 battery (clamped to 100), bytes 3..5 the MAC's low bytes when byte 1 is 0 and byte 2 is the marker 1. This makes renamed beacons configurable from iOS and shows battery without connecting, closing both former TODO items.

UI rework (as requested)

  • Permission page: the app opens on it, granting both permissions moves to the scanner page and the permission UI is gone; a denial keeps the page and names the missing permission.
  • Adapter gate: Start Scan checks the adapter first and refuses with a clear status when bluetooth is off/unauthorized/unsupported.
  • Toggle: one button flips between Start Scan and Stop Scan (also removes the double-start footgun).
  • Live rows: repeated advertisements refresh RSSI and battery and measure the advertisement interval (exponentially smoothed, Decision comment on the 25% tolerance); the row colors green at the expected rate and red when deviating.
  • "discovered" renamed to "found".

Tests

  • The scan callback is clock-injected (onScanResultAt), so rate measurement and smoothing are tested with fabricated times; 63 tests pass covering the permission flow, toggle, adapter gate, coloring (via a widget-tree color walk), ext-data identity including the renamed-iOS path, and all previous behaviour. A sabotage run (EMA replaced by raw delta) failed exactly the smoothing test.
  • The emulator UI test grows the permission-page step and asserts battery shows on the row straight from the advertisement.

Local verification: cabal build clean, 63/63 tests, shellcheck + py_compile pass. The emulator job runs in CI.

🤖 Generated with Claude Code

jappeace-sloth and others added 8 commits July 13, 2026 23:41
Bump the hatter pin to the advertisement-payload branch
(jappeace-sloth/hatter feat/ble-advertisement-payloads, to be
repointed at jappeace/hatter master once #239 merges) and use the new
payloads:

- identifyScanResult now takes the 0x2080 service data payload and
  treats it as the primary KKM signal, exactly like KKM's own
  library; the MAC prefix and factory name remain fallbacks for
  payload-less frames. kkmExtDataBattery and kkmExtDataMac parse the
  payload per KBAdvPacketHandler.java/.swift (byte 0 battery clamped
  to 100; bytes 3..5 the MAC's low bytes when byte 1 is 0 and byte 2
  the marker 1), which makes renamed beacons configurable from iOS
  and shows battery without connecting (both former TODO items).

UI rework, all requested behaviours:

- The app opens on a one-time permission page and moves itself to
  the scanner page when both permissions are granted; a denial keeps
  the page up naming the missing permission.
- Start Scan checks the adapter first and refuses with a clear
  status while bluetooth is off/unauthorized/unsupported.
- One scan button that toggles between Start Scan and Stop Scan.
- Repeated advertisements refresh a listed beacon (RSSI, battery)
  and measure its advertisement interval (exponentially smoothed);
  the row is colored green when the measured rate matches the
  expected interval input within 25% and red when it deviates.
- The "discovered" status is renamed to "found".

The scan callback is clock-injected (onScanResultAt) so the tests
drive rate measurement with fabricated times; 63 tests pass,
including the permission page flow, the toggle, the adapter gate,
rate smoothing and coloring, and the renamed-iOS-beacon path. The
emulator test grows the permission-page step and a battery-on-row
assertion.

Prompt: hmmm, the app doesn't list the current pin rate, and didn't
the original also show colors somehow (I don't remember). Right if
the ping rate is above or below what's expected we'd see the line
colored. also what does "discovered" mean? what happens if I press
start scan twice? can we change start scan into stop scan after
starting? also can we just make a permission page to deal with
permission but once you've done them you move on to the next page and
the permissons are no longer on screen. if you press start scan you
also have to check the adapter, if the adapter is down show a message
to the user and just don't start. / I suppose we've to address 238
first to even support this tool / well just go do the second part as
well as soon as ci passes I'm going to sleep, we can repoint it at
master tomorrow

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Style rule: no crossing wildcards in a pure decision function; the
collapsed clauses hid no distinct outcomes but the enumeration is
two lines.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The emulator job died substituting the NDK toolchain from
nix-cache.jappie.me (curl: failure receiving data from the peer);
build and build-ios passed on the same commit.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Attempt 9 of the emulator run passed everything except the battery
assertion: assert_ui_text exact-matches a node's full text, and
battery shared its node with the nondeterministic measured rate
(" | 85% | ~200 ms"). Battery and rate are separate text nodes now,
and the script asserts the deterministic " | 85%".

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Hatter review rounds changed the advertisement API: service data is
keyed by uuid-types' binary UUID and serviceDataForUuid takes the
UUID value. The KKM ext-data constant becomes a total UUID.fromWords
value (no literal can be malformed), replacing the text constant;
the pin moves to the current fork head so CI proves the integration
before the merge, leaving the post-merge repoint a hash-only change.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Hatter's parser now carries the partial advertisement alongside the
parse errors; the identity gate reads service data from the salvage
too, so a beacon with one garbled structure keeps its valid 0x2080
identity and battery instead of degrading to the MAC-prefix
fallback. Hatter's dispatch already logged the defects.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Review gate finding: the Left-branch salvage in scanResultExtData had
no kbeacon-side coverage (hatter's tests cover hatter's parser, not
this call site); reverting it to Nothing left the suite green. The
new test feeds a malformed advertisement whose salvage carries the
only identity source (opaque iOS address, non-factory name) and
asserts the beacon lists with the ext-data MAC and battery; verified
to fail exactly alone against the reverted branch.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Same tree as the reviewed branch head, now via jappeace/hatter
master. All advertisement-payload work this PR builds on is upstream.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@jappeace
jappeace merged commit 8a3d112 into jappeace:master Jul 14, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants