ECG measurement
Only available for B2 (287-2B)
Available starting version 0.8.2
The ECG measurement is 50 seconds, sampled at 256 Hz.
The ECG feature is meant for a quick measurement of a couple of minutes. It is not meant to stay activated all day, because the measurement of the other metrics is deactivated during the ECG measurement.
During the 50 seconds there are 8 seconds of warm up and 42 seconds of effective ECG data.
The ECG has to be started and stopped by your application: the SDK does not stop it after 50 seconds. Follow the sample app example in DataEcgFragment.kt, which stops it with a 50-second timer.
The path in short
- Start:
startEcg(bleDevice, onDone, onError). - Stop after 50 seconds:
stopEcg(bleDevice, onDone, onError). The SDK then starts a download. - The SDK downloads the recording and merges it into one
.wifffile.manager.ecgWiffFileUpdatedtells you when the file is ready. - Parse the file (
parseEcgMeasurement), filter it (filterEcg), or export it (exportWiffFiles).
| What you want | Call | Where it arrives |
|---|---|---|
| Whether an ECG is running | isEcgRunning { running -> } | The callback |
| The last measurement and its status | getLastEcg { ecg -> } | The callback: EcgMeasurementModel?, with status |
| To know when a recording is ready | manager.ecgWiffFileUpdated.addListener(listener) | onValueUpdated(model: EcgMeasurementModel) |
| The measurements whose file is ready | getExportableEcgs { list -> } | The callback, oldest first |
| The samples of a measurement | parseEcgMeasurement(context, ecg, listener) | EcgParserListener.onFinish(slots) |
| A clean waveform and the heart rate | filterEcg(slots) { result -> } | The callback: EcgLocalFilter.Result |
The .wiff files outside the SDK's folder | exportWiffFiles(...), exportWiffFilesToAppDirectory(...) | onSuccess(files) |
All functions are on the ECG manager. The snippets on this page use:
val manager = DataSdk.getInstance().getManager()
val ecgManager = manager.getEcgManager()
val bleDevice = BleSdk.getInstance().getDevice(address) // address: the bracelet's BLE MAC address
Prerequisites
- Bracelet: a 287-2B. The SDK downloads the ECG recording from a 287-2B only.
- Connected and initialized. The bracelet is connected and its bracelet initialization has finished.
- Licence: the ECG raw data type must be part of your licence. Without it the SDK never downloads the recording, and a measurement stays in the status
PROCESSING. While the SDK is locked by the licence check,startEcgfails withSdkLicenceException. See Licence Key. - Data transfer: the recording reaches the phone through the SDK's download, see Data transfer.
Start ECG measurement
Start ECG using the code below:
ecgManager.startEcg(bleDevice, {
// The bracelet started the ECG. Stop it yourself after 50 seconds.
result("Start Ecg success")
updateUI()
}, { error ->
result("Start Ecg error: $error")
})
The start ECG command is sent to the bracelet, and a row is created in the measurement table (EcgMeasurementModel, status ONGOING).
onError receives:
error | Cause | What to do |
|---|---|---|
An SdkLicenceException | The SDK is locked by the licence check | Retrying does not help. See Licence Key |
null | An ECG is already running according to the SDK's database: the last measurement was never stopped | Check with isEcgRunning, call stopEcg, then start again |
null | The bracelet did not accept the command: not connected or not initialized | Check bleDevice.connectionState and bleDevice.isInitialized, then start again |
Both callbacks are called on the main thread.
A blue light is visible on the bracelet when the ECG is running:

Stop ECG measurement
Stop ECG using the code below:
ecgManager.stopEcg(bleDevice, {
result("Stop Ecg success")
updateUI()
}, { error ->
result("Stop Ecg error: $error")
})
The stop ECG command is sent to the bracelet, and the row in the measurement table is updated with the stop timestamp (status PROCESSING). The SDK then triggers a download of the bracelet's data itself.
onError receives null when no ECG is running according to the SDK's database, or when the bracelet did not accept the command. In the second case the measurement stays ONGOING: call stopEcg again when the bracelet is connected.
stopEcg also works while the SDK is locked by the licence check, so a bracelet does not stay in the measurement. The recording itself is downloaded once the lock is lifted.
The blue light on the bracelet is turned off when the ECG is stopped.

