Quantcast
Channel: Active questions tagged react-native+android - Stack Overflow
Viewing all articles
Browse latest Browse all 28469

How to render data from a buffer? React-Native Javascript

$
0
0

i'm new to react-native and i'm using the library react-native-ble-plx to connect a Heart Sensor to my app and show it's values.

At this point i managed to connect it via bluetooth and store the information on a buffer where i can see with console.log(buffer), as shown in next picture.

enter image description here

My question is how can i render this information to the application? I don't know how to handle it from that buffer.

edit: I specifically want the 2nd value of that buffer (the one that normally is 70)

Here is the code:

scanAndConnect() {
      this.manager.startDeviceScan(null,
                                   null, (error, device) => {
          this.info("Scanning...");

          if (error) {
            this.error(error.message);
            return;
          }
          console.log(device.name)
          //if (device && device.name == 'Inspire HR') {
            if (device && device.name == 'HX-00043494') {
            this.manager.stopDeviceScan()
             device.connect()
               .then((device) => {
                 this.info("Discovering services and characteristics ")
                 return device.discoverAllServicesAndCharacteristics()
           }).then((device) => {
                 this.info("Setting notifications")
            ``return this.Async_setupNotifications(device);
          })
          .then(() => {
            this.info("Listening...")
           return this.setupNotifications(device)

          }, (error) => {
            this.error(error.message)
          })
      }
    })`
  }


async Async_setupNotifications(device) {
 this.manager.characteristic  = device.characteristicsForService("0000180d-0000-1000-8000-00805f9b34fb");
const buf = Buffer.from(characteristic.value, "base64");
console.log(buf);
console.log (buf[1]);


this.manager.characteristic.isNotifying = true;
this.manager.characteristic.isReadable = true;


 if (error) {
   this.error(error.message)
             }
return ;
}

Thanks a lot for the help so far


Viewing all articles
Browse latest Browse all 28469

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>