[英]How to read advertising data from BLE Ionic
Advertising data is in readable format for iPhone, but it is in decimal format for android. 对于iPhone,广告数据为可读格式,对于Android,则为十进制格式。 How to read and interpret the advertising packet for 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 advertising data is received as an ArrayBuffer . Android广告数据作为ArrayBuffer接收。 You need to convert it to a human readable string using javascripts String.fromCharCode
method : 您需要使用javascripts String.fromCharCode
方法将其转换为人类可读的字符串:
let stringResult = String.fromCharCode.apply(null, new Uint8Array(buffer));
Where buffer
is the advertising
property of you response
object. 其中buffer
是response
对象的advertising
属性。 You can find the ionic-native docs for BLE here . 您可以在此处找到BLE的ionic-native文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.