问题
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