Skip to content

Commit b44fe67

Browse files
committed
readme, uuid validation
Update documentation especially around values and requestIds Better validation on getUuids
1 parent 95061f4 commit b44fe67

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

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/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)