Skip to content

Handle bad BMS cell temperature probes#91

Merged
zjwhitehead merged 14 commits intomasterfrom
bms-cell-low-temps
Mar 14, 2026
Merged

Handle bad BMS cell temperature probes#91
zjwhitehead merged 14 commits intomasterfrom
bms-cell-low-temps

Conversation

@zjwhitehead
Copy link
Copy Markdown
Member

@zjwhitehead zjwhitehead commented Feb 21, 2026

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

  • Added sanitizeCellProbeTemps function in bms.h to 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.
  • Updated BMS telemetry struct comments and semantics to clarify that temperature fields are NaN if unavailable or disconnected. [1] [2]
  • Modified updateBMSData in bms.cpp to apply the disconnect policy, log probe connection transitions, and ensure highest/lowest temperature readings exclude disconnected probes. [1] [2]

UI and Display Improvements

  • Changed battery temperature calculation and display logic in lvgl_updates.cpp to only use connected cell probes, showing "-" if none are connected, and hiding the temperature background accordingly. [1] [2] [3]

Testing and Dependency Updates

  • Added extensive unit tests in test_simplemonitor.cpp to verify probe disconnect tolerance, alert triggering, alert clearing, and sanitizer behavior for all probe states.
  • Updated BMS CAN library dependency to a new commit for improved probe disconnect handling.
  • Added stub headers for BMS_CAN and SPI to support testing. [1] [2]

zjwhitehead and others added 11 commits February 21, 2026 15:34
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.
@zjwhitehead zjwhitehead marked this pull request as ready for review March 11, 2026 17:53
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.
@zjwhitehead zjwhitehead merged commit a21eb38 into master Mar 14, 2026
7 checks passed
@zjwhitehead zjwhitehead deleted the bms-cell-low-temps branch March 14, 2026 15:24
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