bluetooth

Kotlin Multiplatform library for talking to Efento bluetooth devices — sensors that take measurements and gateways that forward them on. Runs on Android and iOS from shared code.

Getting started

Initialise the library once, while your application starts:

EfentoBluetooth.init(applicationContext, AndroidLogger())

Then scan for devices, and connect to one to read from it or configure it:

val scanner = EfentoBluetooth.scanner()

scanner.deviceFlow()
.filterIsInstance<Sensor>()
.collect { sensor ->
val connection = when {
sensor.isLegacy -> EfentoBluetooth.sensorLegacyConnection(sensor.id, sensor.bluetoothMacAddress)
else -> EfentoBluetooth.sensorConnection(sensor.id, sensor.bluetoothMacAddress)
}

connection.connect()
try {
val time = connection.commands.getTime()
} finally {
connection.disconnect()
}
}

Scanning already gives you each device's current measurements, so a connection is only needed to read stored measurements, read diagnostics, or change settings.

How the library is organised

PackageWhat it holds
pl.efento.mobile.bluetoothEfentoBluetooth, the entry point
pl.efento.mobile.bluetooth.apiScanning, connections, and each device kind's commands and notifications
pl.efento.mobile.bluetooth.modelDevices, their configuration and the data they report
pl.efento.mobile.bluetooth.measurementMeasurement values and the types a channel can report
pl.efento.mobile.bluetooth.exceptionEverything the library throws
pl.efento.mobile.bluetooth.logLog listener and the ready-made platform loggers

Key concepts

Current and legacy devices. Sensors of software version 7 and later, and current gateways, use one set of interfaces; older ones use a parallel ...Legacy set. Scanning tells you which you have — check Sensor.isLegacy or Gateway.isLegacy and call the matching factory on EfentoBluetooth. The two sets are not interchangeable.

Channels. A device has up to six channels, each with its own sensor and measurement type. Almost everything a device reports is keyed by channel.

Measurements are not always values. Every measurement carries a status alongside its value, and the value is only meaningful when the status says so. Check Measurement.isValid or Measurement.status before using one — a reading can be missing, out of range, or taken before the sensor had stabilised.

Some channels are hidden. Accumulating counters are transmitted across a pair of channels. The library reads both and reports one combined value, so the complementary half never reaches you.

Rules run on the device. A device can watch its own measurements and act without a server, for instance by transmitting early when a threshold is crossed. Those rules are configured through the sensor's commands.

Checking configuration before sending it. Configuration models carry an isValid() that applies the same limits the device does. Calling it first turns a rejected write into a local check.

Error handling

