Repository navigation
Conversation
Recover from boot-time UART noise by checking HEAD_CKSUM at eight bytes and re-locking onto the next SOF. Apply completed frames when the queue is full so sparse heart/breath reports survive a delayed host loop. isHumanDetected() returns the last reported presence. Co-authored-by: Citric Li <limengdu@users.noreply.github.com>
This was referenced Oct 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #7
Fixes #8
This PR keeps the existing Arduino polling API and fixes the two library-level bugs that match those reports. It does not change ESPHome YAML and does not touch Matter (#3).
Causes
#8 “sometimes no values” / NaN after plug-in
Three things in this library can leave the host with no vital-sign updates until a power cycle (including swapping the kit’s second USB-C port):
fetch()treated every0x01as SOF and only checked checksums after the declared payload arrived. A0x01in boot banner / reset noise with a largeLENswallowed the following real frames. Parser state was alsostatic, so it survived acrossbegin()calls.begin(). The radar and the XIAO share UART. Defaultrst = -1does not reset the module, and leftover boot bytes stayed in the 32 KB RX buffer.target_numon0x0A04/0x0A08. A huge count can allocate or walk off the payload and hang the MCU.The “other USB-C port unblocks it” report is consistent with a power-on race: one port restarts the radar, the other the ESP, and a lucky boot happens to start on a real SOF.
#7 “disabling
api:leaves only Target Number”ESPHome’s
seeed_mr60bha2component has its own UART parser (this library is not linked into that firmware). The same symptoms still come from this driver when the host loop is slower (MQTT-only, reconnect stalls, longupdate()gaps):0x0A04) arrive much more often than heart / breath (0x0A14/0x0A15). WhenbyteQueuehitMMWaveMaxQueueSize(120), the oldest frame was discarded. Sparse vitals were the ones that disappeared; the latest target count survived.fetchType()/processQueuedFrames(type)returned beforehandleType()on non-matching frames, so a command ACK wait dropped heart / breath already in the queue.isHumanDetected()consumed the “new data” flag. After one read it returnedfalseeven when a person was still present. Wrappers that gate heart / breath on that call then stop publishing everything except target count.I2C illuminance continuing to work matches both reports: BH1750 never goes through this UART path.
Fixes
FrameCodec+FrameAssembler: validateHEAD_CKSUMat 8 bytes, rejectLEN > 512immediately, resync by scanning leftover bytes for the next0x01.begin()waits briefly, drains UART, and callsresync()(public, so a sketch can recover without resetting the MCU).handleType()before dropping it.isHumanDetected()returns the last reported presence (same idea asSEEED_MR60FDA2::getHuman()).target_numis capped by payload size andMAX_TARGET_NUM/MAX_POINT_CLOUD_NUM.pio test -e native) and GitHub Actions CI (host tests,arduino-lint --compliance specification, compile examples for XIAO ESP32-C6).Testing already run
17/17 host tests passed, including:
0x01LENthat must not consume the next real frameLocal
arduino-lint --compliance specification --library-manager submitfrom aSeeed-mmWave-libraryfolder: 0 errors (existing name-has-“Arduino” / spaces warnings only).Needs hardware verification
This environment has no MR60BHA2 / MR60FDA2 kit. Please confirm on a real XIAO ESP32-C6 + MR60BHA2:
mmWave.begin(&mmWaveSerial),examples/mmwaveBreathshould print heart / breath / distance within ~60 s of a person sitting still (the module’s own lock time). Repeat cold-plug 10 times; values should appear without swapping ports. If the stream is still silent, callmmWave.resync()once after a 200 ms delay.update(100)only every 1–2 s (or add a long MQTT-style delay). Target count, presence, heart rate, and breath rate should all keep updating; presence should staytruewhile a person is in range.api:and using MQTT is an ESPHome app concern. After this library ships, Arduino/custom-component users are covered. Official /limengduESPHome components copy the protocol and do not link this repo — if MQTT-only still shows only Target Number on stock ESPHome firmware, that needs a change in MR60BHA2_ESPHome_external_components or esphome/esphome (theirhas_targetgate and “publish only if != 0” filters).examples/PeopleCounting_demostill reports 1–3 targets.examples/fall_demostill reads fall / human.setInstallationHeight/setThreshold/setSensitivityon MR60FDA2 still get ACKs.Do not merge until those kit checks pass.