php读取蓝牙电子秤,使用ionic/cordova读取小米蓝牙体重秤数据

一开始使用nordic app调试,可以直接读出数据,天真的以为体重秤都是使用的标准格式,然后就搜出了阿里体重秤格式(http://gaic.alicdn.com/ztms/ble-protocol/%E9%98%BF%E9%87%8C%E5%B0%8F%E6%99%BA%E8%93%9D%E7%89%99%E9%80%9A%E8%AE%AF%E5%8D%8F%E8%AE%AE-%E4%BA%91%E7%AB%AF%E7%89%88%E7%A7%A4.pdf)

结果尝试了不行,又搜索,找到了小米的格式(https://github.com/oliexdev/openScale/wiki/Xiaomi-Bluetooth-Mi-Scale)

ionic3测试程序如下:

import { Component } from '@angular/core';

import { NavController } from 'ionic-angular';

import 'rxjs/add/operator/toPromise';

// import { BluetoothSerial } from '@ionic-native/bluetooth-serial';

import { BLE } from '@ionic-native/ble';

@Component({

selector: 'page-home',

templateUrl: 'home.html',

providers: [BLE]

})

export class HomePage {

constructor(

public navCtrl: NavController,

private ble: BLE

) {

}

test1() {

console.log("scan");

this.ble.scan([], 10).subscribe(device => {

console.log(JSON.stringify(device));

}, error => {

console.log(error);

});

}

test2() {

console.log("connect");

this.ble.connect('88:0F:10:A1:22:AC').subscribe(data => {

console.log(data);

console.log(JSON.stringify(data));

},

error => {

console.log(error);

}

);

}

test4() {

console.log("read");

this.ble.startNotification('88:0F:10:A1:22:AC', '181d', '2a9d').subscribe(buffer => {

var d = new Uint8Array(buffer);

console.log(d);

});

}

test3() {

}

test5() {

console.log("Notification");

this.ble.stopNotification('88:0F:10:A1:22:AC', '181d', '2a9d').then(buffer => {

console.log(buffer);

});

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值