【问题标题】:C# - How connect to Xiaomi Smart Scale with BluetoothC# - 如何通过蓝牙连接小米智能体重秤
【发布时间】:2017-02-07 16:08:27
【问题描述】:

我需要在 C# 中使用蓝牙连接到Xiaomi Smart Scale

这可能吗?

【问题讨论】:

  • @Sid TnQ 我什么都没试过也不知道如何开始公司也没有回答

标签: java c# xamarin bluetooth


【解决方案1】:

我看到 github 上的一些人已经创建了几个项目来访问它(特别是 JavaScript、Android、iOS),但我看不到 C#。

所以我会说这绝对是可能的。但也许没那么容易。

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

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

【讨论】:

  • 谢谢@Kilazur 这个javascript代码应该如何使用?这个 JavaScript 如何连接蓝牙?
  • 我不能肯定地说,但据我所知,它只是列出了每个连接的蓝牙设备和一个名为noble 的模块,并为所有这些设备读取数据。唯一确定的方法就是尝试一下。
【解决方案2】:

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

discovered MI_SCALE Bluetooth

使用代码 880f10a0dd92 和命令

节点外设-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# 中使用此方法的简单方法是什么? 如果我使用 noble,我应该在任何用户系统上安装 vs 和 node.js 以及 noble 和 Zadig,而且太复杂了

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

2a03(重连地址) 属性读取、写入无响应、写入

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

【讨论】:

    猜你喜欢
    • 2016-03-20
    • 2021-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-04
    • 1970-01-01
    • 2020-01-27
    • 1970-01-01
    相关资源
    最近更新 更多