GithubHelp home page GithubHelp logo

avlos / cordova-plugin-ble-nordic Goto Github PK

View Code? Open in Web Editor NEW

This project forked from chris-guidry/cordova-plugin-ble-central

0.0 0.0 0.0 576 KB

BLE plugin for Apache Cordova with DFU capabilities for Nordic nRF5x devices.

License: Other

JavaScript 10.92% Java 48.20% Objective-C 38.73% C# 2.15%

cordova-plugin-ble-nordic's Introduction

BLE plugin for Apache Cordova with Nordic DFU

This plugin updates the fxe-gear/cordova-plugin-ble-central plugin to include the latest changes from don/cordova-plugin-ble-central.

There are two additional changes:

  1. When connecting, first unpair the device, which allows certain LG and Motorola phones to connect repeatedly. Some models need to reestablish the bonding information each time they connect.
  2. When connecting, set the connection priority to high to increase the data transfer speed.

This plugin enables communication between a phone and Bluetooth Low Energy (BLE) peripherals. It is a fork of excellent don/cordova-plugin-ble-central plugin enriched with Nordic Semiconductors Android and iOS DFU libraries.

For the main documentation, please visit the base plugin GitHub page. This page covers only additional installation requirements and extended API.


Requirements

For using this plugin on iOS, there are some additional requirements:

  • cordova version >= 6.4
  • cordova-ios version >=4.3.0
  • CocoaPods

Installing

$ cordova plugin add https://github.com/avlos/cordova-plugin-ble-nordic.git

Extended API

Methods

upgradeFirmware

Upgrade a peripheral firmware.

ble.upgradeFirmware(device_id, uri, progress, failure);

Description

Function upgradeFirmware upgrades peripheral firmware using the Nordic Semiconductors' proprietary DFU protocol (hence only Nordic nRF5x series devices can be upgraded). It uses the official DFU libraries for each platform and wraps them for use with Apache Cordova. Currently only supported firmware format is a ZIP file prepared using Nordic CLI utilities.

The function presumes a connected BLE peripheral. A progress callback is called multiple times with upgrade status info, which is a JSON object of the following format:

{
    "status": "--machineFriendlyString--"
}

A complete list of possible status strings is:

  • deviceConnecting
  • deviceConnected
  • enablingDfuMode
  • dfuProcessStarting
  • dfuProcessStarted
  • firmwareUploading
  • progressChanged - extended status info
  • firmwareValidating
  • dfuCompleted
  • deviceDisconnecting
  • deviceDisconnected - the last callback on successful upgrade
  • dfuAborted - the last callback on user abort

The list is only approximately ordered. Not all statuses all presented on both platforms. If status is progressChanged, the object is extended by a progress key like so:

{
    "status": "progressChanged",
    "progress": {
        "percent": 12,
        "speed": 2505.912325285,
        "avgSpeed": 1801.8598291,
        "currentPart": 1,
        partsTotal: 1
    }
}

In a case of error, the JSON object passed to failure callback has following structure:

{
    "errorMessage": "Hopefully human readable error message"
}

Please note, that the device will disconnect (possibly multiple times) during the upgrade, so the ble.connect error callback will trigger. This is intentional.

Parameters

  • device_id: UUID or MAC address of the peripheral
  • uri: URI of a firmware ZIP file on the local filesystem (see cordova-plugin-file)
  • progress: Progress callback function that is invoked multiple times with upgrade status info
  • failure: Error callback function, invoked when an error occurs

Quick Example

// presume connected device

var device_id = "BD922605-1B07-4D55-8D09-B66653E51BBA";
var uri =
  "file:///var/mobile/Applications/12312-1231-1231-123312-123123/Documents/firmware.zip";

ble.upgradeFirmware(device_id, uri, console.log, console.error);

cordova-plugin-ble-nordic's People

Contributors

batcoder avatar cbolgiano avatar chris-armstrong avatar chris-guidry avatar ddugue avatar domvel avatar don avatar doug-a-brunner avatar flemmingdjensen avatar ggordan avatar guanbo avatar hughbris avatar jplourenco avatar kellycampbell avatar ktemby avatar legege avatar lucatorella avatar markterrill avatar mebrunet avatar motla avatar peacepan avatar petrometro avatar riccardodegan-geekcups avatar rrharvey avatar senator avatar surajpindoria avatar timkim avatar tomasbedrich avatar vchaldeakis avatar wynout 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.