BLE temperature characteristic conversion

▼魔方 西西 提交于 2021-02-11 13:58:48

问题


I have a BLE app running on nrf51822 on Zephyr. Application is reading data from humidity and temperature sensor and exposes environmental sensing characteristic. Main exposed value is temperature (uuid:2A6E).

I have trouble reading this data via Bluez on linux. With nrfConnect app everything works no problem - I connect to the device and can see temperature reading - somewhere between 20 and 26 degrees (assigned to said uuid).

Via Bluez I can connect and read characteristic handle but the values does not make any sense to me. Here is my workflow:

$ sudo gatttool -t random -b <ADDR> -I
$ [<ADDR>][LE]> connect
$ Attempting to connect to <ADDR>
$ Connection successful
$ [<ADDR>][LE]> char-desc
# there are a lot of other chars here, I list the one that interests me 
$ handle: 0x0017, uuid: 00002a6e-0000-1000-8000-00805f9b34fb
$ [<ADDR>][LE]> char-read-hnd 0x17
$ Characteristic value/descriptor: 2e 09

So I get this value, and I cannot convert this in any way I know of to something that would make sense. I am familiar with this document: temperature xml but I cannot figure out how this might help me. Somehow Nordic's app can make sense out of it, and I would like to do that too.


回答1:


The temperature measurement follows the following rules:

  • it’s in little endian format so you first need to switch it to read as 0x092e

  • you convert that to decimal and you get (9x256+2x16+14) = 2350

  • then the value has an implied decimal exponent of -2, which means you take the value and divide by 100

This means the value read in this case is 23.50 Celsius



来源:https://stackoverflow.com/questions/61588874/ble-temperature-characteristic-conversion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!