How to use the react-native-ble-manager.getConnectedPeripherals function in react-native-ble-manager

To help you get started, we’ve selected a few react-native-ble-manager examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github adafruit / glider / App.js View on Github external
useEffect(() => {
        console.log("new blestate", bleState);
        if (bleState == "permOk") {
        } else if (bleState == "started") {
            changePeripherals({"action": "clear"});
            BleManager.getConnectedPeripherals([]).then((peripheralsArray) => {
              for (p of peripheralsArray) {
                console.log(p);
                p.connected = true;
                BleManager.connect(p.id).then(() => {
                BleManager.retrieveServices(p.id).then((peripheralInfo) => {
                  console.log(peripheralInfo);
                  p.advertising.serviceUUIDs = [peripheralInfo.services[2].uuid];
                  changePeripherals({"action": "add", "peripheral": p});
                });
              });
              }
              console.log('Connected peripherals: ' + peripheralsArray.length);
            });
            changePeripherals({"action": "scan"});
        } else if (bleState == "disconnected") {
            // set a timeout and try to reconnect
github innoveit / react-native-ble-manager / example / App.js View on Github external
retrieveConnected(){
    BleManager.getConnectedPeripherals([]).then((results) => {
      if (results.length == 0) {
        console.log('No connected peripherals')
      }
      console.log(results);
      var peripherals = this.state.peripherals;
      for (var i = 0; i < results.length; i++) {
        var peripheral = results[i];
        peripheral.connected = true;
        peripherals.set(peripheral.id, peripheral);
        this.setState({ peripherals });
      }
    });
  }
github zhanguangao / react-native-ble-manager-demo / demo for v3.2.1 deprecated / app / BleManager.js View on Github external
getConnectedPeripherals() {
        BleManager.getConnectedPeripherals([])
            .then((peripheralsArray) => {
                console.log('Connected peripherals: ', peripheralsArray);
            });
    }
github CalPlug / Espressif_ESP32-Scale / React Native / BLE Demo / src / ble_manager / BLE.js View on Github external
handleAppStateChange(nextAppState) {
    if (this.state.appState.match(/inactive|background/) && nextAppState === 'active') {
      console.log('App has come to the foreground!')
      BleManager.getConnectedPeripherals([]).then((peripheralsArray) => {
        console.log('Connected peripherals: ' + peripheralsArray.length);
      });
    }
    this.setState({appState: nextAppState});
  }
github zhanguangao / react-native-ble-manager-demo / src / BleModule.js View on Github external
getConnectedPeripherals() {
        BleManager.getConnectedPeripherals([])
            .then((peripheralsArray) => {
                console.log('Connected peripherals: ', peripheralsArray);
            }).catch(error=>{

            })
    }
github innoveit / react-native-ble-manager / example / App.js View on Github external
handleAppStateChange(nextAppState) {
    if (this.state.appState.match(/inactive|background/) && nextAppState === 'active') {
      console.log('App has come to the foreground!')
      BleManager.getConnectedPeripherals([]).then((peripheralsArray) => {
        console.log('Connected peripherals: ' + peripheralsArray.length);
      });
    }
    this.setState({appState: nextAppState});
  }