使用 bluez/bluetoothctl/gatttool 连接到蓝牙智能/LE 体重秤 [英] Connecting to a Bluetooth smart/LE weight scale with bluez/bluetoothctl/gatttool

查看:28
本文介绍了使用 bluez/bluetoothctl/gatttool 连接到蓝牙智能/LE 体重秤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做什么:

我想将我的 Raspberry Pi 2 连接到蓝牙智能体重秤 (Medisana BS440) 并接收我的数据.

I want to connect my Raspberry Pi 2 to a Bluetooth Smart Weight Scale (Medisana BS440) and receive my Data.

我所知道的:

只有一个具有 5 个特征的有趣的主要服务:

There is just one interesting Primary Service with 5 Characteristics:

 - handle: 0x001a
     -  properties: 0x20 (Indication), char value handle: 0x1b uuid:00008a21-0000-1000-8000-00805f9b34fb
 - handle: 0x001d
     -  properties: 0x20 (Indication), char value handle: 0x1e uuid:00008a22-0000-1000-8000-00805f9b34fb
 - handle: 0x0020
     -  properties: 0x02 (Read-Only),  char value handle: 0x21 uuid:00008a20-00..
 - handle: 0x0022
     -  properties: 0x08 (Write-Only), char value handle: 0x23 uuid:00008a81-00..
 - handle: 0x0024
     -  properties: 0x20 (Indication), char value handle: 0x25 uuid:00008a82-00..

我使用了 Android 手机的 HCI-Snoop-Developer-Funktion,以查看相应的应用如何与我的体重秤通信.

I used the HCI-Snoop-Developer-Funktion of my Android-Phone, to see how the corresponding app communicates to my scale.

  1. 写入 0200 -> 0x1f(启用指示 0x1d)
  2. 读取 0x21 -> 0x21(值:37fb)
  3. 写入 0200 -> 0x1c(启用指示 0x1a)
  4. 写入 0200 -> 0x26(启用指示 0x24)
  5. write 02a31e2c0b -> 0x23(我在这里不完全理解,但我知道你是否在 02 之后取字节 (a3 1e 2c 0b -> 0b 2c 1e a3 -> 这是当前的 Unix 时间戳,但对于年份?1975 年?)

在第 4 步之后,有第一个指示(句柄 0x25),它为我提供了我存储的个人数据(我的身高、性别、年龄等)

after step 4. there is the first Indication (handle 0x25) which give me the stored personal data of me (my height, gender, age etc)

在第 5 步之后,有一些指示(句柄 0x1b 和句柄 0x1e)应该传输我的测量数据.(此时没有分析十六进制值)

after step 5. there are some Indications (handle 0x1b and handle 0x1e) which should transfer my measured data. (Didn't analyze the hex-values at this time)

我做了什么:

我在我的 raspi (内核 4.1.13) 上安装了 bluez.5.32,并使用 gatttool 执行了第 1 - 5 步,一切正常,直到第 5 步.我不知道没有从句柄 0x1b 和 0x1e 得到任何指示消息)在第 5 步之后没有任何反应.

I installed bluez.5.32 on my raspi (kernel 4.1.13), and did step 1 - 5 with gatttool and everything works fine till step 5. I don't get any Indication-messages from handle 0x1b and 0x1e) Nothing happens after step 5.

gatttool -t random -b DE:70:4A:XX:XX:XX -I
char-write-cmd 0x1f 0200
char-read-hnd 0x21 (37fb)
char-write-cmd 0x1c 0200
char-write-cmd 0x26 0200
char-write-cmd 0x23 0000000000

(我什至用 unix-timestamp-for 1975 做的事情......没有解决)

(I even do the thing with unix-timestamp-for 1975.. doesnt worked out)

经过数十亿小时后,我开始在我的 raspi 上使用 bluetoothctl(有一个 dbus 问题),并且我对 bluetoothctl 进行了同样的尝试.我启用了所有指示并将 0000000000 写入 hnd=0x23.切换到处理 0x1a 并且它起作用了!我收到了许多十六进制值,它们应该是我要搜索的数据.

After billions of hours I was getting bluetoothctl work on my raspi (there was a dbus-problem) and I tried the same with bluetoothctl. I enabled all Indications and write 0000000000 to hnd=0x23. Switched to handle 0x1a and it worked! I receive many hex-values that should be the data I'm searching for.

问题是什么?我想将 gatttool 用于我的目的,或者至少我想了解,为什么 gatttool 不起作用

So whats the problem? I want to use gatttool for my purpose or at least I want to understand, why it doesnt worked out with gatttool

当我使用bluetoothctl时,我只能选择并观看一个属性,并且在收到数据后,我的体重秤自动断开与我的树莓派的连接.所以当我选择特性 0x1a 时,我看不到特性 0x01d 的指示信息,反之亦然.

When I use bluetoothctl, I just can select and watch one attribute, and after receiving the data, my scale automatically disconnects to my raspberry. So when I select characteristic 0x1a, I cant see the indication-messages of characteristic 0x01d et vice versa.

当我使用 gatttool 或使用 bluetoothctl 时,我的 Pi 和我的 Scale 之间是否存在其他连接?或者在方式上有什么不同,他们如何与我的体重秤沟通?

Is there another connection between my Pi and my Scale when I'm using gatttool or when I'm using bluetoothctl? Or is there a difference in the way, how they communicate to my scale?

推荐答案

好的.. 我自己解决了这个问题.. 我需要做的就是将 ,,char-write-cmd" 更改为 ,,char-write-req".. 在我的 Android-Hci-Snoop 的日志文件中,它始终是一个写请求.不知道为什么一直没认出来...

Okay.. I solved this by my self.. all I needed to do was change ,,char-write-cmd" to ,,char-write-req".. In the log-file by my Android-Hci-Snoop it was always a write requst. Don't know why I didn't recognize it all the time...

如果有人有同样的问题 bluez/bluetoothd/bluetoothctl &dbus 像我一样(要在 bluetoothctl 中使用命令list-attributes"、select"、write",您必须在实验模式下执行 bluetoothd,例如bluetoothd -n -E",但每次执行此操作时,我都会收到一些错误消息,例如"D-Bus:名称已在使用中"或类似d'bus 设置失败:由于安全原因不允许连接拥有该服务..."(不记得确切的错误消息))

If someone has the same problem with bluez/bluetoothd/bluetoothctl & dbus like me (to use the commands "list-attributes", "select" "write" in bluetoothctl you have to execute bluetoothd in Experimental-Mode like "bluetoothd -n -E", but everytime I did this I got some error-messages like "D-Bus: name already in use" or something like "d'bus setup failed: connection is not allowed to own the service due to security..." (don't remember the exact errormessage) )

我做了什么:

  • 使用 ./configure 安装 bluez [...] --enable-experimental(阅读自述文件)

  • installing bluez with ./configure [...] --enable-experimental (read ReadMe-file)

sudo nano/etc/dbus-1/system.d/bluetooth.conf

sudo nano /etc/dbus-1/system.d/bluetooth.conf

--> 复制以 >policy user="root"> 开头的整个块,并将其粘贴到此块下方.然后我在两个块之一中将root"更改为pi"

--> copied the whole block that starts with >policy user="root">, and paste it below this block. Then I changed "root" to "pi" in one of the two blocks

如果有人想知道此量表如何提供测量结果,请查看此链接:一个小游戏/测验:你看到我的价值观了吗?(解释十六进制值)

这篇关于使用 bluez/bluetoothctl/gatttool 连接到蓝牙智能/LE 体重秤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