sandropaganotti / jsgatt

JSGatt adds some syntactic sugar on top of the web bluetooth api
MIT License
12 stars 0 forks source link
gatt webbluetooth

Build Status styled with prettier

JSGatt

JSGatt adds some syntactic sugar on top of the web bluetooth api.

import Device from 'jsgatt';

const phone = new Device();
const battery = phone.register(
  'battery_service', // service name or UID
  'battery_level' // characteristic name or UID
);

document.querySelector('button').addEventListener('click', function(){
  battery().then(value => {
    if (value.getUint8(0) < 20) {
      alert('low battery!');
    }
  });
});

Features

✓ shorter syntax
✓ auto reconnection
✓ caches characteristics
✓ aggregates services for the same device
✓ prevents writing if another writing is in progress
✓ handles accessing a characteristic while the device is still connecting

API

Examples

Check your browser support for web bluetooth before running.

Slides

I made a few slides to explain and detail the examples, you can find them on slides.com.