sandeepmistry / arduino-BLEPeripheral

An Arduino library for creating custom BLE peripherals with Nordic Semiconductor's nRF8001 or nR51822.
MIT License
462 stars 179 forks source link

Translate HEX value from BLEFloatCharacteristic #225

Closed labajo closed 6 years ago

labajo commented 6 years ago

Hi, firstly thanks for your job, it is awesome.

I have a question with the following example: https://github.com/sandeepmistry/arduino-BLEPeripheral/blob/master/examples/temp_sensor/temp_sensor.ino

The API to set a new temperature is tempCharacteristic.setValue(reading); where reading is a float, and the Characteristic is float too.

The problem is I cannot understand how can I convert the value to the right measure.

I'm using LightBlue to get a Temperature of: 0x33331344 (HEX) and a Humidity of 0x66666644(HEX). How can get the real value with a tool?

I used this https://www.scadacore.com/tools/programming-calculators/online-hex-converter/ But I could not see anything.

Thanks a lot.

labajo commented 6 years ago

Sorry for the mistake. It is a Little Endian Float. In node js / node red, you could use the following code:

let a = new Buffer([0x85, 0xeb, 0xb7, 0x41]);
let s = a.readFloatLE()
;
s = 22.989999771118164;