[英]How to read advertising data from BLE Ionic
對於iPhone,廣告數據為可讀格式,對於Android,則為十進制格式。 如何閱讀和解釋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廣告數據作為ArrayBuffer接收。 您需要使用javascripts String.fromCharCode
方法將其轉換為人類可讀的字符串:
let stringResult = String.fromCharCode.apply(null, new Uint8Array(buffer));
其中buffer
是response
對象的advertising
屬性。 您可以在此處找到BLE的ionic-native文檔。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.