Skip to content

Add support for Dr. Trust Smart 505 Scale (India) - #1445

Open
joshferns wants to merge 2 commits into
oliexdev:masterfrom
joshferns:claude/mgbhandler-8byte-streaming-70ivmp
Open

Add support for Dr. Trust Smart 505 Scale (India)#1445
joshferns wants to merge 2 commits into
oliexdev:masterfrom
joshferns:claude/mgbhandler-8byte-streaming-70ivmp

Conversation

@joshferns

Copy link
Copy Markdown

Add 8-byte streaming protocol support to MGBHandler (Dr Trust Smart 505)

MGBHandler matches by name (swan/icomon/yg) or service 0xFFB0. The Dr Trust Smart 505 matches but sends 8-byte frames, while the handler only accepted 20-byte composite frames (if (data.size != 20) return) — so it connected, ran its init writes, and silently saved nothing.

This makes onNotification() dispatch on frame size and adds a path for the 8-byte variant. The 20-byte path is unchanged (extracted verbatim into a private method).

Protocol (8-byte variant)
Frame: AC 02 [b2] [b3] [b4] [b5] [flag] [chk], chk = (b2+b3+b4+b5+flag) & 0xFF. Flag byte: CE live weight, CA settled weight (u16 in b2:b3, 0.01 kg), CB impedance (FD 01 [hi] [lo], ohms), CC status. Completion is the CE→CA flag change, not a separate frame.

Implementation

Pure companion-object parsers (isValidStreamingFrame, parseFinalWeightRaw, parseLiveWeightRaw, parseImpedanceOhm), following VitafitVT701Handler's pattern.
Latches weight + impedance, publishes once both arrive, resets in a new onDisconnected().
Composition via StandardImpedanceLib — same library and sanity guard VitafitVT701Handler uses; raw impedance also stored. No new formulas.

Tests
New MGBHandlerStreamingTest.kt covering weight/impedance parsing, the flag distinctions, the FD-config-vs-impedance collision, and checksum/size rejection. Passes; existing VitafitVT701HandlerTest still passes.

Tested on a physical Dr Trust Smart 505: weigh-in saves correctly, and weight/BMI/bone match the vendor app. Composition is derived from raw impedance via StandardImpedanceLib, so it differs from the vendor's proprietary values (as with other impedance scales here) — happy to swap the estimator if preferred. I don't own the 20-byte variant, so only the 8-byte path is hardware-verified.

claude added 2 commits August 4, 2026 09:17
MGBHandler previously assumed every notification was a 20-byte
composite frame and dropped anything else, so scales like the Dr
Trust Smart 505 (same SWAN name / 0xFFB0 service, but 8-byte
streaming frames) connected and never produced a measurement.

onNotification now dispatches on frame size: the existing 20-byte
composite path is unchanged (only moved into onCompositeFrame), and
a new 8-byte streaming path parses live/final weight and impedance
frames via pure, unit-tested companion functions, latching both
values before publishing one measurement and deriving body
composition with StandardImpedanceLib (same approach as
VitafitVT701Handler).
It had a single call site; folding it into the 8-byte branch matches
VitafitVT701Handler's flatter onNotification style. No logic change.
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