Git Product home page Git Product logo

ble-central-advertisements's Introduction

ble-central-advertisements

Advertisement parsing utility for cordova-plugin-ble-central.

This module aims to unify core GATT advertising attributes under a single interface, so that we can spend less time parsing mundane Bluetooth GATT / ATT profile specifics and more time making bluetooth apps.

Installation

install from npm via:

npm install -P -E ble-central-advertisements

Usage

import { AdvertisementDecoder } from 'ble-central-advertisements';

const decoder = new AdvertisementDecoder();
const services = [];
const seconds = 30;

function success(advertisement) {

	let parsed = decoder.decode(advertisement);

	// or if you want to leave the advertisement un-mutated
	// let parsed = decoder.decode(advertisement, {});

	console.log(parsed.advDataLocalName);
}

function failure(error) {
	console.log(error);
}

// https://github.com/don/cordova-plugin-ble-central#scan
ble.scan(services, seconds, success, failure);

NOTE: While this module was primarily built to deal with advertising data from the ble-central plugin, it is designed to be general purpose, and can parse raw BLE advertising data provided from any module / plugin (not just from the ble-central plugin).

import { AdvertisementDecoder, Convert } from 'ble-central-advertisements';

const decoder = new AdvertisementDecoder();
const advertisementDataHex = '020106030309181409546865726d6f6d65746572204578616d706c65';
const input = Convert.hexToUint8Array(advertisementDataHex).buffer;
const output = decoder.decode(input);

console.log(output.advDataLocalName); // 'Thermometer Example'

Documentation

Source documentation can be found here

ble-central-advertisements's People

Contributors

jospete avatar

Stargazers

 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.