Skip to main content

Bracelet Initialization

From SDK 2.0.0.

A bracelet must be initialized on each connection before it accepts commands. Initialization sets the time, authenticates the connection and applies the plan and the sampling rates, in one sequence.

In most apps this is one call at start, and the SDK does the rest:

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

manager.enableAutoInitialization(
InitializationConfig(
braceletPlan = DevicePlan.CONTINUOUS_GREEN_INTERMITTENT_MULTICOLOR,
samplingRate = SampleRate.ONE_MIN,
)
)

:::warning Breaking change in 2.0.0

A command sent to a connected but not-yet-initialized bracelet is rejected with NotInitializedException. This includes downloads and ordinary reads such as get serial number, get battery or get file size. An app upgrading from 1.x that does nothing else will see every command fail until the device is initialized. See Migrating from 1.x below.

:::

What you call and what you get​

You want toCallWhere the result arrives
Initialize every bracelet on every connectionenableAutoInitialization(config, listener) once at startProgress and errors in the optional BraceletInitializationListener
Know whether a bracelet is readybleDevice.isInitializedProperty, true after a successful run on the current connection
Wait until a bracelet is ready, before your own commandsensureInitialized(bleDevice) (suspend)Result<Boolean>
Change the plan or the sampling rates laterupdateConfiguration(bleDevice, config) (suspend)Result<Boolean>
Run the sequence yourselfbraceletInitialization(bleDevice, config) (suspend)Result<Boolean>

All of them are functions of DataSdk.getInstance().getManager(), so they need the data module.

The command gate​

Every request carries a requiresInitialization flag, true by default. When the bracelet is connected but not initialized, any such request fails through the normal error path with a NotInitializedException (in com.corsano.sdk.ble.exceptions).

The requests that make up the initialization sequence itself set the flag to false, so the sequence can run on a fresh connection: SetTimeRequest, GetFwVersionRequest, GetAuthenticationRequest, SetAuthenticationRequest, GetPlanRequest, SetPlanRequest, GetVitalParameterSamplingRateRequest, SetVitalParameterSamplingRateRequest, GetAccelerometerPlan, SetAccelerometerPlan, GetEmoGraphyAndBiozPlan and SetEmographyAndBiozPlan.

Initialization is tracked per connection:

val ready: Boolean = bleDevice.isInitialized

isInitialized resets to false on every disconnection, because firmware authentication does not survive a disconnect. A bracelet must therefore be re-initialized each time it reconnects. The automatic path below does this for you.

From SDK 2.0.0.

Enable it once, early. Application.onCreate(), right after CorsanoSdk.initialize, is the right place. Every bracelet is then initialized as soon as it connects, with no further call from your app. Reconnections are handled too.

DataSdk.getInstance().getManager().enableAutoInitialization(
InitializationConfig(
braceletPlan = DevicePlan.CONTINUOUS_GREEN_INTERMITTENT_MULTICOLOR,
samplingRate = SampleRate.ONE_MIN,
)
)

With auto-initialization on, downloads initialize the bracelet on their own before transferring, so a periodic or triggered file transfer needs no extra work.

What you need to know about a run:

  • It starts when the connection state becomes CONNECTED. Its commands wait for the bond, like all commands (see Pairing).
  • Each command of the sequence gets at most 20 seconds. On the very first connection this includes the time until the bond is complete (the time the user takes to confirm the pairing, when Android asks for it). If the bond takes longer, the run fails with "BLE error set time".
  • When a run fails, the SDK does not repeat it on the same connection by itself. The next download runs it again, and so does your next call of ensureInitialized.
  • If the SDK is locked by its licence check, no bracelet is initialized: the listener's onError and the Result get an SdkLicenceException. See Licence Key.

InitializationConfig​

Bundles the parameters of the initialization sequence.

FieldTypeDefaultDescription
braceletPlanDevicePlan(required)The plan to apply. See Bracelet Plans
samplingRateActivitySampleRate(required)Activity sampling rate
samplingRatePulseRateSampleRate(required)Pulse rate sampling rate
samplingRateRespirationRateSampleRate(required)Respiration rate sampling rate
samplingRateSp02SampleRate(required)SpO2 sampling rate
samplingRateTemperatureSampleRate(required)Temperature sampling rate
ppg2FrequencyPpg2Frequency?nullPPG2 frequency (B2). null means 32 Hz (Ppg2Frequency.THIRTY_TWO_HZ)
isNibpEnabledBooleanfalseEnable NIBP. true sets the NIBP sampling rate to 30 minutes, false turns it off. See NIBP
isAccEnabledBooleanfalseEnable the raw accelerometer (continuous). See Enable raw streams
isBiozOrEmographyEnabledBooleanfalseEnable BioZ and EmoGraphy together (continuous). See Enable raw streams

