Skip to content

Bluetooth Low Energy (BLE) Central plugin for Apache Cordova (aka PhoneGap)

License

Notifications You must be signed in to change notification settings

lulumahot/cordova-plugin-ble-central

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BLE plugin for Apache Cordova with Nordic DFU

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:

This plugin isn't intended for scanning beacons. Try cordova-plugin-ibeacon for iBeacons.

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

Supported Platforms

  • iOS
  • Android (4.3 or greater)
  • cordova version >= 6.4
  • cordova-ios version >=4.3.0
  • CocoaPods

Installing

$ cordova plugin add https://github.com/fxe-gear/cordova-plugin-ble-central.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);

About

Bluetooth Low Energy (BLE) Central plugin for Apache Cordova (aka PhoneGap)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 50.7%
  • Objective-C 37.5%
  • JavaScript 9.5%
  • C# 2.3%