ECG in the database
The ECG are saved into the table EcgMeasurementModel. Since 3.0.0 it is a plain class, and every model the SDK returns is a copy.
open class EcgMeasurementModel {
var startTimestamp: Long = 0L // start time of the ECG
var endTimestamp: Long? = null // end time of the ECG
var wiffFilename: String? = null // filename of the full .wiff file of the measurement when the measurement is finished and after a successful sync
val status: Status
}
startTimestamp and endTimestamp are the phone's time, in epoch milliseconds, at which the bracelet accepted the start and the stop.
EcgMeasurementModel.Status, in order:
| Status | Meaning |
|---|---|
ONGOING | Started, not stopped (endTimestamp is null) |
PROCESSING | Stopped; the .wiff file is not ready yet (wiffFilename is null) |
FINISHED | The .wiff file is ready (wiffFilename is set) |
Read the measurements through the ECG manager:
| Function | Result |
|---|---|
isEcgRunning { running -> } | true when the newest measurement is ONGOING |
getLastEcg { ecg -> } | The newest measurement, or null |
getEcgMeasurementsToSync { list -> } | The stopped measurements whose file is not ready, newest first |
getExportableEcgs { list -> } | The measurements whose file is ready, oldest first |
deleteEcgInRange(startTimestampDelete, endTimestampDelete, onSuccess, onError) | Deletes the measurements that start in the range, both ends included |
deleteAllEcg(onSuccess, onError) | Deletes every measurement |
deleteAllFiles(context) { files -> } | Deletes every .wiff file of the SDK's ECG folder |
Deleting measurements does not delete their files, and deleting files does not delete the measurements.
manager.ecgRepository (an EcgRepository) offers the two deletes as deleteEcgByTimestampRange and deleteAllEcg. Since 3.0.0 you cannot construct an EcgRepository yourself.
Retrieve data of the ECG measurement
To retrieve the ECG data, make sure the bracelet is syncing regularly using the Data transfer.
- Small .wiff.part files at each synchronisation
The ECG data from the bracelet is synced at each regular sync. At each sync, the ECG data is written in a file named ecg-<bracelet address>-<timestamp>.wiff.part (the : of the address are replaced by _). The .wiff.part files are stored in the app internal folder, in the ecg directory (<filesDir>/ecg).

- Merge to a .wiff file at the end of the ECG
When the ECG is stopped, after the next sync with the bracelet, when the SDK is sure that there is no remaining ECG data on the bracelet, the .wiff.part files are merged into one .wiff file, in the same directory. The file is named ECG_<yyyy-MM-dd_HH-mm-ss-SSS>_Android_full.wiff, with the date and time of the merge. This is the file that is available for export. After the merge, the .wiff.part files are deleted, wiffFilename is set and the status becomes FINISHED.