A secondary constructor applies a single SampleRate to all five vital parameters, which is what most integrations need:

InitializationConfig(
braceletPlan = DevicePlan.CONTINUOUS_GREEN_INTERMITTENT_MULTICOLOR,
samplingRate = SampleRate.ONE_MIN,
isNibpEnabled = true,
)

The sample rates supported are:

SampleRateMeaning
THIRTY_SECSOne value every 30 seconds
ONE_MINOne value every minute
FIVE_MINOne value every 5 minutes
THIRTY_MINOne value every 30 minutes
OFFThe parameter is not sampled

Which rates a plan accepts is described in Bracelet Plans. Use the plan and the rates agreed with Corsano for your project.

InitializationConfig.isStandard() returns false for a combination the bracelet does not support:

  • BioZ / EmoGraphy and NIBP are both enabled, or
  • BioZ / EmoGraphy or NIBP is enabled while PPG2 is at 128 Hz (Ppg2Frequency.HUNDRED_TWENTY_HEIGHT_HZ).

enableAutoInitialization and updateConfiguration refuse such a config, see below.

List of PPG frequencies​

enum class Ppg2Frequency(val braceletValue: Int, val frequency: Int) {
THIRTY_TWO_HZ(1, 32),
SIXTY_FOUR_HZ(2, 64),
HUNDRED_TWENTY_HEIGHT_HZ(3, 128),
TWO_HUNDRED_FIFTY_SIX_HZ(4, 256),
FIVE_HUNDRED_TWELVE_HZ(5, 512);
}

enableAutoInitialization / disableAutoInitialization​

fun enableAutoInitialization(config: InitializationConfig, listener: BraceletInitializationListener? = null)
fun disableAutoInitialization()

The optional listener observes the initialization progress and errors of every device. See BraceletInitializationListener.

enableAutoInitialization does not return a result. If config.isStandard() is false, auto-initialization is not enabled: the function calls listener.onError and returns. Pass a listener, or check isStandard() yourself, to notice this.

note

disableAutoInitialization() stops future automatic runs but does not turn off the command gate. Already-initialized connections keep working; once disabled, initializing a device becomes your responsibility again via braceletInitialization. It also deletes the configuration that updateConfiguration stored.

ensureInitialized​

suspend fun ensureInitialized(bleDevice: BleDevice, listener: BraceletInitializationListener? = null): Result<Boolean>

Initializes the device if it is not already initialized on its current connection, using the config passed to enableAutoInitialization (or the one stored by updateConfiguration). It is idempotent and safe to call from several places: concurrent callers, for instance the on-connect trigger and a starting download, are serialized and share one initialization run.

Returns success if the device is (or becomes) initialized, and failure if it does not. In particular it fails with IllegalStateException if auto-initialization was never enabled.

Call it before issuing reads right after a connection:

manager.ensureInitialized(bleDevice)
.onSuccess {
// safe to read now
bleDevice.awaitCommandV2(GetSerialNumberRequest(), timeout = 10_000)
}
.onFailure { Log.e("Corsano-SDK", "Init failed: $it") }

updateConfiguration​

From SDK 2.1.0.

Changes the bracelet configuration at runtime (a new plan, different sampling rates, NIBP on or off) and re-applies it immediately.

suspend fun updateConfiguration(bleDevice: BleDevice, config: InitializationConfig, listener: BraceletInitializationListener? = null): Result<Boolean>

Unlike ensureInitialized, this does not short-circuit when the device is already initialized: it always re-runs the sequence, which is exactly what you need when the user changes the configuration on an already-set-up bracelet. The new config also replaces the one stored by enableAutoInitialization, so a later reconnection re-applies the new configuration rather than the previous one.

