Handle bad BMS cell temperature probes#91
Merged
zjwhitehead merged 14 commits intomasterfrom Mar 14, 2026
Merged
Conversation
Detect and handle disconnected BMS cell temperature probes by treating known disconnected sentinel values as NaN. Add helpers (isBmsCellTempValidC, sanitizeBmsCellTempC) and constants to inc/sp140/bms.h, update telemetry struct comments to indicate NaN semantics, and sanitize raw cell temps in updateBMSData. Recompute highest/lowest temperature extrema from valid readings and log probe connection/disconnection transitions. Update BLE temperature characteristic to include a valid-sensor bitmap and send 0 for invalid sensors. Update LVGL main screen to compute battery temperature using only valid cell probes and only display it when a valid reading exists.
Inline BMS cell temperature validity into sanitizeBmsCellTempC and update call sites to use the sanitizer (and isnan checks) to treat disconnected probes as NaN. Update lvgl and bms logic to rely on sanitized values. Add unit tests covering sanitizer behavior and monitor handling of disconnected BMS probes, and include native test stubs for BMS_CAN and SPI. This centralizes validity logic and ensures disconnected readings are ignored consistently.
Unify handling of BMS cell probes by treating a raw -40.0°C as a disconnected probe and converting such readings to NaN. Changes: - inc/sp140/bms.h: add BMS_CELL_TEMP_DISCONNECTED_C constant and update sanitizeBmsCellTempC to return NaN for disconnected/invalid readings (use strict > to exclude -40.0). - src/sp140/bms.cpp: reuse sanitizer for connection detection and logging, exclude NaN values from extrema computation, and recompute extrema after sanitization so published high/low temps match stored values. - src/sp140/lvgl/lvgl_updates.cpp: sanitize cell temps before UI logic and show "-" when no valid battery temperature is available. Reason: ensures consistent telemetry, logging and UI behavior for disconnected probes and helps field-debug intermittent wiring issues.
CI fix
Co-authored-by: zjwhitehead <4623792+zjwhitehead@users.noreply.github.com>
Introduce BMS_CELL_PROBE_COUNT and BMS_MAX_IGNORED_DISCONNECTED_PROBES and replace the single-value sanitizer with sanitizeCellProbeTemps(), which converts disconnected sentinel (-40°C) probes to NaN while ignoring up to two such sentinels before treating further -40°C readings as real temperatures. Update bms.cpp to produce and log using sanitized probe arrays and adjust LVGL code to assume probe values are pre-sanitized. Remove the old sanitizeBmsCellTempC overload that accepted a keep-disconnected flag and expand tests to cover the new multi-probe sanitization and alert transition behavior.
…gnore-logic Normalize BMS -40C cell probe handling (ignore any 2)
Replace the local BMS_CELL_TEMP_DISCONNECTED_C sentinel with the canonical TEMP_PROBE_DISCONNECTED constant from BMS_CAN. Update sanitizeBmsCellTempC and sanitizeCellProbeTemps to reference BMS_CAN::TEMP_PROBE_DISCONNECTED, and remove the duplicate local constant. Add a native test stub for BMS_CAN exposing the constexpr TEMP_PROBE_DISCONNECTED so tests compile. Also bump the ANT-BMS-CAN dependency reference in platformio.ini to the commit that contains this change. This centralizes the probe-disconnected sentinel in the BMS_CAN library while keeping application-level policy (max ignored disconnected probes) in the app.
Sanitize BMS cell probe handling to accept NaN from the BMS library and apply an app-level tolerance: allow up to BMS_MAX_IGNORED_DISCONNECTED_PROBES NaNs to pass through, but replace any additional NaNs with the TEMP_PROBE_DISCONNECTED sentinel so monitors alert. Removed the old single-value sanitizer, made sanitizeCellProbeTemps a two-pass routine that counts NaNs and writes either NaN, the original temp, or the sentinel. Updated bms.cpp to consume the new API (pass-through NaNs from library, call sanitizeCellProbeTemps, and use library-provided highest/lowest temps), removed recomputeBmsTemperatureExtrema, and adjusted connection-logging comments. Tests were updated to feed NaN for disconnected probes and to reflect the new alerting/tolerance behavior. Also updated the ANT-BMS-CAN dependency reference in platformio.ini.
Update platformio.ini to use espressif32@6.13.0 and bump several Adafruit libraries: Adafruit BusIO 1.17.2→1.17.4, Adafruit NeoPixel 1.15.2→1.15.4, and Adafruit CAN 0.2.1→0.2.3. These dependency updates improve compatibility and include upstream fixes for the OpenPPG-CESP32S3-CAN-SP140 environment.
Update platformio.ini to use ArduinoJson@7.4.3 (from 7.3.1) and h2zero/NimBLE-Arduino@^2.3.9 (from ^2.3.5). This brings in upstream fixes and improvements for JSON handling and BLE stack compatibility.
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.
This pull request introduces improved handling and monitoring of battery cell temperature probes, focusing on robustness against probe disconnects and better alert management. The changes ensure that up to two disconnected probes are tolerated, but additional disconnects trigger alerts, and UI and telemetry reflect probe status accurately. Comprehensive unit tests validate these behaviors.
BMS Cell Probe Disconnect Handling and Alert Policy
sanitizeCellProbeTempsfunction inbms.hto tolerate up to two disconnected cell probes (represented as NaN), replacing excess disconnects with a sentinel value to trigger alerts downstream. Introduced constants for probe count and disconnect tolerance.updateBMSDatainbms.cppto apply the disconnect policy, log probe connection transitions, and ensure highest/lowest temperature readings exclude disconnected probes. [1] [2]UI and Display Improvements
lvgl_updates.cppto only use connected cell probes, showing "-" if none are connected, and hiding the temperature background accordingly. [1] [2] [3]Testing and Dependency Updates
test_simplemonitor.cppto verify probe disconnect tolerance, alert triggering, alert clearing, and sanitizer behavior for all probe states.BMS_CANandSPIto support testing. [1] [2]