Skip to content

Commit

Permalink
Docs
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosinigaglia committed Jan 11, 2024
1 parent c92f2c9 commit 5301699
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 3 deletions.
4 changes: 4 additions & 0 deletions docs/changelog.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ nav_order: 100

To read all the details go to the [Github Releases section](https://github.com/innoveit/react-native-ble-manager/releases).

## Release v11.1.X

- Added `writeDescriptor` method.

## Release v11.0.X

- The iOS module has been completely rewritten in Swift.
Expand Down
69 changes: 66 additions & 3 deletions docs/methods.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ BleManager.start({ showAlert: false }).then(() => {
console.log("Module initialized");
});
```

---

## scan(serviceUUIDs, seconds, allowDuplicates, scanningOptions)
Expand Down Expand Up @@ -63,6 +64,7 @@ BleManager.scan([], 5, true).then(() => {
console.log("Scan started");
});
```

---

## stopScan()
Expand All @@ -78,6 +80,7 @@ BleManager.stopScan().then(() => {
console.log("Scan stopped");
});
```

---

## connect(peripheralId, options)
Expand All @@ -95,7 +98,6 @@ Returns a `Promise` object.
- `phy` - `Number` - [Android only] corresponding to the preferred phy channel ([`Android doc`](<https://developer.android.com/reference/android/bluetooth/BluetoothDevice?hl=en#connectGatt(android.content.Context,%20boolean,%20android.bluetooth.BluetoothGattCallback,%20int,%20int)>))
- `autoconnect` - `Boolean` - [Android only] whether to directly connect to the remote device (false) or to automatically connect as soon as the remote device becomes available (true) ([`Android doc`](<https://developer.android.com/reference/android/bluetooth/BluetoothDevice?hl=en#connectGatt(android.content.Context,%20boolean,%20android.bluetooth.BluetoothGattCallback,%20int,%20int)>))


**Examples**

```js
Expand All @@ -111,6 +113,7 @@ BleManager.connect("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX")
```

---

## disconnect(peripheralId, force)

Disconnect from a peripheral.
Expand Down Expand Up @@ -140,6 +143,7 @@ BleManager.disconnect("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX")
console.log(error);
});
```

---

## enableBluetooth() [Android only]
Expand All @@ -160,6 +164,7 @@ BleManager.enableBluetooth()
console.log("The user refuse to enable bluetooth");
});
```

---

## checkState()
Expand All @@ -174,6 +179,7 @@ BleManager.checkState().then((state) =>
console.log(`current BLE state = '${state}'.`)
);
```

---

## startNotification(peripheralId, serviceUUID, characteristicUUID)
Expand Down Expand Up @@ -204,6 +210,7 @@ BleManager.startNotification(
console.log(error);
});
```

---

## startNotificationUseBuffer(peripheralId, serviceUUID, characteristicUUID, buffer) [Android only]
Expand Down Expand Up @@ -236,6 +243,7 @@ BleManager.startNotification(
console.log(error);
});
```

---

## stopNotification(peripheralId, serviceUUID, characteristicUUID)
Expand Down Expand Up @@ -285,6 +293,7 @@ BleManager.read(
console.log(error);
});
```

---

## write(peripheralId, serviceUUID, characteristicUUID, data, maxByteSize)
Expand Down Expand Up @@ -346,6 +355,7 @@ BleManager.write(
console.log(error);
});
```

---

## writeWithoutResponse(peripheralId, serviceUUID, characteristicUUID, data, maxByteSize, queueSleepTime)
Expand Down Expand Up @@ -384,6 +394,7 @@ BleManager.writeWithoutResponse(
console.log(error);
});
```

---

## readRSSI(peripheralId)
Expand All @@ -408,6 +419,7 @@ BleManager.readRSSI("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX")
console.log(error);
});
```

---

