All Projects → manekinekko → Angular Web Bluetooth

manekinekko / Angular Web Bluetooth

Licence: mit
The missing Web Bluetooth module for Angular

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects
javascipt
17 projects

Projects that are alternatives of or similar to Angular Web Bluetooth

Web Bluetooth Terminal
Progressive Web Application for serial communication with your own Bluetooth Low Energy (Smart) devices
Stars: ✭ 130 (-20.73%)
Mutual labels:  bluetooth-low-energy, iot, bluetooth
Nimble Arduino
A fork of the NimBLE library structured for compilation with Ardruino, designed for use with ESP32.
Stars: ✭ 108 (-34.15%)
Mutual labels:  bluetooth-low-energy, bluetooth-le, bluetooth
Blynk Library
Blynk library for embedded hardware. Works with Arduino, ESP8266, Raspberry Pi, Intel Edison/Galileo, LinkIt ONE, Particle Core/Photon, Energia, ARM mbed, etc.
Stars: ✭ 3,305 (+1915.24%)
Mutual labels:  bluetooth-low-energy, iot, bluetooth
pirowflo
All-in-one data interface for your Waterrower S4 Monitor or Smartrow
Stars: ✭ 73 (-55.49%)
Mutual labels:  bluetooth, bluetooth-low-energy, bluetooth-le
Node Ble
Bluetooth Low Energy (BLE) library written with pure Node.js (no bindings) - baked by Bluez via DBus
Stars: ✭ 159 (-3.05%)
Mutual labels:  bluetooth-low-energy, bluetooth-le, bluetooth
IOS-DFU-Library
OTA DFU Library for Mac and iOS, compatible with nRF5x SoCs
Stars: ✭ 400 (+143.9%)
Mutual labels:  bluetooth, bluetooth-low-energy, bluetooth-le
Ble.net
Cross-platform Bluetooth Low Energy (BLE) library for Android, iOS, and UWP
Stars: ✭ 137 (-16.46%)
Mutual labels:  bluetooth-low-energy, bluetooth-le, bluetooth
py-bluetooth-utils
Python module containing bluetooth utility functions, in particular for easy BLE scanning and advertising
Stars: ✭ 60 (-63.41%)
Mutual labels:  bluetooth, bluetooth-low-energy, bluetooth-le
Bluetoothlinux
Pure Swift Linux Bluetooth Stack
Stars: ✭ 149 (-9.15%)
Mutual labels:  bluetooth-low-energy, iot, bluetooth
Bleu
BLE (Bluetooth LE) for U🎁 Bleu is the best in the Bluetooth library.
Stars: ✭ 481 (+193.29%)
Mutual labels:  bluetooth-low-energy, bluetooth-le, bluetooth
ruuvitag-demo
Demo of reading Bluetooth Low Energy sensor measurements of RuuviTag environmental sensors and feeding them to MQTT, a database and dashboards
Stars: ✭ 14 (-91.46%)
Mutual labels:  bluetooth, bluetooth-low-energy, bluetooth-le
Easyble
Android BLE framework
Stars: ✭ 155 (-5.49%)
Mutual labels:  bluetooth-low-energy, bluetooth-le, bluetooth
BleLab
Bluetooth LE Lab - UWP application for interaction with BLE GATT devices
Stars: ✭ 68 (-58.54%)
Mutual labels:  bluetooth, bluetooth-low-energy, bluetooth-le
Xiaomi Flower Care Api
Xiaomi Flower Care (MiFlora) API wrapper.
Stars: ✭ 111 (-32.32%)
Mutual labels:  bluetooth-low-energy, sensor, iot
PiBeacon
Low-cost iBeacon using Raspberry Pi
Stars: ✭ 41 (-75%)
Mutual labels:  bluetooth, bluetooth-low-energy, bluetooth-le
Ios Pods Dfu Library
OTA DFU Library for Mac and iOS, compatible with nRF5x SoCs
Stars: ✭ 349 (+112.8%)
Mutual labels:  bluetooth-low-energy, bluetooth-le, bluetooth
Radareeye
A tool made for specially scanning nearby devices[BLE, Bluetooth & Wifi] and execute our given command on our system when the target device comes in-between range.
Stars: ✭ 218 (+32.93%)
Mutual labels:  bluetooth-low-energy, iot, bluetooth
Gatt Python
Bluetooth GATT SDK for Python
Stars: ✭ 233 (+42.07%)
Mutual labels:  bluetooth-low-energy, bluetooth-le, bluetooth
Gort
Command Line Interface (CLI) for RobotOps
Stars: ✭ 425 (+159.15%)
Mutual labels:  bluetooth-low-energy, iot, bluetooth
Ehal
Embedded Hardware Abstraction Library
Stars: ✭ 84 (-48.78%)
Mutual labels:  bluetooth-low-energy, sensor, iot