Everything the library throws derives from BluetoothException, so a single catch covers the lot. The subclasses tell you whether the problem is the platform (bluetooth switched off, permission missing), the connection (dropped, timed out), or the request itself (a command the device's firmware does not support). Commands suspend until the device replies or the connection drops, so wrap them in withTimeout if you need a deadline.

Kotlin Multiplatform library for talking to Efento bluetooth devices — sensors that take measurements and gateways that forward them on. Runs on Android and iOS from shared code.

Getting started

Initialise the library once, while your application starts:

EfentoBluetooth.init(applicationContext, AndroidLogger())

Then scan for devices, and connect to one to read from it or configure it:

val scanner = EfentoBluetooth.scanner()

scanner.deviceFlow()
.filterIsInstance<Sensor>()
.collect { sensor ->
val connection = when {
sensor.isLegacy -> EfentoBluetooth.sensorLegacyConnection(sensor.id, sensor.bluetoothMacAddress)
else -> EfentoBluetooth.sensorConnection(sensor.id, sensor.bluetoothMacAddress)
}

connection.connect()
try {
val time = connection.commands.getTime()
} finally {
connection.disconnect()
}
}

Scanning already gives you each device's current measurements, so a connection is only needed to read stored measurements, read diagnostics, or change settings.

How the library is organised

PackageWhat it holds
pl.efento.mobile.bluetoothEfentoBluetooth, the entry point
pl.efento.mobile.bluetooth.apiScanning, connections, and each device kind's commands and notifications
pl.efento.mobile.bluetooth.modelDevices, their configuration and the data they report
pl.efento.mobile.bluetooth.measurementMeasurement values and the types a channel can report
pl.efento.mobile.bluetooth.exceptionEverything the library throws
pl.efento.mobile.bluetooth.logLog listener and the ready-made platform loggers

Key concepts

Current and legacy devices. Sensors of software version 7 and later, and current gateways, use one set of interfaces; older ones use a parallel ...Legacy set. Scanning tells you which you have — check Sensor.isLegacy or Gateway.isLegacy and call the matching factory on EfentoBluetooth. The two sets are not interchangeable.

Channels. A device has up to six channels, each with its own sensor and measurement type. Almost everything a device reports is keyed by channel.

Measurements are not always values. Every measurement carries a status alongside its value, and the value is only meaningful when the status says so. Check Measurement.isValid or Measurement.status before using one — a reading can be missing, out of range, or taken before the sensor had stabilised.

Some channels are hidden. Accumulating counters are transmitted across a pair of channels. The library reads both and reports one combined value, so the complementary half never reaches you.

Rules run on the device. A device can watch its own measurements and act without a server, for instance by transmitting early when a threshold is crossed. Those rules are configured through the sensor's commands.

Checking configuration before sending it. Configuration models carry an isValid() that applies the same limits the device does. Calling it first turns a rejected write into a local check.

Error handling

Everything the library throws derives from BluetoothException, so a single catch covers the lot. The subclasses tell you whether the problem is the platform (bluetooth switched off, permission missing), the connection (dropped, timed out), or the request itself (a command the device's firmware does not support). Commands suspend until the device replies or the connection drops, so wrap them in withTimeout if you need a deadline.

Kotlin Multiplatform library for talking to Efento bluetooth devices — sensors that take measurements and gateways that forward them on. Runs on Android and iOS from shared code.

Getting started

Initialise the library once, while your application starts:

EfentoBluetooth.init(applicationContext, AndroidLogger())

Then scan for devices, and connect to one to read from it or configure it:

val scanner = EfentoBluetooth.scanner()

scanner.deviceFlow()
.filterIsInstance<Sensor>()
.collect { sensor ->
val connection = when {
sensor.isLegacy -> EfentoBluetooth.sensorLegacyConnection(sensor.id, sensor.bluetoothMacAddress)
else -> EfentoBluetooth.sensorConnection(sensor.id, sensor.bluetoothMacAddress)
}

connection.connect()
try {
val time = connection.commands.getTime()
} finally {
connection.disconnect()
}
}

Scanning already gives you each device's current measurements, so a connection is only needed to read stored measurements, read diagnostics, or change settings.

How the library is organised

PackageWhat it holds
pl.efento.mobile.bluetoothEfentoBluetooth, the entry point
pl.efento.mobile.bluetooth.apiScanning, connections, and each device kind's commands and notifications
pl.efento.mobile.bluetooth.modelDevices, their configuration and the data they report
pl.efento.mobile.bluetooth.measurementMeasurement values and the types a channel can report
pl.efento.mobile.bluetooth.exceptionEverything the library throws
pl.efento.mobile.bluetooth.logLog listener and the ready-made platform loggers

Key concepts

Current and legacy devices. Sensors of software version 7 and later, and current gateways, use one set of interfaces; older ones use a parallel ...Legacy set. Scanning tells you which you have — check Sensor.isLegacy or Gateway.isLegacy and call the matching factory on EfentoBluetooth. The two sets are not interchangeable.

Channels. A device has up to six channels, each with its own sensor and measurement type. Almost everything a device reports is keyed by channel.

Measurements are not always values. Every measurement carries a status alongside its value, and the value is only meaningful when the status says so. Check Measurement.isValid or Measurement.status before using one — a reading can be missing, out of range, or taken before the sensor had stabilised.

Some channels are hidden. Accumulating counters are transmitted across a pair of channels. The library reads both and reports one combined value, so the complementary half never reaches you.

Rules run on the device. A device can watch its own measurements and act without a server, for instance by transmitting early when a threshold is crossed. Those rules are configured through the sensor's commands.

Checking configuration before sending it. Configuration models carry an isValid() that applies the same limits the device does. Calling it first turns a rejected write into a local check.

Error handling

Everything the library throws derives from BluetoothException, so a single catch covers the lot. The subclasses tell you whether the problem is the platform (bluetooth switched off, permission missing), the connection (dropped, timed out), or the request itself (a command the device's firmware does not support). Commands suspend until the device replies or the connection drops, so wrap them in withTimeout if you need a deadline.

Packages

Link copied to clipboard
apple
common

Entry point of the library. EfentoBluetooth initialises it and creates scanners and connections; everything else starts here.

Link copied to clipboard
common

Scanning and connections, plus the commands and notifications each kind of device supports.

Link copied to clipboard
common

Everything the library throws. All of it derives from BluetoothException.

Link copied to clipboard
apple
common

Log listener interface and the platform loggers built on it.

Link copied to clipboard
common

Measurement values and the types a channel can report.

Link copied to clipboard
common

Devices as scanning reports them, the configuration you can read and write, and the diagnostics a device keeps about itself.

common
Link copied to clipboard
common
common
Link copied to clipboard
common
common
common