This plugin updates the fxe-gear/cordova-plugin-ble-central plugin to include the latest changes from don/cordova-plugin-ble-central.
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.
For using this plugin on iOS, there are some additional requirements:
cordova
version >= 6.4cordova-ios
version >=4.3.0- CocoaPods
$ cordova plugin add https://github.com/pni-ciklum/cordova-plugin-ble-central.git
Upgrade a peripheral firmware.
ble.upgradeFirmware(device_id, uri, progress, failure);
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 infofirmwareValidating
dfuCompleted
deviceDisconnecting
deviceDisconnected
- the last callback on successful upgradedfuAborted
- 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.
- 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
// 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);