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

487

一开始使用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);
    });
  }

}

 

留下一个答复

Please enter your comment!
Please enter your name here