react-native-simple-ble
Currently only support ios and require react-native >= 0.40.0
Installation
-
Install library from
npm
npm install react-native-simple-ble --save -
Link native code
react-native link react-native-simple-ble
Usage
Methods
scan(UUIDs,allowDuplicates,showPowerAlert)
Scaning peripherals.
See method registerDiscoverPeripheral()
.
Arguments The parameter is optional the configuration keys are:
UUIDs
-Array of String
- [default empty] If you confirm the service UUID in the broadcast information,fill the UUID,block out you don't want, otherwise not.allowDuplicates
-Boolean
- [default false] Allow scanning duplicates.showPowerAlert
-Boolean
- [default true] Show or hide the alert if the bluetooth is turned off during initialization.
Examples
ble;// ble.scan(['XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX']);
stopScan()
Stop the scanning.
Examples
ble;
connect(identifier)
Connect to a specified peripheral.
Arguments
identifier
-String
- Using the method you have to obtain theidentifier
before ,from methodregisterDiscoverPeripheral()
.
Examples
ble
disconnect()
Disconnect from a peripheral.
Examples
ble;
write(msg,UUID)
Write to the specified characteristic.
Returns a Promise
object.
Arguments
msg
-String
- The data to write hexstring.(e.g. 'ABCDEF0123456789')UUID
-String
- [default empty] If you confirm the write more than one characteristic,fill in your specified write characteristic UUID , otherwise not.
Examples
// ble.write('ABCDEF0123456789')ble
result.writeUUID
-String
- write characteristic UUID.result.message
-String
- write state message.error
- error.
read(UUID)
Read value for the specified characteristic.
Returns a Promise
object.
Arguments
UUID
-String
- the UUID of the read characteristic.
Examples
ble
result.writeUUID
-String
- read characteristic UUID.result.value
-String
- characteristic value.error
- error.
Events
registerUpdateConnectionStatus(callback)
Register a callback to monitor the connection status.
The status changed callback.
Examples
ble;
param.connect
-Boolean
- Is connect or not.param.desc
-String
- Error message description.
registerDiscoverPeripheral()
Register a callback to monitor discover peripherals.see method connect()
.
Once found a peripheral callback.
Examples
ble;
param.name
-String
- Peripheral's name.param.identifier
-String
- Peripheral's identifier.Using connection,see methodconnect()
.param.RSSI
-Number
- Peripheral received signal strength indicator....
- (broadcast information)
registerDidUpdateValueForCharacteristic()
Register a callback to monitor characteristic value.
Characteristic value did update callback.You can get all peripheral sending data from here.
Examples
ble;
param.UUID
-String
- Characteristic UUID.param.value
-String
- Characteristic value. ======= Simple ble api for react native
f001669d457ad68bec621814dff0742bdf3d892b