Giter Site home page Giter Site logo

fstanis / web-toothbrush Goto Github PK

View Code? Open in Web Editor NEW
11.0 2.0 0.0 20 KB

Web Bluetooth based JS library for connecting to a smart toothbrush from your browser

License: MIT License

JavaScript 39.74% TypeScript 60.26%
web-bluetooth web-bluetooth-api toothbrush iot web bluetooth-low-energy

web-toothbrush's Introduction

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

  1. Install using NPM.
npm i web-toothbrush
  1. Import the Toothbrush class.
import { Toothbrush } from 'web-toothbrush'
  1. 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()
  1. Make an instance of Toothbrush.
const toothbrush = new Toothbrush(server)
  1. 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 device
  • deviceType - the type of the device
  • userAccountId - ID of user account
  • batteryLevel - current battery percent
  • data - 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 on
  • buttonState - whether a button is pressed and which
  • mode - current brushing mode
  • pressureSensor - whether a pressure sensor is currently triggered
  • quadrantProperty - the quadrant currently in progress
  • smiley - current "smiley" state
  • state - current toothbrush state

Configuration

These properties can be read or modified to affect the toothbrush behavior.

  • brushingModes - modes that can be triggered and used
  • brushingTimer - how the user is notified about the timer state
  • color - color of the LEDs
  • command - used internally by other properties to send commands
  • flightMode - used to enable or disable flight mode
  • pressure - how the user if notified about the pressure sensor
  • quadrantTimes - how much time is spent per quadrant
  • rtc - current time
  • timezone - current time zone / locale
  • tongueTime - 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.

web-toothbrush's People

Contributors

fstanis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.