Skip to content

Commit 7683d77

Browse files
authored
Merge pull request #1 from randdusing/master
update from origin
2 parents 899d18b + 3611f41 commit 7683d77

15 files changed

+944
-223
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"editor.formatOnSave": false
3+
}

CHANGELOG.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,80 @@
1+
## 6.5.0 - 2021-06-21
2+
- Operations are queued per device connection rather than globally on Android
3+
- Use service data if available on Android
4+
5+
## 6.4.1 - 2021-06-08
6+
- Ensure Android subscriptions are returned in order [\#419](https://github.com/randdusing/cordova-plugin-bluetoothle/issues/419)
7+
8+
## 6.4.0 - 2021-06-08
9+
- Fix issue with writeQ when peripheral disconnects [\#690](https://github.com/randdusing/cordova-plugin-bluetoothle/issues/690)
10+
- Add JavaScript helper methods for encoding and decoding Unicode strings
11+
12+
## 6.3.1 - 2021-04-07
13+
- Fix #retrieveConnected() for Android, Dual Type devices are no longer filtered out. [\#559](https://github.com/randdusing/cordova-plugin-bluetoothle/issues/559)
14+
15+
## 6.3.0 - 2021-02-19
16+
- Add #retrievePeripheralsByAddress() for iOS and OSX
17+
18+
## 6.2.2 - 2021-02-19
19+
- Remove ACCESS_BACKGROUND_LOCATION permission. Revert changes from v6.1.1. This should be added manually if background permissions are actually needed
20+
21+
## 6.2.1 - 2021-02-05
22+
- Update types for NotifyParams
23+
24+
## 6.2.0 - 2020-12-23
25+
- Add #setPin() method for Android
26+
27+
## 6.1.1 - 2020-12-04
28+
- Add ACCESS_BACKGROUND_LOCATION permission to fix issue with Android target SDK 29
29+
30+
## 6.1.0 - 2020-11-07
31+
- Allow specifying transport mode for Android
32+
33+
## 6.0.2 - 2020-10-10
34+
- Add name when advertising
35+
36+
## 6.0.1 - 2020-09-19
37+
- Force re-discovery when clearCache => true. [\#634](https://github.com/randdusing/cordova-plugin-bluetoothle/issues/634)
38+
39+
## 6.0.0 - 2020-08-19
40+
- Fix ordering issue with notifications
41+
- Potential breaking change - Verify #subscribe() behavior closely!
42+
43+
## 5.0.2 - 2020-08-05
44+
- Update cordovaDependencies to allow install [\#632](https://github.com/randdusing/cordova-plugin-bluetoothle/issues/632)
45+
46+
## 5.0.1 - 2020-07-31
47+
- Reset isAdvertising flag when Bluetooth resets [\#302](https://github.com/randdusing/cordova-plugin-bluetoothle/issues/302)
48+
49+
## 5.0.0 - 2020-07-21
50+
- Improves writeQ performance [\#617](https://github.com/randdusing/cordova-plugin-bluetoothle/issues/617)
51+
- Potentially breaking change, thus the version bump:
52+
- iOS 10 required
53+
- writeQ returns a success callback even with iOS's noResponse type. Ignore callback to keep existing behavior
54+
- Review writeQ section of [readme](https://github.com/randdusing/cordova-plugin-bluetoothle#writeq)
55+
56+
## 4.5.14 - 2020-06-25
57+
- Fix NPE in Android [\#615](https://github.com/randdusing/cordova-plugin-bluetoothle/issues/615)
58+
59+
## 4.5.13 - 2020-06-16
60+
- Use fine location permissions to fix scanning in Android 10 [\#579](https://github.com/randdusing/cordova-plugin-bluetoothle/issues/579)
61+
62+
## 4.5.12 - 2020-06-03
63+
- Update types
64+
65+
## 4.5.11 - 2020-05-20
66+
- Reinitialize gatt server when Bluetooth resets [\#302](https://github.com/randdusing/BluetoothLE/issues/302)
67+
68+
## 4.5.10 - 2020-04-10
69+
- Remove unnecessary check when advertising
70+
71+
## 4.5.9 - 2020-03-13
72+
- Add null check when disabling scan on newer Android versions
73+
- Update docs
74+
75+
## 4.5.8 - 2020-03-08
76+
- Improve connection reliability on Android
77+
178
## 4.5.7 - 2020-02-11
279
- Stop scan when Bluetooth is disabled on Android v6+
380

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cordova-plugin-bluetoothle",
3-
"version": "4.5.7",
3+
"version": "6.5.0",
44
"description": "Use the Bluetooth Low Energy plugin to connect your Cordova app to new Bluetooth devices like heart rate monitors, thermometers, etc...",
55
"types": "./types/index.d.ts",
66
"cordova": {
@@ -32,7 +32,7 @@
3232
"cordova": ">=5.0.0",
3333
"cordova-android": ">=5.0.0"
3434
},
35-
"5.0.0": {
35+
"7.0.0": {
3636
"cordova": ">=100"
3737
}
3838
}

plugin.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:m2="http://schemas.microsoft.com/appx/2013/manifest" id="cordova-plugin-bluetoothle" version="4.5.7">
2+
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:m2="http://schemas.microsoft.com/appx/2013/manifest" id="cordova-plugin-bluetoothle" version="6.5.0">
33
<engines>
44
<engine name="cordova-plugman" version=">=5.0.0" />
55
<engine name="cordova-android" version=">=5.0.0" />
@@ -20,9 +20,11 @@
2020
</config-file>
2121
<source-file src="src/android/BluetoothLePlugin.java" target-dir="src/com/randdusing/bluetoothle" />
2222
<source-file src="src/android/Operation.java" target-dir="src/com/randdusing/bluetoothle" />
23+
<source-file src="src/android/SequentialCallbackContext.java" target-dir="src/com/randdusing/bluetoothle" />
2324
<config-file target="AndroidManifest.xml" parent="/manifest">
2425
<uses-permission android:name="android.permission.BLUETOOTH"/>
2526
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
27+
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
2628
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
2729
</config-file>
2830
</platform>

readme.md

Lines changed: 102 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
# Cordova Bluetooth LE Plugin
23
This plugin allows you to interact with Bluetooth LE devices on Android, iOS, and Windows.
34

@@ -62,6 +63,8 @@ This plugin allows you to interact with Bluetooth LE devices on Android, iOS, an
6263
- [requestPermission](#requestpermission)
6364
- [isLocationEnabled](#islocationenabled)
6465
- [requestLocation](#requestlocation)
66+
- [setPin](#setPin)
67+
- [retrievePeripheralsByAddress](#retrievePeripheralsByAddress)
6568
- [Peripheral Life Cycle](#peripheral-life-cycle)
6669
- [Initilization](#initilization)
6770
- [Notifications](#notifications)
@@ -79,6 +82,8 @@ This plugin allows you to interact with Bluetooth LE devices on Android, iOS, an
7982
- [bytesToEncodedString](#bytestoencodedstring)
8083
- [stringToBytes](#stringtobytes)
8184
- [bytesToString](#bytestostring)
85+
- [encodeUnicode](#encodeunicode)
86+
- [decodeUnicode](#decodeunicode)
8287
- [Example](#example)
8388
- [Data Parsing Example](#data-parsing-example)
8489
- [Sample: Discover and interact with Bluetooth LE devices](#sample-discover-and-interact-with-bluetooth-le-devices)
@@ -95,8 +100,8 @@ This plugin allows you to interact with Bluetooth LE devices on Android, iOS, an
95100
## Requirements ##
96101

97102
* Cordova 5.0.0 or higher
98-
* Android 4.3 or higher, Android Cordova library 5.0.0 or higher, target Android API 23 or higher
99-
* iOS 7 or higher
103+
* Android Cordova library 5.0.0 or higher, target Android API 23/Platform 6.0 or higher (support for older Android versions should use versions 2.4.0 or below)
104+
* iOS 10 or higher
100105
* Windows Phone 8.1 (Tested on Nokia Lumia 630)
101106
* Windows 10 UWP
102107
* Device hardware must be certified for Bluetooth LE. i.e. Nexus 7 (2012) doesn't support Bluetooth LE even after upgrading to 4.3 (or higher) without a modification
@@ -237,6 +242,7 @@ Neither Android nor iOS support Bluetooth on emulators, so you'll need to test o
237242
* [bluetoothle.requestPermission](#requestpermission) (Android 6+)
238243
* [bluetoothle.isLocationEnabled](#islocationenabled) (Android 6+)
239244
* [bluetoothle.requestLocation](#requestlocation) (Android 6+)
245+
* [bluetoothle.retrievePeripheralsByAddress](#retrievePeripheralsByAddress) (iOS)
240246
* [bluetoothle.initializePeripheral](#initializeperipheral)
241247
* [bluetoothle.addService](#addservice)
242248
* [bluetoothle.removeService](#removeservice)
@@ -245,10 +251,13 @@ Neither Android nor iOS support Bluetooth on emulators, so you'll need to test o
245251
* [bluetoothle.stopAdvertising](#stopadvertising)
246252
* [bluetoothle.respond](#respond)
247253
* [bluetoothle.notify](#notify)
254+
* [bluetoothle.setPin](#setPin) (Android)
248255
* [bluetoothle.encodedStringToBytes](#encodedstringtobytes)
249256
* [bluetoothle.bytesToEncodedString](#bytestoencodedstring)
250257
* [bluetoothle.stringToBytes](#stringtobytes)
251258
* [bluetoothle.bytesToString](#bytestostring)
259+
* [bluetoothle.encodeUnicode](#encodeunicode)
260+
* [bluetoothle.decodeUnicode](#decodeunicode)
252261

253262

254263

@@ -286,6 +295,8 @@ Whenever the error callback is executed, the return object will contain the erro
286295
* isNotConnected - Device isn't connected (Don't call discover or any read/write operations)
287296
* isDisconnected - Device is disconnected (Don't call disconnect)
288297
* isBonded - Operation is unsupported. (Is the device Android?)
298+
* setPin - Operation is unsupported. (Is the device Android?)
299+
* retrievePeripheralsByAddress - Operation is unsupported (Is the device iOS?)
289300

290301
For example:
291302
```javascript
@@ -614,7 +625,7 @@ bluetoothle.connect(connectSuccess, connectError, params);
614625
##### Params #####
615626
* address = The address/identifier provided by the scan's return object
616627
* autoConnect = Automatically connect as soon as the remote device becomes available (Android)
617-
628+
* transport = Mode of transport - Auto = 0, Prefer BR/EDR = 1, Prefer LE = 2, (Android API 23+)
618629
```javascript
619630
{
620631
"address": "ECC037FD-72AE-AFC5-9213-CA785B3B5C63"
@@ -1264,6 +1275,8 @@ To write without response, set type to "noResponse". Any other value will defaul
12641275
var string = "Write Hello World";
12651276
var bytes = bluetoothle.stringToBytes(string);
12661277
var encodedString = bluetoothle.bytesToEncodedString(bytes);
1278+
// if your code includes special characters you should use the encodeUnicode helper function
1279+
var encodedUnicodeString = bluetoothle.encodeUnicode(string);
12671280

12681281
//Note, this example doesn't actually work since it's read only characteristic
12691282
{"value":"V3JpdGUgSGVsbG8gV29ybGQ=","service":"180F","characteristic":"2A19","type":"noResponse","address":"ABC123"}
@@ -1276,24 +1289,33 @@ Value is a base64 encoded string of written bytes. Use bluetoothle.encodedString
12761289
var returnObj = {"status":"written","service":"180F","characteristic":"2A19","value":"V3JpdGUgSGVsbG8gV29ybGQ=","address":"ABC123"}
12771290
var bytes = bluetoothle.encodedStringToBytes(returnObj.value);
12781291
var string = bluetoothle.bytesToString(bytes); //This should equal Write Hello World
1292+
1293+
// if your code includes special characters you should use the decodeUnicode helper function
1294+
var string = bluetoothle.decodeUnicode(returnObj.value);
12791295
```
12801296

12811297

12821298

12831299
### writeQ ###
1284-
Write Quick / Queue, use this method to quickly execute write without response commands when writing more than 20 bytes at a time. The data will automatically be split up into 20 bytes packets. On iOS, these packets are written immediately since iOS uses queues. You probably won't see much of a performance increase using writeQ. On Android, a queue isn't used internally. Instead another call shouldn't be made until onCharacteristicWrite is called. This could be done at the Javascript layer, but the Javascript to plugin "bridge" must be crossed twice, which leads to some significant slow downs when milliseconds make a difference. For even better write throughput, use requestConnectionPriority('high') as well. Note, no callback will occur on write without response on iOS.
1300+
Write Quick / Queue, use this method to quickly execute write without response commands when writing more than 20 bytes at a time. The data will automatically be split up into 20 bytes packets by default or you can increase that by setting `chunkSize`. On iOS, these packets are written immediately since iOS uses queues. You probably won't see much of a performance increase using writeQ unless you use `type="noResponse"` and set `chunkSize` higher than 20. On Android, a queue isn't used internally. Instead another call shouldn't be made until onCharacteristicWrite is called. This could be done at the Javascript layer, but the Javascript to plugin "bridge" must be crossed twice, which leads to some significant slow downs when milliseconds make a difference. For even better write throughput, use requestConnectionPriority('high') and mtu(SAME_VALUE_AS_CHUNK_SIZE_PARAM) as well.
12851301

12861302
Warnings
12871303
* This is experimental. Test heavily before using in any production code.
1288-
* iOS won't see much performance gain, but Android should.
1304+
* To see a performance gain you should use this in combination with requestConnectionPriority('high') and mtu(`MTU_VALUE`) and then calling this method with `type="noResponse"` and set `chunkSize` to `MTU_VALUE`.
1305+
* Only supported on iOS11+.
12891306
* Only supports one call at a time. Don't execute back to back, use on multiple devices, or multiple characteristics.
12901307

12911308
```javascript
12921309
bluetoothle.writeQ(writeSuccess, writeError, params);
12931310
```
12941311

12951312
##### Params #####
1296-
See write() above.
1313+
* address = The address/identifier provided by the scan's return object
1314+
* service = The service's UUID
1315+
* characteristic = The characteristic's UUID
1316+
* value = Base64 encoded string
1317+
* type = Set to "noResponse" to enable write without response, all other values will write normally.
1318+
* chunkSize = Define the size of packets. This should be according to MTU value
12971319

12981320
##### Success #####
12991321
See write() above.
@@ -1553,7 +1575,32 @@ bluetoothle.isBonded(isBondedSuccess, isBondedError, params);
15531575
}
15541576
```
15551577

1578+
### setPin ###
1579+
Set PIN if required by the pairing process. Android support only.
1580+
1581+
```javascript
1582+
bluetoothle.setPin(success, error, params);
1583+
```
15561584

1585+
#### Params ####
1586+
* address = The address/identifier provided by the scan's return object
1587+
* pin = Pairing PIN code
1588+
1589+
```javascript
1590+
{
1591+
"address": "5A:94:4B:38:B3:FD",
1592+
"pin": "1234"
1593+
}
1594+
```
1595+
1596+
##### Success #####
1597+
* status => string
1598+
1599+
```javascript
1600+
{
1601+
"status": "pinSet",
1602+
}
1603+
```
15571604

15581605
### wasConnected ###
15591606
Determine whether the device was connected, or error if not initialized.
@@ -1714,6 +1761,38 @@ bluetoothle.requestLocation(requestLocationSuccess, requestLocationError);
17141761

17151762

17161763

1764+
### retrievePeripheralsByAddress ###
1765+
Retrieve paired Bluetooth LE devices based on their address. Wraps the iOS method [CBCentralManager.retrievePeripheralsWithIdentifiers](https://developer.apple.com/documentation/corebluetooth/cbcentralmanager/1519127-retrieveperipheralswithidentifie?language=objc). iOS support only. Will return an error if used on Android.
1766+
1767+
```javascript
1768+
bluetoothle.retrievePeripheralsByAddress(success, error, params);
1769+
```
1770+
1771+
##### Params #####
1772+
* addresses = An arrays of addresses/identifiers to lookup devices by. If no addresses are specified, no devices will be returned
1773+
1774+
```javascript
1775+
{
1776+
"addresses": ["ECC037FD-72AE-AFC5-9213-CA785B3B5C63"]
1777+
}
1778+
```
1779+
1780+
##### Success #####
1781+
Returns an array of device objects:
1782+
* name = the device's display name
1783+
* address = the device's address / identifier for connecting to the object
1784+
1785+
```javascript
1786+
[
1787+
{
1788+
"name": "Polar H7 3B321015",
1789+
"address": "ECC037FD-72AE-AFC5-9213-CA785B3B5C63"
1790+
}
1791+
]
1792+
```
1793+
1794+
1795+
17171796
## Peripheral Life Cycle ##
17181797

17191798
1. initializePeripheral
@@ -2006,7 +2085,7 @@ bluetoothle.isAdvertising(success, error);
20062085

20072086

20082087
### respond ###
2009-
Respond to a read or write request
2088+
Respond to a read or write request. On Android, a device address is required
20102089

20112090
```javascript
20122091
bluetoothle.respond(success, error, params);
@@ -2038,7 +2117,7 @@ var params = {
20382117

20392118

20402119
### notify ###
2041-
Update a value for a subscription. Currently all subscribed devices will receive update. Device specific updates will be added in the future. If ```sent``` equals false in the return value, you must wait for the ```peripheralManagerIsReadyToUpdateSubscribers``` event before sending more updates.
2120+
Update a value for a subscription. Currently all subscribed devices will receive updates on iOS. Device specific updates will be added in the future. On Android, a device address is required. If ```sent``` equals false in the return value, you must wait for the ```peripheralManagerIsReadyToUpdateSubscribers``` event before sending more updates.
20422121

20432122
```javascript
20442123
bluetoothle.notify(success, error, params);
@@ -2050,6 +2129,7 @@ var params = {
20502129
"service":"1234",
20512130
"characteristic":"ABCD",
20522131
"value":"U3Vic2NyaWJlIEhlbGxvIFdvcmxk" //Subscribe Hello World
2132+
// "address": "5163F1E0-5341-AF9B-9F67-613E15EC83F7" // only on android
20532133
};
20542134
```
20552135

@@ -2172,6 +2252,20 @@ if (obj.status == "subscribedResult")
21722252
}
21732253
```
21742254

2255+
### encodeUnicode ###
2256+
Helper function to convert unicode string to base64 encoded string. This function can be used to encode special characters such as emojis.
2257+
2258+
```javascript
2259+
bluetoothle.encodeUnicode(string);
2260+
```
2261+
2262+
### decodeUnicode ###
2263+
Helper function to convert a base64 encoded string to unicode string. This function also decodes special characters such as emojis.
2264+
2265+
```javascript
2266+
bluetoothle.decodeUnicode(string);
2267+
```
2268+
21752269
## Sample: Discover and interact with Bluetooth LE devices ##
21762270

21772271
We'll build an app that lets you discover Bluetooth Low Energy (LE) devices that are around you, connect to a one, and then look at all of the information that you can obtain from that device such as signal strength, supported services, battery level and more.

0 commit comments

Comments
 (0)