- Know when the file is ready
manager.ecgWiffFileUpdated.addListener(object : ValueUpdated.Listener<EcgMeasurementModel> {
override fun onValueUpdated(model: EcgMeasurementModel) {
// model.wiffFilename is set: the measurement can be parsed and exported
}
})
The listener is called once per download that merged a file. When one download merges several measurements, it is called for one of them only: list them all with getExportableEcgs.
Export ECG files
Export to phone storage
Use the function exportWiffFiles, this function will:
- Get in the DB the ECG with a wiff file to export
- Check that the file exists
- Export it
- If the flag
deleteAfterExportis true, the file will be deleted from the app storage (recommended)
// uri: the folder the user picked with Intent.ACTION_OPEN_DOCUMENT_TREE
val folder = DocumentFile.fromTreeUri(context, uri) ?: return
ecgManager.exportWiffFiles(
context,
folder,
true, // deleteAfterExport
{ files ->
Toast.makeText(context, "${files?.size ?: 0} files saved successfully", Toast.LENGTH_SHORT).show()
},
{ error ->
result("Export ECG error $error")
})
onSuccess receives the exported files, or null when there was nothing to export.
Export to another directory in the app folder
Use the function exportWiffFilesToAppDirectory, this function will:
- Get in the DB the ECG with a wiff file to export
- Check that the file exists
- Copy it to the destination directory
- If the flag
deleteAfterExportis true, the file will be deleted from the app storage (recommended)
ecgManager.exportWiffFilesToAppDirectory(
context,
destDirectory, // a java.io.File
true, // deleteAfterExport
{ files -> }, // the copies, or null when there was nothing to export
{ error -> })
With deleteAfterExport, the file leaves the SDK's folder but the measurement keeps its wiffFilename. parseEcgMeasurement then reports that the file does not exist. Parse before you export, or parse your copy with EcgWiffParser().run(file, listener), which takes the same EcgParserListener.
Parsing wiff files
Use the function parseEcgMeasurement, this function will:
- Check the ECG in the database and parse the wiff file associated
ecgManager.parseEcgMeasurement(context, ecg, object : EcgParserListener {
override fun onStart() {}
override fun onNewSlotsAvailable(slots: List<EcgSlotModel>) {} // the samples of one packet
override fun onFinish(slots: List<EcgSlotModel>) {} // all samples of the file
override fun onError(t: Throwable) {}
})
- The file is parsed on the calling thread, and the listener is called on that thread before
parseEcgMeasurementreturns. Call it from a background thread. onErroris called when the measurement has no file yet (its status is notFINISHED) or when the file is no longer in the SDK's folder.- Since 3.0.0 a sample dated before 2021-01-01 or more than 10 minutes after the phone's clock is not handed to the listener.
The parsing result is a list of EcgSlotModel:
data class EcgSlotModel(
var timestamp: Long = 0L,
var chunkIndex: Int = 0,
var qualityIndexElectrodeContact: Int? = null,
var qualityIndexStability: Int? = null,
var qualityIndexNoise: Int? = null,
var qualityIndexPower: Int? = null,
var qualityIndexMovements: Int? = null,
var ecg: Double = 0.0
)
| Field | Value |
|---|---|
timestamp | Time of the sample, epoch milliseconds. The samples of a packet are spaced at 256 Hz from the packet's second |
chunkIndex | Chunk index of the packet the sample comes from, as the bracelet sent it |
ecg | The raw sample, in millivolts |
qualityIndexElectrodeContact, qualityIndexStability | Quality flags of the packet, 0 or 1 |
qualityIndexNoise, qualityIndexPower, qualityIndexMovements | Quality indexes of the packet, 0 to 3 |
The raw sample is in ecg; the qualityIndex* fields describe the recording conditions for that slot. They are the same for every sample of a packet.
ECG filtering
From SDK 2.1.0.
The ecg values in the parsed slots are the raw signal. To display a clean waveform and a heart rate, filter the slots with filterEcg. The filtering runs entirely on the phone: no backend or internet connection is needed.
fun filterEcg(
slots: List<EcgSlotModel>,
durationSeconds: Int = 0,
result: (EcgLocalFilter.Result) -> Unit
)
| Parameter | Type | Description |
|---|---|---|
slots | List<EcgSlotModel> | The parsed slots, e.g. the output of parseEcgMeasurement |
durationSeconds | Int | 0 filters the whole signal; n produces n * 256 samples (ECG is sampled at 256 Hz) |
result | (EcgLocalFilter.Result) -> Unit | Called with the filtered signal and detected BPM |
filterEcg returns at once; result is called on the main thread when the filtering has finished.
EcgLocalFilter.Result
data class Result(
val filteredSignal: List<Double>,
val bpm: Int
)
| Field | Type | Description |
|---|---|---|
filteredSignal | List<Double> | The filtered ECG waveform, ready to plot |
bpm | Int | Detected heart rate, or -1 when it cannot be determined |
Always check for bpm == -1 before showing a heart rate: a short or noisy recording may not yield one even though filteredSignal is still usable for display.
Example
ecgManager.parseEcgMeasurement(context, measurement, object : EcgParserListener {
override fun onFinish(slots: List<EcgSlotModel>) {
ecgManager.filterEcg(slots) { result ->
drawWaveform(result.filteredSignal)
if (result.bpm != -1) showHeartRate(result.bpm)
}
}
// other callbacks…
})
EcgLocalFilter is a Kotlin port of the Corsano reference ECG filter, verified to produce output identical to the original. You can call EcgLocalFilter.filter(ecgValues, durationSeconds) directly on a List<Double> if you already have raw values outside of EcgSlotModel, or to run the filtering on a thread of your choice: it returns the Result on the calling thread.
Sample app: in the sample module, Data → ECG → "parse last ECG" filters the parsed measurement locally and displays the detected BPM.