Skip to content

Commit 836aac0

Browse files
committed
Merge remote-tracking branch 'randdusing/master'
2 parents d5cf590 + 635791e commit 836aac0

File tree

5 files changed

+71
-53
lines changed

5 files changed

+71
-53
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
## master - 2016-04-06
1+
## master - 2016-05-01
22
- wasConnected helper function
33
- Improved subscribe with Android. No longer need to specify whether notification or indication
44
- Read, write, subscribe, unsubscribe, readDescriptor, writeDescriptor queueing for Android [\#263](https://github.com/randdusing/BluetoothLE/issues/263), [\#153](https://github.com/randdusing/BluetoothLE/issues/153)
55
- Everything now runs on the single WebCore thread with Android. It should prevent issues with race conditions
66
- Fix issue with writeDescriptor on Android
7+
- Fix issue with UUID validation on iOS
78

89
## 4.0.0 - 2016-03-30
910
- Update OS X

readme.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ Another option is to connect to the device and use the "Device Information" (0x1
9393
See the following StackOverflow posts for more info: [here](https://stackoverflow.com/questions/18973098/get-mac-address-of-bluetooth-low-energy-peripheral) and [here](https://stackoverflow.com/questions/22833198/get-advertisement-data-for-ble-in-ios)
9494

9595

96+
## Data Values ##
97+
98+
9699
## Emulator ##
97100
Neither Android nor iOS support Bluetooth on emulators, so you'll need to test on a real device.
98101

@@ -942,7 +945,7 @@ bluetoothle.read(readSuccess, readError, params);
942945
```javascript
943946
{
944947
"status": "read",
945-
"value": "AQ==",
948+
"value": "UmVhZCBIZWxsbyBXb3JsZA==", //Read Hello World
946949
"characteristic": "2a38",
947950
"name": "Polar H7 3B321015",
948951
"service": "180d",
@@ -989,7 +992,7 @@ bluetoothle.subscribe(subscribeSuccess, subscribeError, params);
989992

990993
{
991994
"status": "subscribedResult",
992-
"value": "BkY=",
995+
"value": "U3Vic2NyaWJlIEhlbGxvIFdvcmxk", //Subscribe Hello World
993996
"characteristic": "2a37",
994997
"name": "Polar H7 3B321015",
995998
"service": "180d",
@@ -1053,21 +1056,21 @@ bluetoothle.write(writeSuccess, writeError, params);
10531056
Value is a base64 encoded string of bytes to write. Use bluetoothle.bytesToEncodedString(bytes) to convert to base64 encoded string from a unit8Array.
10541057
To write without response, set type to "noResponse". Any other value will default to write with response. Note, no callback will occur on write without response on iOS.
10551058
```javascript
1056-
var string = "Hello World";
1059+
var string = "Write Hello World";
10571060
var bytes = bluetoothle.stringToBytes(string);
10581061
var encodedString = bluetoothle.bytesToEncodedString(bytes);
10591062

10601063
//Note, this example doesn't actually work since it's read only characteristic
1061-
{"value":encodedString,"service":"180F","characteristic":"2A19","type":"noResponse","address":"ABC123"}
1064+
{"value":"V3JpdGUgSGVsbG8gV29ybGQ=","service":"180F","characteristic":"2A19","type":"noResponse","address":"ABC123"}
10621065
```
10631066

10641067
##### Success #####
10651068
Value is a base64 encoded string of written bytes. Use bluetoothle.encodedStringToBytes(obj.value) to convert to a unit8Array. See characteristic's specification and example below on how to correctly parse this.
10661069

10671070
```javascript
1068-
var returnObj = {"status":"written","service":"180F","characteristic":"2A19","value":"SGVsbG8gV29ybGQ=","address":"ABC123"}
1071+
var returnObj = {"status":"written","service":"180F","characteristic":"2A19","value":"V3JpdGUgSGVsbG8gV29ybGQ=","address":"ABC123"}
10691072
var bytes = bluetoothle.encodedStringToBytes(returnObj.value);
1070-
var string = bluetoothle.bytesToString(bytes); //This should equal Hello World!
1073+
var string = bluetoothle.bytesToString(bytes); //This should equal Write Hello World
10711074
```
10721075

10731076

@@ -1157,14 +1160,14 @@ var string = "Hello World";
11571160
var bytes = bluetoothle.stringToBytes(string);
11581161
var encodedString = bluetoothle.bytesToEncodedString(bytes);
11591162

1160-
{"service":"180D","characteristic":"2A37","descriptor":"2902","value":encodedString,"address":"ABC123"}
1163+
{"service":"180D","characteristic":"2A37","descriptor":"2902","value":"AQAAAAAAAAA=","address":"ABC123"}
11611164
```
11621165

11631166
##### Success #####
11641167
Value is a base64 encoded string of written bytes. Use bluetoothle.encodedStringToBytes(obj.value) to convert to a unit8Array.
11651168

11661169
```javascript
1167-
{"status":"writeDescriptor","service":"180D","characteristic":"2A37", "descriptor":"2902","value":"SGVsbG8gV29ybGQ","address":"ABC123"}
1170+
{"status":"writeDescriptor","service":"180D","characteristic":"2A37", "descriptor":"2902","value":"AQAAAAAAAAA=","address":"ABC123"}
11681171
var bytes = bluetoothle.encodedStringToBytes(returnObj.value);
11691172
var string = bluetoothle.bytesToString(bytes); //This should equal Hello World!
11701173
```
@@ -1548,7 +1551,7 @@ bluetoothle.initializePeripheral(success, error, params);
15481551
"address":"5163F1E0-5341-AF9B-9F67-613E15EC83F7",
15491552
"service":"1234",
15501553
"characteristic":"ABCD",
1551-
requestId":0,
1554+
requestId":0, //This integer value will be incremented every read/writeRequested
15521555
"offset":0
15531556
}
15541557
```
@@ -1560,7 +1563,7 @@ bluetoothle.initializePeripheral(success, error, params);
15601563
"address":"5163F1E0-5341-AF9B-9F67-613E15EC83F7",
15611564
"service":"1234",
15621565
"characteristic":"ABCD",
1563-
"requestId":2,
1566+
"requestId":1, //This integer value will be incremented every read/writeRequested
15641567
"value":"V3JpdGUgSGVsbG8gV29ybGQ=", //Write Hello World
15651568
"offset":0
15661569
}
@@ -1652,8 +1655,7 @@ var params = {
16521655
//authenticatedSignedWrites: true,
16531656
//notifyEncryptionRequired: true,
16541657
//indicateEncryptionRequired: true,
1655-
},
1656-
value: "base64encodedstring"
1658+
}
16571659
}
16581660
]
16591661
};

src/android/BluetoothLePlugin.java

Lines changed: 47 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,7 @@ private void disableAction(CallbackContext callbackContext) {
10321032
//Else listen to initialize callback for disabling
10331033
}
10341034

1035-
private void startScanAction(JSONArray args, CallbackContext callbackContext) {
1035+
private synchronized void startScanAction(JSONArray args, CallbackContext callbackContext) {
10361036
if (isNotInitialized(callbackContext, true)) {
10371037
return;
10381038
}
@@ -1119,7 +1119,7 @@ private void startScanAction(JSONArray args, CallbackContext callbackContext) {
11191119
}
11201120
}
11211121

1122-
private void stopScanAction(CallbackContext callbackContext) {
1122+
private synchronized void stopScanAction(CallbackContext callbackContext) {
11231123
if (isNotInitialized(callbackContext, true)) {
11241124
return;
11251125
}
@@ -2539,21 +2539,24 @@ public void onActivityResult(int requestCode, int resultCode, Intent intent) {
25392539
private LeScanCallback scanCallbackKitKat = new LeScanCallback() {
25402540
@Override
25412541
public void onLeScan(final BluetoothDevice device, int rssi, byte[] scanRecord) {
2542-
if (scanCallbackContext == null) {
2543-
return;
2544-
}
2542+
synchronized(BluetoothLePlugin.this){
25452543

2546-
JSONObject returnObj = new JSONObject();
2544+
if (scanCallbackContext == null) {
2545+
return;
2546+
}
25472547

2548-
addDevice(returnObj, device);
2548+
JSONObject returnObj = new JSONObject();
25492549

2550-
addProperty(returnObj, keyRssi, rssi);
2551-
addPropertyBytes(returnObj, keyAdvertisement, scanRecord);
2552-
addProperty(returnObj, keyStatus, statusScanResult);
2550+
addDevice(returnObj, device);
25532551

2554-
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, returnObj);
2555-
pluginResult.setKeepCallback(true);
2556-
scanCallbackContext.sendPluginResult(pluginResult);
2552+
addProperty(returnObj, keyRssi, rssi);
2553+
addPropertyBytes(returnObj, keyAdvertisement, scanRecord);
2554+
addProperty(returnObj, keyStatus, statusScanResult);
2555+
2556+
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, returnObj);
2557+
pluginResult.setKeepCallback(true);
2558+
scanCallbackContext.sendPluginResult(pluginResult);
2559+
}
25572560
}
25582561
};
25592562

@@ -2571,43 +2574,47 @@ public void onBatchScanResults(List<ScanResult> results) {
25712574

25722575
@Override
25732576
public void onScanFailed(int errorCode) {
2574-
if (scanCallbackContext == null)
2575-
return;
2577+
synchronized(BluetoothLePlugin.this){
2578+
if (scanCallbackContext == null)
2579+
return;
25762580

2577-
JSONObject returnObj = new JSONObject();
2578-
addProperty(returnObj, keyError, errorStartScan);
2581+
JSONObject returnObj = new JSONObject();
2582+
addProperty(returnObj, keyError, errorStartScan);
2583+
2584+
if (errorCode == ScanCallback.SCAN_FAILED_ALREADY_STARTED) {
2585+
addProperty(returnObj, keyMessage, "Scan already started");
2586+
} else if (errorCode == ScanCallback.SCAN_FAILED_APPLICATION_REGISTRATION_FAILED) {
2587+
addProperty(returnObj, keyMessage, "Application registration failed");
2588+
} else if (errorCode == ScanCallback.SCAN_FAILED_FEATURE_UNSUPPORTED) {
2589+
addProperty(returnObj, keyMessage, "Feature unsupported");
2590+
} else if (errorCode == ScanCallback.SCAN_FAILED_INTERNAL_ERROR) {
2591+
addProperty(returnObj, keyMessage, "Internal error");
2592+
} else {
2593+
addProperty(returnObj, keyMessage, logScanStartFail);
2594+
}
25792595

2580-
if (errorCode == ScanCallback.SCAN_FAILED_ALREADY_STARTED) {
2581-
addProperty(returnObj, keyMessage, "Scan already started");
2582-
} else if (errorCode == ScanCallback.SCAN_FAILED_APPLICATION_REGISTRATION_FAILED) {
2583-
addProperty(returnObj, keyMessage, "Application registration failed");
2584-
} else if (errorCode == ScanCallback.SCAN_FAILED_FEATURE_UNSUPPORTED) {
2585-
addProperty(returnObj, keyMessage, "Feature unsupported");
2586-
} else if (errorCode == ScanCallback.SCAN_FAILED_INTERNAL_ERROR) {
2587-
addProperty(returnObj, keyMessage, "Internal error");
2588-
} else {
2589-
addProperty(returnObj, keyMessage, logScanStartFail);
2596+
scanCallbackContext.error(returnObj);
2597+
scanCallbackContext = null;
25902598
}
2591-
2592-
scanCallbackContext.error(returnObj);
2593-
scanCallbackContext = null;
25942599
}
25952600

25962601
@Override
25972602
public void onScanResult(int callbackType, ScanResult result) {
2598-
if (scanCallbackContext == null)
2599-
return;
2603+
synchronized(BluetoothLePlugin.this){
2604+
if (scanCallbackContext == null)
2605+
return;
26002606

2601-
JSONObject returnObj = new JSONObject();
2607+
JSONObject returnObj = new JSONObject();
26022608

2603-
addDevice(returnObj, result.getDevice());
2604-
addProperty(returnObj, keyRssi, result.getRssi());
2605-
addPropertyBytes(returnObj, keyAdvertisement, result.getScanRecord().getBytes());
2606-
addProperty(returnObj, keyStatus, statusScanResult);
2609+
addDevice(returnObj, result.getDevice());
2610+
addProperty(returnObj, keyRssi, result.getRssi());
2611+
addPropertyBytes(returnObj, keyAdvertisement, result.getScanRecord().getBytes());
2612+
addProperty(returnObj, keyStatus, statusScanResult);
26072613

2608-
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, returnObj);
2609-
pluginResult.setKeepCallback(true);
2610-
scanCallbackContext.sendPluginResult(pluginResult);
2614+
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, returnObj);
2615+
pluginResult.setKeepCallback(true);
2616+
scanCallbackContext.sendPluginResult(pluginResult);
2617+
}
26112618
}
26122619
};
26132620
}

src/ios/BluetoothLePlugin.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3367,6 +3367,10 @@ -(NSMutableArray*) getUuids:(NSDictionary *) dictionary forType:(NSString*) type
33673367
}
33683368

33693369
for (NSString* checkUuid in checkUuids) {
3370+
if (![checkUuid isKindOfClass:[NSString class]]) {
3371+
continue;
3372+
}
3373+
33703374
CBUUID* uuid = [CBUUID UUIDWithString:checkUuid];
33713375

33723376
if (uuid != nil) {

src/osx/BluetoothLePlugin.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3367,6 +3367,10 @@ -(NSMutableArray*) getUuids:(NSDictionary *) dictionary forType:(NSString*) type
33673367
}
33683368

33693369
for (NSString* checkUuid in checkUuids) {
3370+
if (![checkUuid isKindOfClass:[NSString class]]) {
3371+
continue;
3372+
}
3373+
33703374
CBUUID* uuid = [CBUUID UUIDWithString:checkUuid];
33713375

33723376
if (uuid != nil) {

0 commit comments

Comments
 (0)