1.1.3 • Published 7 years ago

react-native-zdh-bluetooth v1.1.3

Weekly downloads
2
License
ISC
Repository
github
Last release
7 years ago

react-native-zdh-bluetooth

npm version

Currently only support ios and require react-native >= 0.40.0

##Installation 1. Install library from npm

```bash
npm install react-native-zdh-bluetooth --save
```
  1. Link native code

    react-native link react-native-zdh-bluetooth

##Usage

import ble from 'react-native-zdh-bluetooth'

##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.scan();
// ble.scan(['XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX']);

stopScan()

Stop the scanning.

Examples

ble.stopScan();

connect(identifier)

Connect to a specified peripheral.

Arguments

  • identifier - String - Using the method you have to obtain the identifier before ,from method registerDiscoverPeripheral().

Examples

ble.connect('XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX')

disconnect()

Disconnect from a peripheral.

Examples

ble.disconnect();

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.write('ABCDEF0123456789','XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX')
  .then((result) =>{
    console.log(result.writeUUID+' : ' +result.message);
  })
  .catch((error) =>{
    console.log(error);
  })
  • 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.read('XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX')
  .then((result) =>{
    console.log(result.readUUID+' : '+result.value);
  })
  .catch((error)=>{
    console.log(error);
  })
  • 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.registerUpdateConnectionStatus((param)=>{
  console.log(param.connect+','+param.desc);
});
  • 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.registerDiscoverPeripheral((param)=>{
  console.log(param.name+','+param.identifier);
});
  • param.name - String - Peripheral's name.
  • param.identifier - String - Peripheral's identifier.Using connection,see method connect().
  • 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.registerDidUpdateValueForCharacteristic((param)=>{
  console.log(param.UUID+' : ',param.value);
});
  • param.UUID - String - Characteristic UUID.
  • param.value - String - Characteristic value.
1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago