Skip to main content

PPG2 / BioZ / Accelerometer / ECG transfer & export

PPG2, BioZ, accelerometer and ECG data are too large to store as database rows. The SDK writes them to binary .wiff files on the phone. This page explains how the files get on the phone, how your app is told that a file is ready, and how to export the files.

For ECG, the measurement and its export are described on the ECG page. To decode the files into samples inside your app, see Parsing Raw Files.

What must be in place before a file appears:

  1. The bracelet is a 287-2B.
  2. Your licence includes the raw data type. See The licence and raw data.
  3. The raw data is switched on on the bracelet. See Enable raw streams and Bracelet Plans.
  4. The bracelet is subscribed for the automatic download.

How a file gets on the phone​

  1. Each automatic download fetches the new raw data from the bracelet and stores it on the phone as a part file (.wiff.part).
  2. When the part files of a type are together at least as large as the threshold in DataSdk.Config (ppg2ThresholdFileSize, bioZThresholdFileSize, accThresholdFileSize), the SDK merges them into one .wiff file and deletes the parts. See File size thresholds.
  3. The SDK then calls the wiffFileUpdated listener with the new file. The file is now exportable.

With the default thresholds a PPG2 file is made once 500 KB of data is waiting, and a BioZ or accelerometer file once 30 KB is waiting. To make a file from the parts that are waiting, without waiting for the threshold, call:

val manager = DataSdk.getInstance().getManager()

// also: manager.biozWiffFileUpdater, manager.accWiffFileUpdater
manager.ppg2WiffFileUpdater.mergeChunkFilesForce(
address, // MAC address of the bracelet
onSuccess = { chunk -> /* the new file, or null when no part was waiting */ },
onError = { error -> /* could not merge */ }
)

Location of the files: PPG2, EmoGraphy, BioZ, Accelerometer​

All the files are saved in the internal app folder on the phone (Context.filesDir), in one folder per type. The folders are not accessible from outside your app. Here is the list of the folders per type:

enum class RawFileType(val directory: String) {
UNKNOWN(""),
SLEEP("sleep"),
PPG2("ppg2"),
ECG("ecg"),
BIOZ("bioz"),
ACC("acc");
}

A file is named <TYPE>_<yyyy-MM-dd_HH-mm-ss-SSS>_Android_full.wiff, for example PPG2_2026-11-17_09-14-32-118_Android_full.wiff. The date is the moment the file was made.

EmoGraphy is not a file: its values are stored as MetricEmography rows. See Retrieve the Data.

The list of files is in the table RawFileChunk, which you read through rawFileRepository. One RawFileChunk describes one file:

FieldTypeDescription
fileNameStringName of the file in the folder of its type
typeStringExportable files have the type <type>_FULL, example for PPG2: PPG2_FULL
watchAddressStringMAC address of the bracelet the data comes from
timestampLongWhen the file was made, UTC milliseconds
sizeLongSize in bytes
statusIntRawFileChunk.Status: 0 NEW, 1 PROCESSING (an export is under way), 2 PROCESSED (exported)
note

Use type to tell the files apart. RawFileChunk.fileType is RawFileType.UNKNOWN for an exportable file, because its type ends with _FULL.

Once exported, the files are deleted from the internal folder.

Get notified when a new .wiff file is ready​

Starting SDK 0.8.0. The listener is called on the callback scheduler (the main thread by default), once per new PPG2, BioZ or accelerometer file.

import com.corsano.sdk.data.external.realm.models.RawFileChunk
import com.corsano.sdk.data.external.realm.models.enum.RawFileType
import com.corsano.sdk.data.summary.ValueUpdated

private val dataSdkManager = DataSdk.getInstance().getManager()
private val type = RawFileType.PPG2

private val fullWiffFileListener = object : ValueUpdated.Listener<RawFileChunk> {
override fun onValueUpdated(model: RawFileChunk) {
if (model.type.contains(type.name, true)) {
view?.findViewById<TextView>(R.id.action_result)?.text =
"New File saved: ${model.fileName} size ${model.size / 1024} KB at ${Date(model.timestamp)}"
}
}
}

override fun onStart() {
super.onStart()
dataSdkManager.wiffFileUpdated.addListener(fullWiffFileListener)
}

override fun onStop() {
// Unsubscribe updated listener.
dataSdkManager.wiffFileUpdated.removeListener(fullWiffFileListener)
super.onStop()
}

