Notifications (Ping)
The bracelet sends a notification (or ping) by itself when some events occur. Your app does not ask for them: it listens.
| Notification | Class | When the bracelet sends it |
|---|---|---|
| Regular Ping | Notification.RegularPing | Every minute |
| Instant data Ping (B2 only) | Notification.RealTimePing | Regularly, once you have enabled it |
| Charger event Ping | Notification.ChargingEventPing | When the bracelet is put on or taken off the charger |
| Live HRM | Notification.LiveHrm | In workout mode |
The bracelet must be connected. Notifications are live values: the SDK does not store them, and a ping that the bracelet sends while it is not connected is not delivered later. The stored measurements arrive with the data transfer.
How to register to these events?
- Observe notifications:
import com.corsano.sdk.ble.command.observeNotifications
import com.corsano.sdk.ble.command.observeNotificationsOfType
val bleDevice = BleSdk.getInstance().getDevice(address)
// all notifications
val listener = bleDevice.observeNotifications { notification ->
when (notification) {
is Notification.RegularPing -> { /* ... */ }
is Notification.RealTimePing -> { /* ... */ }
is Notification.ChargingEventPing -> { /* ... */ }
else -> { /* a type you do not use */ }
}
}
// or one type only
bleDevice.observeNotificationsOfType<Notification.RealTimePing> { ping ->
Log.d("Corsano-SDK", "Heart rate ${ping.hrm} bpm, quality ${ping.hrmQ}")
}
- The values arrive in the lambda. The SDK calls it on its callback scheduler (the main thread by default).
- You can register before the bracelet is connected. The listener stays registered across reconnections.
- To stop listening, pass the returned listener to
bleDevice.notifications.removeNotificationListener(listener). - With coroutines and the
datamodule you can usebleDevice.notificationFlow()(com.corsano.sdk.data.util) instead. - Keep the
elsebranch: a new SDK version can add a notification type.
1 - Regular Ping
Ping sent by the bracelet every minute, this triggers the data download. It is not necessary to listen to this event, but it is a good indication of the connection quality.
data class RegularPing(
val batteryLevel: Int,
val ppgSize: Int,
val activitySize: Int,
val hrvSize: Int,
val workoutSize: Int,
val sleepSize: Int,
val logSize: Int
) : Notification()
| Field | Description |
|---|---|
batteryLevel | The battery level the bracelet sends with the ping |
ppgSize, activitySize, hrvSize, workoutSize, sleepSize, logSize | The sizes of these files as the bracelet sends them with the ping. For the size of a file in bytes, use GetFileSizeRequest |
The download that a ping starts
When the automatic data transfer is active for a bracelet, each regular ping starts a download. You do not have to do anything. From SDK 3.0.0 a ping does not start a download:
- within a minute of the start of the previous download (less 5 seconds, for the timing of the ping),
- while the bracelet is pairing,
- after the bracelet refused the authentication or did not answer it,
- while the SDK is locked by its licence check, see Licence Key.
The next ping tries again. A download that you start yourself with triggerDownload is not held back by the first three rules.
2 - Instant data (B2 only)
Available starting SDK 0.8.8
Only for B2 bracelets
What are the instant data?
The instant data is a set of live values such as the heart rate, the respiration rate and the battery level. They come regularly, without a sync.
The bracelet needs to be connected and the instant data must be enabled (see How to implement it).
Then this set of data will come automatically every 25 seconds. You can read and change the period, see below.
data class RealTimePing(
val timestampSecs: Long, // in secs
val hrm: Int,
val hrmQ: Int,
val respRate: Float,
val respRateQ: Int,
val spo2: Int,
val spo2Q: Int,
val coreBodyTemp: Float,
val movementLevel: Int,
val batteryLevel: Int
) : Notification()
| Field | Description |
|---|---|
timestampSecs | Time of the values, in seconds since 1970-01-01 UTC |
hrm | Heart rate, in beats per minute |
hrmQ | Quality of the heart rate, see Quality |
respRate | Respiration rate, in steps of 0.25 (the bracelet sends the value multiplied by 4) |
respRateQ | Quality of the respiration rate |
spo2 | SpO2 |
spo2Q | Quality of the SpO2 value. SpO2 has additional quality values, see Quality |
coreBodyTemp | Temperature in °C, in steps of 0.01 °C (the bracelet sends the value multiplied by 100). To display it, round it as described in Temperature resolution and rounding |
movementLevel | 0 to 4. 0 = not moving much, 4 = lots of movements |
batteryLevel | Battery level in percent. See the note below |
In this example the bracelet has no respiration rate and no SpO2 value: both are 0, with quality 0.
Example:
RealTimePing(timestampSecs=1697104452, hrm=86, hrmQ=1, respRate=0.0, respRateQ=0, spo2=0, spo2Q=0, coreBodyTemp=29.66, movementLevel=4, batteryLevel=61)
Use a value only when its quality is good enough for your purpose, see Quality and alerts.
batteryLevel is the byte as the bracelet sends it, read as a number from 0 to 255. While the bracelet is on the charger it can be above 100. For a battery level you can rely on, use GetBatteryLevelRequest or the charger event ping.
How to implement it
The commands need an initialized bracelet.
- Enable it
bleDevice.enqueueCommand(
request = SetRealTimePingEnableRequest(true),
onSuccess = { acknowledged -> Log.d("Corsano-SDK", "Instant data enabled: $acknowledged") },
onError = { error -> Log.e("Corsano-SDK", "Instant data not enabled: $error") }
)
Pass false to disable it.
- Get value on device
bleDevice.enqueueCommand(
request = GetRealTimeEnabledRequest(),
onSuccess = { enabled -> Log.d("Corsano-SDK", "Instant data enabled? $enabled") },
onError = { error -> Log.e("Corsano-SDK", "Not read: $error") }
)
- Read or change the period
GetRealTimePeriodRequest() returns the period in seconds. SetRealTimePingPeriodRequest(periodSecs) sets it; periodSecs must be between 0 and 255. The sample app offers 1, 5, 10, 30, 60 and 120 seconds.
- Receive the values
Register a listener as shown in How to register to these events?. Each ping arrives as a Notification.RealTimePing.
Full code sample in the sample app file:
DataStartFragment.kt
3 - Charger event ping
From SDK 0.9.9
Triggered when the bracelet is put on or taken off the charger
Data structure:
data class ChargingEventPing(
val percentage: Int,
val voltageMillivolts: Int,
val isCharging: Boolean
) : Notification()
| Field | Description |
|---|---|
percentage | Battery level in percent |
voltageMillivolts | Battery voltage in millivolts |
isCharging | true when the bracelet is on the charger (also when the battery is already full), false when it is not |
4 - Live HRM
The bracelet sends this ping in workout mode.
data class LiveHrm(
val energy: Int,
val maxHrm: Int,
val speed: Int,
val duration: Int,
val batteryLevel: Int,
val hrm: Int,
val hrmQ: Int,
val steps: Int,
val averageHrm: Int,
val averageSpeed: Int
) : Notification()