manager.updateConfiguration(
bleDevice,
InitializationConfig(
braceletPlan = DevicePlan.HOSPITAL_MULTICOLOR,
samplingRate = SampleRate.FIVE_MIN,
),
).onSuccess { Log.d("Corsano-SDK", "New configuration applied") }
.onFailure { Log.e("Corsano-SDK", "Reconfigure failed: $it") }

The run is serialized with any concurrent initialization of the same device (the on-connect trigger, a starting download, or another updateConfiguration call), so the change is applied atomically. It returns failure if the sequence does not complete, for example if the bracelet is not connected.

:::warning Incompatible configurations (2.2.0)

Not every combination of options is valid on the bracelet. updateConfiguration rejects a config whose isStandard() is false before contacting the bracelet, returning a failed Result. Check the Result and show the error rather than assuming the change was applied.

:::

:::note Persisted configuration (2.2.0)

The applied config is persisted, so it survives the app process being killed. After a restart and reconnection the bracelet is re-initialized with your last updateConfiguration values rather than the defaults passed to enableAutoInitialization. To go back to the defaults, call disableAutoInitialization() and then enableAutoInitialization(...) again.

:::

Manual initialization​

If you do not use the automatic path, run the sequence yourself once per connection.

suspend fun braceletInitialization(
bleDevice: BleDevice,
config: InitializationConfig,
listener: BraceletInitializationListener? = null
): Result<Boolean>
val result = manager.braceletInitialization(
bleDevice,
InitializationConfig(
braceletPlan = DevicePlan.CONTINUOUS_GREEN_INTERMITTENT_MULTICOLOR,
samplingRate = SampleRate.ONE_MIN,
),
)

Overloads accept the plan and a single SampleRate directly, or every parameter individually, instead of an InitializationConfig. braceletInitialization does not check isStandard().

warning

You must re-run this after every reconnection, because isInitialized resets on disconnect. The automatic path does this for you; if you initialize manually, hook it to the connection state listener yourself.

The sequence​

Every path above runs the same sequence. The time is always written. For the plan, the sampling rates and the raw streams the SDK reads the bracelet's value first and writes only when it differs.

StepWhat the SDK doesStatuses reported
1Sets the bracelet's time (UTC, with the phone's time zone offset)SET_TIME_STARTED, SET_TIME_SUCCESS
2Reads the firmware versionGET_FW_VERSION_STARTED, GET_FW_VERSION_SUCCESS
3Firmware 8.41 or later: reads whether the connection is authenticatedGET_AUTHENTICATION_STATUS_STARTED, GET_AUTHENTICATION_STATUS_DONE
4Only when it is not authenticated: authenticatesSET_AUTHENTICATION_STATUS_STARTED, SET_AUTHENTICATION_STATUS_DONE
5Plan and PPG2 frequencySET_PLAN_STARTED, SET_PLAN_DONE
6Sampling rates: activity, pulse rate, respiration rate, SpO2, temperature, NIBPSET_SAMPLING_RATE_ACTIVITY_*, SET_SAMPLING_RATE_PR_*, SET_SAMPLING_RATE_RR_*, SET_SAMPLING_RATE_SP02_*, SET_SAMPLING_RATE_TEMP_*, SET_SAMPLING_RATE_NIBP_* (each _STARTED, then _DONE)
7Raw accelerometer on or offSET_ACC_FREQUENCY_STARTED, SET_ACC_FREQUENCY_DONE
8BioZ and EmoGraphy on or offSET_BIOZ_EMOGRAPHY_FREQUENCY_STARTED, SET_BIOZ_EMOGRAPHY_FREQUENCY_DONE
EndisInitialized becomes trueDONE_WITH_SUCCESS

The sequence stops at the first step that fails. Each command gets at most 20 seconds.

BraceletInitializationListener​

interface BraceletInitializationListener {
fun onStatusChanged(status: BraceletInitializationStatus)
fun onError(t: Throwable? = null)
}

onStatusChanged reports each step of the sequence, which is useful for a progress UI. The values of BraceletInitializationStatus are:

STARTED, SET_TIME_STARTED, SET_TIME_SUCCESS, GET_FW_VERSION_STARTED, GET_FW_VERSION_SUCCESS, GET_AUTHENTICATION_STATUS_STARTED, GET_AUTHENTICATION_STATUS_DONE, SET_AUTHENTICATION_STATUS_STARTED, SET_AUTHENTICATION_STATUS_DONE, SET_PLAN_STARTED, SET_PLAN_DONE, the SET_SAMPLING_RATE_* pairs (activity, PR, RR, SpO2, temp, NIBP), SET_ACC_FREQUENCY_*, SET_BIOZ_EMOGRAPHY_FREQUENCY_*, and finally DONE_WITH_SUCCESS.

