Sleep settings
287-2B only
Sleep monitoring needs two things on the bracelet: a plan that records sleep, and a bedtime and a rise time. Both are set with the commands of Bracelet init and setup. This page says what the bracelet does with them. How the SDK turns the night into a summary is on Sleep processing.
Bracelet Plan
The sleep monitoring is enabled according to the plan set to the bracelet. Set the plan with InitializationConfig.braceletPlan: see Set bracelet plan, and Bracelet Plans for which plans record sleep.
Bedtime / Risetime
The sleep monitoring uses the bracelet battery, and to avoid a high consumption, the sleep is not monitored all day long. This is why it is important to set a theoretical bedtime and rise time to the bracelet.
Set them with SetBedtimeRequest and SetRisetimeRequest, in GMT. The commands, the conversion from local time and an example are on Bedtime / risetime.
What the bracelet does with them (this is the bracelet's firmware, not the SDK):
- It monitors sleep from 2 hours before the bedtime.
- From 2 hours before the rise time, it looks for activity of the user to end the session (see Sleep Stop).
- It ends the session at the latest 3 hours after the rise time.
The 287-2B also has commands for a bedtime and a rise time per day (CommandId.APP_CMD_SET_SLEEP_SCHEDULE and APP_CMD_GET_SLEEP_SCHEDULE, firmware 9.47 or later), but SDK 3.0.0 has no public request for them: use SetBedtimeRequest and SetRisetimeRequest.
Sleep Stop
The bracelet ends the sleep session by itself in the morning, once the user has walked 250 steps. If the user does not reach 250 steps, the bracelet ends it 3 hours after the rise time. This is the bracelet's behaviour, not the SDK's.
Your app can end the session earlier, for example from a "Stop sleep now" button, with manager.sendStopSleep(bleDevice, onSuccess, onError). See Manual Stop sleep.
The night is built and saved after the session has ended, by the downloads that follow. See Sleep analysis.
Sleep session
How the SDK builds a night from the bracelet's records (one-minute slots, markers, totals) is described under Sleep session on the Sleep processing page.
SleepSettings
SleepSettings (com.corsano.sdk.data.sleep) is a set of nine values that the SDK stores for your app in its database.
The SDK does not use these values. They are not sent to the bracelet, and they do not change the sleep monitoring or the night's summary: sleepNeedDuration stays 7 hours whatever sleepGoalMinutes says. To set the bedtime and the rise time on the bracelet, use the commands under Bedtime / Risetime.
Get them with SleepSettings.load; there is no public constructor. Since 3.0.0 load replaces the SleepSettings(realm) constructor of 2.x.
// In a coroutine: throws when the settings cannot be read, or when DataSdk is not initialized
val settings = SleepSettings.load()
// With callbacks, on the callback scheduler (the main thread by default)
SleepSettings.load(
result = { settings -> show(settings.sleepGoalMinutes) },
onError = { error -> Log.e("Corsano-SDK", "Sleep settings not read: $error") },
)
loadreads on the SDK's database thread, so you can call it from the main thread. It waits until the import of the data of SDK 2.x is over (see Migrating to 3.0).onErroris called when the database cannot be opened. The callback version throwsIllegalStateExceptionat once whenDataSdkis not initialized.- Pass
resultby name, as above: a trailing lambda would be taken asonError.
Each value is an Int you can read and write. A value that was never set reads as -1. A write changes the value in the object at once and is stored in the database in the background. Another SleepSettings object, loaded earlier, does not see the change.
| Property | Type |
|---|---|
sleepGoalMinutes | Int |
sleepCatchUp | Int |
sleepCatchUpMinutes | Int |
sleepIntensity | Int |
sleepIntensityMinutes | Int |
bedTimeGmtHour | Int |
bedTimeGmtMinute | Int |
riseTimeGmtHour | Int |
riseTimeGmtMinute | Int |
Sleep process technically:
From SDK 2.2.0, the sleep session is computed on the bracelet ("Corsano sleep"). While the user sleeps the bracelet records and analyses the night itself; once the session is finished the SDK downloads it during a normal sync, the same way it downloads any other data, and builds the night's summary. There is no .wiff sleep parsing on the phone any more, and the bundled Philips library is removed.
See Sleep processing for the full flow and, if you are upgrading from 2.1.x, the migration steps.