React Native app freezes for continuous data read from BLE device

406 Views Asked by At

I successfully receive and read the data from BLE device using react-native-ble-plx library.

Listener receives the data every 10ms or 20ms but UI freezes ~1min afterwards.

What is the proper way to handle this scenario?

class DataReceiver extends React.Component {

  ...

  characteristicListener = async (error, characteristic) => {
    if (error) {
      // handle error
    } else {
      // read data
      //parse data/
      // add new data to data object
    }
  };
  
  startReadingData = async () => {
    ...
    
    action.monitorCharacteristic({
      serviceUUID: SERVICE_UUID,
      characteristicUUID: CHAR_UUID,
      listener: this.characteristicListener,
    });
    
    ...
  }

  render() {
     ...
  }
}

function mapStateToProps(state) {
  return {
    ...
  };
}

function mapDispatchToProps(dispatch) {
  return {
    action: bindActionCreators(
      {
        writeCharacteristic,
        monitorCharacteristic,
        readCharacteristic,
      },
      dispatch,
    ),
    dispatch,
  };
}

export default connect(mapStateToProps, mapDispatchToProps)(DataReceiver);
0

There are 0 best solutions below