## readDescriptor(peripheralId, serviceId, characteristicId, descriptorId)
Expand Down Expand Up @@ -446,6 +458,41 @@ BleManager.readDescriptor(
console.log(error);
});
```

---

## writeDescriptor(peripheralId, serviceId, characteristicId, descriptorId, data)

Write a value to the specified descriptor, you need to call `retrieveServices` method before.
Returns a `Promise` object.

**Arguments**

- `peripheralId` - `String` - the id/mac address of the peripheral.
- `serviceUUID` - `String` - the UUID of the service.
- `characteristicUUID` - `String` - the UUID of the characteristic.
- `descriptorUUID` - `String` - the UUID of the descriptor.
- `data` - `number[]` - the data to write as a plain integer array representing a `ByteArray` structure.

**Examples**

```js
BleManager.writeDescriptor(
"XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
"XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
"XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
"XXXX",
[1, 2]
)
.then(() => {
// Success code
})
.catch((error) => {
// Failure code
console.log(error);
});
```

---

## requestConnectionPriority(peripheralId, connectionPriority) [Android only API 21+]
Expand Down Expand Up @@ -474,6 +521,7 @@ BleManager.requestConnectionPriority("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX", 1)
console.log(error);
});
```

---

## requestMTU(peripheralId, mtu) [Android only API 21+]
Expand All @@ -499,6 +547,7 @@ BleManager.requestMTU("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX", 512)
console.log(error);
});
```

---

## retrieveServices(peripheralId[, serviceUUIDs])
Expand All @@ -521,6 +570,7 @@ BleManager.retrieveServices("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX").then(
}
);
```

---

## refreshCache(peripheralId) [Android only]
Expand All @@ -544,6 +594,7 @@ BleManager.refreshCache("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX")
console.error(error);
});
```

---

## getConnectedPeripherals(serviceUUIDs)
Expand All @@ -563,6 +614,7 @@ BleManager.getConnectedPeripherals([]).then((peripheralsArray) => {
console.log("Connected peripherals: " + peripheralsArray.length);
});
```

---

## createBond(peripheralId,peripheralPin) [Android only]
Expand All @@ -581,6 +633,7 @@ BleManager.createBond(peripheralId)
console.log("fail to bond");
});
```

---

## removeBond(peripheralId) [Android only]
Expand All @@ -599,6 +652,7 @@ BleManager.removeBond(peripheralId)
console.log("fail to remove the bond");
});
```

---

## getBondedPeripherals() [Android only]
Expand All @@ -614,6 +668,7 @@ BleManager.getBondedPeripherals([]).then((bondedPeripheralsArray) => {
console.log("Bonded peripherals: " + bondedPeripheralsArray.length);
});
```

---

## getDiscoveredPeripherals()
Expand All @@ -629,6 +684,7 @@ BleManager.getDiscoveredPeripherals([]).then((peripheralsArray) => {
console.log("Discovered peripherals: " + peripheralsArray.length);
});
```

---

## removePeripheral(peripheralId) [Android only]
Expand Down Expand Up @@ -662,6 +718,7 @@ BleManager.isPeripheralConnected(
}
});
```

---

## setName(name) [Android only]
Expand All @@ -682,6 +739,7 @@ BleManager.setName("INNOVEIT_CENTRAL")
console.log("Name could not be set");
});
```

---

## getMaximumWriteValueLengthForWithoutResponse(peripheralId) [iOS only]
Expand All @@ -692,10 +750,13 @@ Returns a `Promise` object.
**Examples**

```js
BleManager.getMaximumWriteValueLengthForWithoutResponse("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX").then((maxValue) => {
BleManager.getMaximumWriteValueLengthForWithoutResponse(
"XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
).then((maxValue) => {
console.log("Maximum length for WriteWithoutResponse: " + maxValue);
});
```

---

## getMaximumWriteValueLengthForWitResponse(peripheralId) [iOS only]
Expand All @@ -706,7 +767,9 @@ Returns a `Promise` object.
**Examples**

```js
BleManager.getMaximumWriteValueLengthForWitResponse("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX").then((maxValue) => {
BleManager.getMaximumWriteValueLengthForWitResponse(
"XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
).then((maxValue) => {
console.log("Maximum length for WriteWithResponse: " + maxValue);
});
```

0 comments on commit 5301699

Please sign in to comment.