[英]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.