Skip to content

Commit c620ec4

Browse files
authored
Merge branch 'master' into master
2 parents 8de1d91 + 094cb48 commit c620ec4

File tree

9 files changed

+200
-93
lines changed

9 files changed

+200
-93
lines changed

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
## 5.0.0 - 2020-07-21
2+
- Improves writeQ performance [\#617](https://github.com/randdusing/cordova-plugin-bluetoothle/issues/617)
3+
- Potentially breaking change, thus the version bump:
4+
- iOS 10 required
5+
- writeQ returns a success callback even with iOS's noResponse type. Ignore callback to keep existing behavior
6+
- Review writeQ section of [readme](https://github.com/randdusing/cordova-plugin-bluetoothle#writeq)
7+
8+
## 4.5.14 - 2020-06-25
9+
- Fix NPE in Android [\#615](https://github.com/randdusing/cordova-plugin-bluetoothle/issues/615)
10+
11+
## 4.5.13 - 2020-06-16
12+
- Use fine location permissions to fix scanning in Android 10 [\#579](https://github.com/randdusing/cordova-plugin-bluetoothle/issues/579)
13+
14+
## 4.5.12 - 2020-06-03
15+
- Update types
16+
17+
## 4.5.11 - 2020-05-20
18+
- Reinitialize gatt server when Bluetooth resets [\#302](https://github.com/randdusing/BluetoothLE/issues/302)
19+
120
## 4.5.10 - 2020-04-10
221
- Remove unnecessary check when advertising
322

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cordova-plugin-bluetoothle",
3-
"version": "4.5.10",
3+
"version": "5.0.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": {

plugin.xml

Lines changed: 2 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.10">
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="5.0.0">
33
<engines>
44
<engine name="cordova-plugman" version=">=5.0.0" />
55
<engine name="cordova-android" version=">=5.0.0" />
@@ -23,6 +23,7 @@
2323
<config-file target="AndroidManifest.xml" parent="/manifest">
2424
<uses-permission android:name="android.permission.BLUETOOTH"/>
2525
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
26+
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
2627
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
2728
</config-file>
2829
</platform>

readme.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ This plugin allows you to interact with Bluetooth LE devices on Android, iOS, an
9696

9797
* Cordova 5.0.0 or higher
9898
* Android 4.3 or higher, Android Cordova library 5.0.0 or higher, target Android API 23 or higher
99-
* iOS 7 or higher
99+
* iOS 10 or higher
100100
* Windows Phone 8.1 (Tested on Nokia Lumia 630)
101101
* Windows 10 UWP
102102
* 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
@@ -1281,19 +1281,25 @@ var string = bluetoothle.bytesToString(bytes); //This should equal Write Hello W
12811281

12821282

12831283
### 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.
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 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.
12851285

12861286
Warnings
12871287
* This is experimental. Test heavily before using in any production code.
1288-
* iOS won't see much performance gain, but Android should.
1288+
* 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`.
1289+
* Only supported on iOS11+.
12891290
* Only supports one call at a time. Don't execute back to back, use on multiple devices, or multiple characteristics.
12901291

12911292
```javascript
12921293
bluetoothle.writeQ(writeSuccess, writeError, params);
12931294
```
12941295

12951296
##### Params #####
1296-
See write() above.
1297+
* address = The address/identifier provided by the scan's return object
1298+
* service = The service's UUID
1299+
* characteristic = The characteristic's UUID
1300+
* value = Base64 encoded string
1301+
* type = Set to "noResponse" to enable write without response, all other values will write normally.
1302+
* chunkSize = Define the size of packets. This should be according to MTU value
12971303

12981304
##### Success #####
12991305
See write() above.

src/android/BluetoothLePlugin.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
public class BluetoothLePlugin extends CordovaPlugin {
5858
//Initialization related variables
5959
private final int REQUEST_BT_ENABLE = 59627; /*Random integer*/
60-
private final int REQUEST_ACCESS_COARSE_LOCATION = 59628;
60+
private final int REQUEST_ACCESS_FINE_LOCATION = 59628;
6161
private final int REQUEST_LOCATION_SOURCE_SETTINGS = 59629;
6262
private BluetoothAdapter bluetoothAdapter;
6363
private boolean isReceiverRegistered = false;
@@ -874,7 +874,7 @@ private void notifyAction(JSONArray args, CallbackContext callbackContext) {
874874
public void hasPermissionAction(CallbackContext callbackContext) {
875875
JSONObject returnObj = new JSONObject();
876876

877-
addProperty(returnObj, "hasPermission", cordova.hasPermission(Manifest.permission.ACCESS_COARSE_LOCATION));
877+
addProperty(returnObj, "hasPermission", cordova.hasPermission(Manifest.permission.ACCESS_FINE_LOCATION));
878878

879879
callbackContext.success(returnObj);
880880
}
@@ -889,7 +889,7 @@ public void requestPermissionAction(CallbackContext callbackContext) {
889889
}
890890

891891
permissionsCallback = callbackContext;
892-
cordova.requestPermission(this, REQUEST_ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION);
892+
cordova.requestPermission(this, REQUEST_ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION);
893893
}
894894

895895
public void onRequestPermissionResult(int requestCode, String[] permissions, int[] grantResults) throws JSONException {
@@ -900,7 +900,7 @@ public void onRequestPermissionResult(int requestCode, String[] permissions, int
900900
//Just call hasPermission again to verify
901901
JSONObject returnObj = new JSONObject();
902902

903-
addProperty(returnObj, "requestPermission", cordova.hasPermission(Manifest.permission.ACCESS_COARSE_LOCATION));
903+
addProperty(returnObj, "requestPermission", cordova.hasPermission(Manifest.permission.ACCESS_FINE_LOCATION));
904904

905905
permissionsCallback.success(returnObj);
906906
}
@@ -1008,16 +1008,16 @@ private void initializeAction(JSONArray args, CallbackContext callbackContext) {
10081008
}
10091009
}
10101010

1011-
1011+
10121012
/**
1013-
* Retrieves a minimal set of adapter details
1013+
* Retrieves a minimal set of adapter details
10141014
* (address, name, initialized state, enabled state, scanning state, discoverable state)
10151015
*/
1016-
private void getAdapterInfoAction(CallbackContext callbackContext) {
1017-
JSONObject returnObj = new JSONObject();
1016+
private void getAdapterInfoAction(CallbackContext callbackContext) {
1017+
JSONObject returnObj = new JSONObject();
10181018

10191019
// Not yet initialized
1020-
if (bluetoothAdapter == null) {
1020+
if (bluetoothAdapter == null) {
10211021
Activity activity = cordova.getActivity();
10221022
BluetoothManager bluetoothManager = (BluetoothManager) activity.getSystemService(Context.BLUETOOTH_SERVICE);
10231023
BluetoothAdapter bluetoothAdapterTmp = bluetoothManager.getAdapter();
@@ -1032,7 +1032,7 @@ private void getAdapterInfoAction(CallbackContext callbackContext) {
10321032
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, returnObj);
10331033
pluginResult.setKeepCallback(true);
10341034
callbackContext.sendPluginResult(pluginResult);
1035-
return;
1035+
return;
10361036
} else {
10371037
// Already initialized, so use the bluetoothAdapter class property to get all the info
10381038
addProperty(returnObj, keyAddress, bluetoothAdapter.getAddress());
@@ -1043,10 +1043,10 @@ private void getAdapterInfoAction(CallbackContext callbackContext) {
10431043
addProperty(returnObj, keyIsDiscoverable, bluetoothAdapter.getScanMode() == BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE);
10441044
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, returnObj);
10451045
pluginResult.setKeepCallback(true);
1046-
callbackContext.sendPluginResult(pluginResult);
1046+
callbackContext.sendPluginResult(pluginResult);
10471047
return;
10481048
}
1049-
1049+
10501050
}
10511051

10521052
private void enableAction(CallbackContext callbackContext) {
@@ -1692,7 +1692,7 @@ private boolean refreshDeviceCache(BluetoothGatt gatt) {
16921692
boolean bool = ((Boolean) localMethod.invoke(localBluetoothGatt, new Object[0])).booleanValue();
16931693
return bool;
16941694
}
1695-
}
1695+
}
16961696
catch (Exception localException) {
16971697
Log.e("BLE", "An exception occured while refreshing device cache");
16981698
}
@@ -2113,7 +2113,7 @@ private void writeQAction(JSONArray args, CallbackContext callbackContext) {
21132113
queueQuick.clear();
21142114

21152115
int length = value.length;
2116-
int chunkSize = 20;
2116+
int chunkSize = obj.optInt("chunkSize", 20);
21172117
int offset = 0;
21182118

21192119
do {

src/ios/BluetoothLePlugin.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@
1515
int requestId;
1616
NSMutableDictionary* requestsHash;
1717
NSMutableDictionary* servicesHash;
18+
19+
BOOL writeQIsRunning;
20+
int writeQtype;
21+
NSInteger writeQLocation;
22+
NSInteger writeQLength;
23+
NSInteger writeQChunkSize;
24+
NSData *writeQData;
25+
CBCharacteristic *currentWriteCharacteristic;
1826
}
1927

2028
- (void)initialize:(CDVInvokedUrlCommand *)command;

0 commit comments

Comments
 (0)