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

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

问题描述

我想做什么:

我想将Raspberry Pi 2连接到Bluetooth Smart体重秤(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. 写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

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

(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 [...] --enable-experimental(阅读自述文件)安装bluez

  • 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连接到Bluetooth Smart/LE体重秤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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