web-toothbrush
v0.1.0
Published
Web Bluetooth based JS library for connecting to a smart toothbrush from your browser
Downloads
253
Maintainers
Readme
web-toothbrush
Yet another IoT JS library nobody asked for
Overview
This library is unofficial and I'm in no way associated with the manufacturers of these devices. Use at your own risk.
This is a simple JavaScript library that uses the Web Bluetooth API to connect a smart electric toothbrush that supports bluetooth.
Depending on the model allows you to read the current status during a session, modify settings or read data from previous sessions.
Usage
- Install using NPM.
npm i web-toothbrush
- Import the
Toothbrush
class.
import { Toothbrush } from 'web-toothbrush'
- Connect to your device and receive a
BluetoothRemoteGATTServer
object.
// This displays a dialog to the user
const device = await navigator.bluetooth.requestDevice({
acceptAllDevices: true,
optionalServices: Toothbrush.services // contains list of GATT services used
})
// Connect to the GATT server
const server = await device.gatt.connect()
- Make an instance of
Toothbrush
.
const toothbrush = new Toothbrush(server)
- Query some properties.
const batteryLife = toothbrush.getProperty('batteryLevel')
if (!await batteryLife.isAvailable()) {
// tough luck, we can't query that property
}
console.log(await batteryLife.readValue())
Simple version
In most cases, you can just use Toothbrush.connect()
if you don't want to worry about all the bluetooth connection trouble:
import { Toothbrush } from 'web-toothbrush'
[...]
const toothbrush = await Toothbrush.connect()
const batteryLife = toothbrush.getProperty('batteryLevel')
[...]
Supported properties
The following properties can be accessed via the bluetooth API. Availability depends on the model of your device.
General information
All of these properties are read-only.
handleId
- the unique ID of the devicedeviceType
- the type of the deviceuserAccountId
- ID of user accountbatteryLevel
- current battery percentdata
- information about previous saved sessions
Current session
These properties are read only, but can be subscribed to and reflect the status of the current session in progress.
brushingTime
- how long the toothbrush has been onbuttonState
- whether a button is pressed and whichmode
- current brushing modepressureSensor
- whether a pressure sensor is currently triggeredquadrantProperty
- the quadrant currently in progresssmiley
- current "smiley" statestate
- current toothbrush state
Configuration
These properties can be read or modified to affect the toothbrush behavior.
brushingModes
- modes that can be triggered and usedbrushingTimer
- how the user is notified about the timer statecolor
- color of the LEDscommand
- used internally by other properties to send commandsflightMode
- used to enable or disable flight modepressure
- how the user if notified about the pressure sensorquadrantTimes
- how much time is spent per quadrantrtc
- current timetimezone
- current time zone / localetongueTime
- how much time is spent in tongue cleaning mode
Supported devices
The following toothbrushes are currently supported by this library:
- Oral-B Genius 9000
- Oral-B Genius 8000
- Oral-B Teen
- Oral-B SmartSeries 6500
- Oral-B Smart 5 5000N
Please refer to Web Bluetooth Community Group's Implementation Status to see which platforms currently support the (experimental) Web Bluetooth API.