首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >蓝牙低能量重量测量特征时间戳

蓝牙低能量重量测量特征时间戳
EN

Stack Overflow用户
提问于 2020-09-07 11:54:15
回答 1查看 345关注 0票数 0

当我的设备没有连接时,我会缓冲数据,所以我需要实现时间戳,这样我就可以知道什么时候测量到了什么。

幸运的是,重量测量特征包括一个时间戳。

不幸的是,不清楚如何将这些数据写到包中,因为它不是普通的数据类型,而且它肯定不只是一个字节。

https://www.bluetooth.com/wp-content/uploads/Sitecore-Media-Library/Gatt/Xml/Characteristics/org.bluetooth.characteristic.weight_measurement.xml

我使用的是Adafruit的bluefruit arduino库,所以我尝试忽略模式,并在SI权重之后编写unix时间戳,但毫不奇怪,模式似乎不允许这样做,所以当我收到通知时,我看不到时间戳(但我仍然看到正确的权重读数)

下面是指向date_time特征的链接,这显然是它期望的https://www.bluetooth.com/wp-content/uploads/Sitecore-Media-Library/Gatt/Xml/Characteristics/org.bluetooth.characteristic.date_time.xml格式

我试着查看了一下API SDK,看看是否可以通过他们的nRF52更好地处理这件事,但学习曲线有点陡峭,我只需要完成这最后一点就能让我的设备工作。

更新:

对于任何其他有这个问题的人来说,解决方案是我使用notify方法的方式与adafruit示例中编写的方法相同

wmc.notify(notification, sizeof(notification))

因为我是通过缓冲数据的N x 7数组进行索引的,所以notification是指向我要馈送的1 x 7数组中第一个元素的指针,所以sizeof总是返回4(我假设的地址大小),而不是最初写入的数组的长度7

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-09-07 13:50:55

weight_scale服务有两个管理特征:

代码语言:javascript
复制
<Characteristic type="org.bluetooth.characteristic.weight_scale_feature" name="Weight Scale Feature">
  <Requirement>Mandatory</Requirement>
<Characteristic type="org.bluetooth.characteristic.weight_measurement" name="Weight Measurement">
  <Requirement>Mandatory</Requirement>

weight_measurement特征(uuid="2A9D")中,第一个字节是标志。其中<Bit index="1" size="1" name="Time stamp present">需要为1才能说明将有一个"Time Stamp“字段。"Time Stamp“字段为:

代码语言:javascript
复制
<Field name="Year"> <Format>uint16</Format> = 2 bytes
<Field name="Month"> <Format>uint8</Format> = 1 byte
<Field name="Day"> <Format>uint8</Format> = 1 byte
<Field name="Hours"> <Format>uint8</Format> = 1 byte
<Field name="Minutes"> <Format>uint8</Format> = 1 byte
<Field name="Seconds"> <Format>uint8</Format> = 1 byte

这使得“时间戳”字段有7个字节宽。

为了给出一个有效的例子,说明如何创建完整的数据包,如果你想要重量( Kg)和时间戳,它需要10字节长:

代码语言:javascript
复制
<Field name="Flags"> <Format>8bit</Format>  = 1 byte
<Field name="Weight - SI "> <Format>uint16</Format> = 2 bytes
<Field name="Time Stamp"> = 7 bytes

我已经使用Python计算了一个包的值:

代码语言:javascript
复制
import struct

flags = 0b00000010 # Include time. SI units
weight_raw = 38.1 #  Weight of 38.1 Kg
weight = int((weight_raw/5)*1000) # Formula from XML
year = 1972
month = 12
day = 11
hour = 23
minute = 22
second = 8

packet = struct.pack('<BHHBBBBB', flags, weight, year, month, day, hour, minute, second)
print(packet)

这将给出一个10字节长的包:

代码语言:javascript
复制
b'\x02\xc4\x1d\xb4\x07\x0c\x0b\x17\x16\x08'
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63771111

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档