Get the exportable files​

To list the files of a bracelet that are waiting for an export:

DataSdk.getInstance().getManager().rawFileRepository.getExportabledWiffFiles(
watchAddress,
RawFileType.PPG2,
{ chunks -> Log.d("Corsano-SDK", "${chunks?.size ?: 0} PPG2 files to export") },
{ error -> Log.e("Corsano-SDK", "Could not read the files: $error") }
)

Both callbacks are required. The result is an Array<RawFileChunk>?, oldest file first.

Export of the files​

manager.wiffFileExporter copies the exportable files of one bracelet and one type out of the internal folder. After the export, the copied files are deleted from the app's internal folder, so each file is exported once.

Method 1: export to the phone's storage (Documents, Download, etc)​

The user selects a folder, for example the Download folder, and gives your app access to it. The files are then copied to that folder.

Code example (DataMeasurementFragment.kt in the sample app does the same):

private val pickFolder =
registerForActivityResult(ActivityResultContracts.OpenDocumentTree()) { uri ->
val docFile = uri?.let { DocumentFile.fromTreeUri(requireContext(), it) }
?: return@registerForActivityResult
dataSdkManager.wiffFileExporter.exportWiffFiles(
address, type, docFile,
{ chunks -> Log.d("Corsano-SDK", "${chunks.size} files saved successfully") },
{ error -> Log.e("Corsano-SDK", "Export failed: $error") }
)
}

// When the user taps "Export":
pickFolder.launch(null)

docFile is obtained by asking the user to select a folder and give access to the app.

Method 2: export to the app folder (hidden from the user)​

It is possible to export the files to a folder of your app with the method exportWiffFilesToAppDirectory. You pass any folder your app can write to as a File.

With getExternalFilesDir, the files are copied to Android/data/<your.application.id>/files (in the sample app, Android/data/com.corsano.sdk.sample/files).

Example using the sample app with “My_directory”

Export to the app directory

Code example (DataMeasurementFragment.kt in the sample app):

val directory = requireContext().getExternalFilesDir("My_directory") ?: return
if (!directory.exists())
directory.mkdir()

dataSdkManager.wiffFileExporter.exportWiffFilesToAppDirectory(
watchAddress, RawFileType.PPG2,
directory,
{ chunks -> Log.d("Corsano-SDK", "${chunks.size} files saved successfully") },
{ error -> Log.e("Corsano-SDK", "Export failed: $error") }
)

Export behaviour​

exportWiffFiles copies the .wiff files recorded for a bracelet to a folder the user has granted access to.

fun exportWiffFiles(
address: String,
type: RawFileType,
documentFile: DocumentFile,
onSuccess: ((ArrayList<RawFileChunk>) -> Unit)? = null,
onError: ((Throwable) -> Unit)? = null
)
ParameterTypeDescription
addressStringMAC address of the bracelet whose files are exported
typeRawFileTypePPG2, ACC or BIOZ. For ECG use the ECG manager, see ECG. SLEEP and UNKNOWN have no exportable files: the call succeeds with an empty list
documentFileDocumentFileDestination folder, from the system folder picker
onSuccess((ArrayList<RawFileChunk>) -> Unit)?The files that were copied
onError((Throwable) -> Unit)?Called when nothing could be copied

exportWiffFilesToAppDirectory has the same parameters, with directory: File in place of documentFile, and behaves the same way.

Points worth knowing when you build a UI around it:

  • Having nothing to export is a success, not an error. onSuccess is called with an empty list. Do not present that as a failure to the user.
  • A file that cannot be copied does not abort the batch. Every other file is still exported; the failure is logged per file.
  • Files that failed stay eligible. They are returned to the pending state and retried on the next export, rather than being stuck as permanently in-progress.
  • Files whose .wiff file no longer exists on disk are removed from the database before the export starts, so they cannot make every later export fail.
  • A destination folder that is no longer writable is reported through onError with a readable message.
  • The callbacks run on the callback scheduler (the main thread by default). The files are copied on that thread too, before the callback.

Export therefore either copies what it can and reports it through onSuccess, or reports a real problem through onError: a partial batch is not treated as a total failure.

Data interpretation​

The binary layout of the files is documented in Raw files. PPG2 and accelerometer files can be decoded in your app with the SDK's parsers: see Parsing Raw Files.

The exported files can also be parsed using our sample code, available in Python or PHP.

Please request access via our contact page.