The first status a run reports is SET_TIME_STARTED. The sequence does not report STARTED. The authentication statuses are reported only when that step runs (see the table above), so do not wait for them.

onError is called with the failure if any step fails; the Result from the initialization call is also a failure in that case. The message of the Throwable tells you which step failed:

MessageStep that failed
BLE error set timeSet time. Also the message when the bracelet is not connected or not bonded within 20 seconds
BLE error get FW versionRead the firmware version
BLE error GET authentication (in the Result: BLE error get authentication)Read the authentication status
BLE error SET authenticationAuthenticate. Also when the bracelet refuses the authentication
BLE error set planSet the plan
BLE error set sampling rate activity, ... PR, ... RR, ... Sp02Set that sampling rate
BLE error set sampling rate TEMP (in the Result: BLE error set TEMP rate)Set the temperature sampling rate
BLE error set NIBPSet the NIBP sampling rate
BLE error set ACCSet the raw accelerometer
BLE error set Bioz/EmoGraphySet BioZ and EmoGraphy

When the SDK is locked by its licence check, the error is an SdkLicenceException instead.

After a failure the bracelet stays not initialized. Call ensureInitialized (or your manual call) again; it is safe to repeat.

Firmware authentication​

Authentication is one step of the initialization sequence, so most apps never call it directly. It is documented here because it defines what "initialized" protects.

FW 8.48 requires the connection to be authenticated before it will act on commands. The SDK authenticates using a stable per-phone identifier. The initialization sequence runs the authentication step when the bracelet reports firmware 8.41 or later, and skips it for older firmware.

RequestCommandReturnsPurpose
SetAuthenticationRequest(phoneId)250 (APP_CMD_AUTHENTICATE)BooleanAuthenticate the connection. true when the bracelet accepts it
GetAuthenticationRequest()251 (APP_CMD_GET_AUTH_STATUS)BooleanWhether the connection is already authenticated

The phoneId is any stable per-phone string. Pass Settings.Secure.ANDROID_ID, which is what the initialization sequence does:

val phoneId = Settings.Secure.getString(contentResolver, Settings.Secure.ANDROID_ID)
SetAuthenticationRequest(phoneId)

ANDROID_ID is a 16-hex-character value and maps onto the firmware's 8-byte field directly; any other string is SHA-256 hashed down to 8 bytes, so it is still stable and well distributed. Both SetAuthenticationRequest and GetAuthenticationRequest set requiresInitialization = false, so they run on a fresh connection.

Authentication does not survive a disconnection. This is why isInitialized resets and the bracelet must be re-authenticated on every reconnect.

Migrating from 1.x​

The command gate is on by default in 2.0.0, so an app that neither enables auto-initialization nor calls braceletInitialization gets NotInitializedException on every non-initialization command.

To migrate:

  1. Enable auto-initialization once at startup with your plan and sampling rates:

    class MyApp : Application() {
    override fun onCreate() {
    super.onCreate()
    CorsanoSdk.initialize(this, config)
    DataSdk.getInstance().getManager().enableAutoInitialization(
    InitializationConfig(
    braceletPlan = DevicePlan.CONTINUOUS_GREEN_INTERMITTENT_MULTICOLOR,
    samplingRate = SampleRate.ONE_MIN,
    )
    )
    }
    }
  2. Sequence any reads that ran right after connection (get serial number, battery, file size) after initialization instead of firing them from the connection callback:

    // Before (1.x): read straight after connecting
    // After (2.0.0):
    manager.ensureInitialized(bleDevice).onSuccess {
    bleDevice.awaitCommandV2(GetBatteryLevelRequest(), timeout = 10_000)
    }
  3. If you set the plan or sampling rates manually after connecting, remove that code. The initialization sequence now does it. In 2.0.0 the sample app's DataStartFragment dropped its manual plan / ACC / BioZ / EmoGraphy setup for exactly this reason.

Once auto-initialization is enabled, existing download and summary code keeps working unchanged: downloads initialize the bracelet themselves before transferring.