The missing Web Bluetooth module for Angular

Install

npm install -S @manekinekko/angular-web-bluetooth @types/web-bluetooth

Note: Make also sure the @types/web-bluetooth is installed correctly in your node_modules.

Getting started

1) import the WebBluetoothModule module

import { NgModule } from '@angular/core';
import { WebBluetoothModule } from '@manekinekko/angular-web-bluetooth';

@NgModule({
  imports: [
    //...,
    WebBluetoothModule.forRoot({
      enableTracing: true // or false, this will enable logs in the browser's console
    })
  ]
  //...
})
export class AppModule {}

2.a) use it in your service/component (the easiest way)

Here is an annotated example using the BluetoothCore service:

import { Injectable } from '@angular/core';
import { BluetoothCore } from '@manekinekko/angular-web-bluetooth';
import { map } from 'rxjs/operators';

@Injectable({
  providedIn: 'root'
})
export class BatteryLevelService {

  constructor(public readonly ble: BluetoothCore) {}

  getDevice() {
    // call this method to get the connected device
    return this.ble.getDevice$();
  }

  stream() {
    // call this method to get a stream of values emitted by the device for a given characteristic
    return this.ble.streamValues$().pipe(
      map((value: DataView) => value.getInt8(0))
    );
  }

  disconnectDevice() {
    // call this method to disconnect from the device. This method will also stop clear all subscribed notifications
    this.ble.disconnectDevice();
  }

  value() {
    console.log('Getting Battery level...');

    return this.ble
      .value$({
        service: 'battery_service',
        characteristic: 'battery_level'
      });
  }

}

2.b) use it in your service/component (the advanced way)

Here is an annotated example using the BluetoothCore service:

import { Injectable } from '@angular/core';
import { map, mergeMap } from 'rxjs/operators';
import { BluetoothCore } from '@manekinekko/angular-web-bluetooth';

@Injectable({
  providedIn: 'root'
})
export class BatteryLevelService {
  static GATT_CHARACTERISTIC_BATTERY_LEVEL = 'battery_level';
  static GATT_PRIMARY_SERVICE = 'battery_service';

  constructor(public ble: BluetoothCore) {}

  getDevice() {
    // call this method to get the connected device
    return this.ble.getDevice$();
  }

  stream() {
    // call this method to get a stream of values emitted by the device
    return this.ble.streamValues$().pipe(map((value: DataView) => value.getUint8(0)));
  }

  disconnectDevice() {
    this.ble.disconnectDevice();
  }

  /**
   * Get Battery Level GATT Characteristic value.
   * This logic is specific to this service, this is why we can't abstract it elsewhere.
   * The developer is free to provide any service, and characteristics they want.
   *
   * @return Emites the value of the requested service read from the device
   */
  value() {
    console.log('Getting Battery level...');

    return this.ble

        // 1) call the discover method will trigger the discovery process (by the browser)
        .discover$({
          acceptAllDevices: true,
          optionalServices: [BatteryLevelService.GATT_PRIMARY_SERVICE]
        })
        .pipe(

          // 2) get that service
          mergeMap((gatt: BluetoothRemoteGATTServer) => {
            return this.ble.getPrimaryService$(gatt, BatteryLevelService.GATT_PRIMARY_SERVICE);
          }),

          // 3) get a specific characteristic on that service
          mergeMap((primaryService: BluetoothRemoteGATTService) => {
            return this.ble.getCharacteristic$(primaryService, BatteryLevelService.GATT_CHARACTERISTIC_BATTERY_LEVEL);
          }),

          // 4) ask for the value of that characteristic (will return a DataView)
          mergeMap((characteristic: BluetoothRemoteGATTCharacteristic) => {
            return this.ble.readValue$(characteristic);
          }),

          // 5) on that DataView, get the right value
          map((value: DataView) => value.getUint8(0))
        )
  }
}

API documentation

The API documentation can be found here: https://manekinekko.github.io/angular-web-bluetooth/

Need a starter?

This project serves also as a starter. Run the following command:

npm start

Blog post

Checkout my full blog post on dev.to about how to use this package in your app.

Have a PR?

All contributions are welcome. Here are few open issues that I need help with ;)

License

The MIT License (MIT) Copyright (c) 2017 - Wassim CHEGHAM

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].