Streaming Biosignals
Once a device reaches the .ready connection state, you can start streaming biosignal data.
Start and Stop Streaming
// Start streaming from a connected device
sdk.startStreaming(deviceId: device.id)
// Stop streaming
sdk.stopStreaming(deviceId: device.id)
Stream States
Each device tracks its streaming state independently:
.idle → .starting → .streaming
→ .stopping → .idle
→ .stalled
→ .unsupported
| State | Description |
|---|---|
.idle | Not streaming |
.starting | Stream initialization in progress |
.streaming | Actively receiving biosignal data |
.stopping | Teardown in progress |
.stalled | Stream interrupted (e.g., temporary signal loss) |
.unsupported | Device does not support streaming |
Receiving Samples
Biosignal samples arrive as .sample events on the SDK's event publisher:
sdk.events.sink { event in
if case .sample(let deviceId, let sample) = event {
print("Signal: \(sample.signalName)")
switch sample.data {
case .waveform(let values):
// Array of sample points (e.g., ECG, PPG, EDA waveforms)
print(" \(values.count) samples")
case .scalar(let value):
// Single value (e.g., heart rate, temperature, SpO2)
print(" Value: \(value)")
}
}
}
Signal Types
The BioSample type includes convenience properties for identifying signal types:
| Property | Signal | Data type |
|---|---|---|
sample.isECG | Electrocardiogram | .waveform |
sample.isPPG | Photoplethysmography | .waveform |
sample.isEDA | Electrodermal activity | .waveform |
sample.isTemp | Skin temperature | .scalar |
sample.isHeartRate | Heart rate (BPM) | .scalar |
sample.isSpO2 | Blood oxygen saturation | .scalar |
sdk.events.sink { event in
if case .sample(_, let sample) = event {
if sample.isHeartRate, let bpm = sample.scalarValue {
print("Heart rate: \(bpm) BPM")
}
if sample.isECG, let waveform = sample.waveform {
// Feed to BioECGChart or your own visualization
updateChart(waveform)
}
}
}
Auto-Stream
Enable auto-stream on a device to automatically start streaming whenever the device connects (including reconnections):
sdk.setAutoStream(deviceId: device.id, enabled: true)
// Check current setting
let isAuto = sdk.autoStreamEnabled(deviceId: device.id)
Data Delivery
The SDK buffers all biosignal data locally and uploads it to the AnyBio platform automatically. Data is persisted across app restarts, so no samples are lost even during network interruptions or app termination.