Skip to content

_read_metadata() drops calibration fields when metadata arrives split across multiple serial reads #61

@valentinkauf

Description

@valentinkauf

Summary

_read_metadata() in src/ppk2_api/ppk2_api.py returns as soon as a single serial read buffer contains "END", without accumulating data from earlier reads. When the PPK2 firmware sends its calibration metadata split across multiple USB serial buffers, calibration fields from earlier chunks are silently discarded and remain at their default value of 0.

This causes systematically wrong current readings at low µA ranges, with no warning or error.

Expected behaviour

The full metadata string (multi-line ASCII, ending with END) should be assembled from all serial reads before parsing — matching the official nRF Connect Power Profiler, which accumulates chunks until "END" appears in the combined string.

Actual behaviour

When metadata is split across two (or more) USB reads:

  1. First read: e.g. Calibrated: 0, O0O4, S0S4, … (no END yet) → loop continues, data is not kept
  2. Second read: e.g. HW: …, END → function returns only this chunk
  3. _parse_metadata() never sees O0, S0, HW, etc. → they stay at default 0

Impact

At the lowest measurement range (range 0, ~µA scale), O[0] is the factory ADC zero-point offset (typically ~166 ADC counts). With O[0] = 0: result = (adc - O[0]) × (adc_mult / R[0]) applies no zero-point correction, adding a fixed offset of roughly ~1.8 µA to every sample (depending on hardware, some are 0.6µA, some 2.0µA). Readings in the low-µA range are systematically too high, with no error raised.

Reproduction

  1. Use a factory-calibrated PPK2 (Calibrated: 0 in metadata).
  2. Connect on a platform where metadata spans multiple serial reads (observed on macOS, metadata split across 2 reads).
  3. Call get_modifiers() and log the raw metadata string — fields like O0:O4: and HW: are missing from the returned string even though the device sent them.
  4. Measure a low-current load (< 5 µA) and compare with nRF Connect Power Profiler — this library reads ~1.8 µA higher.

Solution

I have the correction but i can't push a branch.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions