GithubHelp home page GithubHelp logo

creativekodes / cordova-plugin-ble-peripheral Goto Github PK

View Code? Open in Web Editor NEW

This project forked from don/cordova-plugin-ble-peripheral

0.0 1.0 1.0 44 KB

Apache Cordova plugin for implementing BLE (Bluetooth Low Energy) peripherals.

License: Other

Objective-C 33.31% JavaScript 14.51% Java 52.18%

cordova-plugin-ble-peripheral's Introduction

Bluetooth Low Energy (BLE) Peripheral Plugin for Apache Cordova

A Cordova plugin for implementing BLE (Bluetooth Low Energy) peripherals.

Need a BLE central module? See cordova-plugin-ble-central.

Supported Platforms

  • iOS
  • Android

Usage

Callbacks

Register callbacks to receive notifications from the plugin

blePeripheral.onWriteRequest(app.didReceiveWriteRequest);
blePeripheral.onBluetoothStateChange(app.onBluetoothStateChange);

Defining services with JSON

Define your Bluetooth Service using JSON

var uartService = {
    uuid: SERVICE_UUID,
    characteristics: [
        {
            uuid: TX_UUID,
            properties: property.WRITE,
            permissions: permission.WRITEABLE,
            descriptors: [
                {
                    uuid: '2901',
                    value: 'Transmit'
                }
            ]
        },
        {
            uuid: RX_UUID,
            properties: property.READ | property.NOTIFY,
            permissions: permission.READABLE,
            descriptors: [
                {
                    uuid: '2901',
                    value: 'Receive'
                }
            ]
        }
    ]
};

Create the service and start advertising

Promise.all([
    blePeripheral.createServiceFromJSON(uartService),
    blePeripheral.startAdvertising(uartService.uuid, 'UART')
]).then(
    function() { console.log ('Created UART Service'); },
    app.onError
);

Defining services programatically

Instead of using JSON, you can create services programtically. Note that for 1.0 descriptors are only supported with the JSON format.

Promise.all([
    blePeripheral.createService(SERVICE_UUID),
    blePeripheral.addCharacteristic(SERVICE_UUID, TX_UUID, property.WRITE, permission.WRITEABLE),
    blePeripheral.addCharacteristic(SERVICE_UUID, RX_UUID, property.READ | property.NOTIFY, permission.READABLE),
    blePeripheral.publishService(SERVICE_UUID),
    blePeripheral.startAdvertising(SERVICE_UUID, 'UART')
]).then(
    function() { console.log ('Created UART Service'); },
    app.onError
);

Examples

See the examples for more ideas on how this plugin can be used.

Installing

Cordova

$ cordova plugin add cordova-plugin-ble-peripheral

PhoneGap

$ phonegap plugin add cordova-plugin-ble-peripheral

PhoneGap Build

Edit config.xml to install the plugin for PhoneGap Build.

<gap:plugin name="cordova-plugin-ble-peripheral" source="npm" />

License

Apache 2.0

Feedback

Try the code. If you find an problem or missing feature please create a github issue. When you're submitting an issue please include a sample project that recreates the problem.

cordova-plugin-ble-peripheral's People

Contributors

don avatar lucatorella avatar whebcraft avatar

Watchers

 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.