C# - 如何通过蓝牙连接小米智能秤

时间:2017-02-07 16:08:28

标签: java c# xamarin bluetooth

我需要使用C#

中的蓝牙连接到Xiaomi Smart Scale

这可能吗?

2 个答案:

答案 0 :(得分:0)

我看到github上的一些人已经做了一些项目来访问它(特别是JavaScript,Android,iOS),但我没有看到C#。

所以我说这绝对有可能。但也许不那么容易。

您可以尝试将this little JavaScript project移植到C#并亲自查看。

编辑:some insights关于找到实际的蓝牙设备。它很可能必须已与客户端计算机配对。

答案 1 :(得分:0)

经过几个小时的搜索,我找到了this个视频 我发现了MI_SCALE蓝牙设备

discovered MI_SCALE Bluetooth

代码为880f10a0dd92,命令为

  

node peripheral-explorer.js 880f10a0dd92

基于视频连接智能比例并接收数据:

    > peripheral with ID 880f10a0dd92 found
  Local Name        = MI_SCALE
  Manufacturer Data = 5701880f10a0dd92
  Service Data      = [object Object]
  Service UUIDs     = 181d
  services and characteristics:
  1800 (Generic Access)
  2a00 (Device Name)
    properties  read, write
    value       4d495f5343414c45 | 'MI_SCALE'
   2a01 (Appearance)
    properties  read
    value       800c | ' '
  2a02 (Peripheral Privacy Flag)
    properties  read, write
    value       00 | ' '
  2a04 (Peripheral Preferred Connection Parameters)
    properties  read
    value       6400c8000000d007 | 'd H   P'
  2a03 (Reconnection Address)
    properties  read, writeWithoutResponse, write
    value        | ''
  2a9d (Weight Measurement)
    properties  indicate
  00002a2f0000351221180009af100700
    properties  write, notify
  000015300000351221180009af100700
  000015310000351221180009af100700
    properties  write, notify
  000015320000351221180009af100700
    properties  writeWithoutResponse
  2a04 (Peripheral Preferred Connection Parameters)
    properties  read, write, notify
    value       0c000c000000c800 | '    H '
  000015420000351221180009af100700
    properties  read, write, notify
    value       0301 | ''
  000015430000351221180009af100700
    properties  read, write, notify
    value       0100 | ' '

但基于此代码:

'use strict';
const noble = require('noble');
let lastvalue = '';

noble.on('stateChange', state => {
  if (state === 'poweredOn') {
    noble.startScanning(['181d'], true);
  } else {
    noble.stopScanning();
  }
});

noble.on('discover', peripheral => {
  let serviceData = peripheral.advertisement.serviceData,
    unit = '',
    newval = false,
    measured;
  if (serviceData && serviceData.length) {
    for (let i in serviceData) {
      if (serviceData.hasOwnProperty(i)) {
        let data = serviceData[i].data.toString('hex');
        switch (data.substr(0, 2)) {
        case '03':
          unit = 'lbs';
          newval = true;
          break;
        case 'a3':
          unit = 'lbs';
          break;
        case '12':
          unit = 'jin';
          newval = true;
          break;
        case 'b2':
          unit = 'jin';
          break;
        case '22':
          unit = 'kg';
          newval = true;
          break;
        case 'a2':
          unit = 'kg';
          break;
        default:
          unit = '';
          break;
        }
        measured = parseInt(data.slice(4, 6) + data.slice(2, 4), 16) * 0.01;
        measured = unit === 'kg' ? measured / 2 : measured;
        if (unit) {
          if (lastvalue !== measured && !newval) {
            console.log('Last measured: ' + measured + ' ' + unit);
          } else if (newval && lastvalue !== measured) {
            console.log('New measure: ' + measured + ' ' + unit);
          }
          lastvalue = measured;
        }
      }
    }
  }
});
 

我使用serviceData变量,最后我体重

但我的问题是 什么是简单方法在C#中使用此方法? 如果我使用贵族我应该在任何用户系统上安装vs和node.js以及贵族和Zadig并且太复杂了

另一个问题,例如在回收数据中

  

2a03(重新连接地址)       属性read,writeWithoutResponse,write

这些属性是什么以及如何使用它们?