简体   繁体   中英

How to read advertising data from BLE Ionic

Advertising data is in readable format for iPhone, but it is in decimal format for android. How to read and interpret the advertising packet for android.

 this.scanner = this.ble.scan(["00EDSE-0000-00AE-9VVQ-9125475145125"], 1).subscribe((response) => {
              console.log("success scan.." + JSON.stringify(response));
              this.ble.connect(response.id).subscribe((response) => {
                this.toast.show("Successfully paired", '2000', 'bottom').subscribe((toast) => {
                  console.log(toast);
                  this.spinnerDialog.hide();
                });

Android advertising data is received as an ArrayBuffer . You need to convert it to a human readable string using javascripts String.fromCharCode method :

let stringResult = String.fromCharCode.apply(null, new Uint8Array(buffer));

Where buffer is the advertising property of you response object. You can find the ionic-native docs for BLE here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM