Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 49083

How to get UUID from advertising data using Ionic?

$
0
0

Hi,

I’m trying to get the UUID from my nRF52840 BLE device with my Ionic Angular App without connecting to the device.

For this I’m using the Bluetooth Low Energy Central Plugin and i already get advertising data as a string, but i don’t know how to get the UUID from this string.

Here is the data i found:
image
When i try searching with the nRF connect app I’ll find the UUID so it should be possible
image
This is my code so far for the BluetoothService

export class BluetoothService {

 public logmsg: string[] = [];

 constructor(private bluetoothle : BluetoothLE, public alertController: AlertController) {
    console.log("init bluetooth");
    bluetoothle.initialize({ request: true, statusReceiver: false, restoreKey: "smartbuoyrestorekey"}).subscribe(result => {
      console.log("bluetooth init done");
      this.initializeSuccess(result);
    }, error => this.handleError(error));
  }

  public initializeSuccess(result) {
    if (result.status === "enabled") {
        console.log("Bluetooth is enabled.");
        this.log(result);

        this.startScan();
    } else {
      this.log("Bluetooth is not enabled:", "status");
      this.log(result, "status");
    }
  }

  startScanSuccess(result) {
    if (result.status === "scanStarted") {
        this.log("Scanning for devices (will continue to scan until you select a device)...", "status");
    }
    else if (result.status === "scanResult" && result.address === 'F2:AE:E5:72:6A:94') {
        if (!this.devices.some((device) =>{
            return device.address === result.address;

        })) {
            this.log('FOUND DEVICE ADVERTISMENT');
            this.log(result.advertisement);
        }
    }
  }
  
  public log(msg, level?) {
    level = level || "log";
    if (typeof msg === "object") {
        msg = JSON.stringify(msg, null, "  ");
    }
        this.logmsg.push(msg);
  }
}

Sorry if the answer is obvious but it is my first time working with BLE.

Thanks for every response.

Best regards

Niglmon

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 49083

Trending Articles



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