# Decoding a float value in a payload function

**URL:** <https://www.thethingsnetwork.org/forum/t/decoding-a-float-value-in-a-payload-function/4395>\
**Category:** Application Development\
**Created:** [December 10, 2016, 2:11pm UTC](https://www.thethingsnetwork.org/forum/t/decoding-a-float-value-in-a-payload-function/4395 "2016-12-10T14:11:04Z")\
**Posts on this page:** 1\
**Showing post:** 18

<div class="post-metadata">

**Author:** ![csabagod](https://www.thethingsnetwork.org/forum/letter_avatar_proxy/v4/letter/c/43a26b/32.png) [@csabagod](https://www.thethingsnetwork.org/forum/u/csabagod)\
**Post date:** [March 2, 2017, 7:25pm UTC](https://www.thethingsnetwork.org/forum/t/decoding-a-float-value-in-a-payload-function/4395/18 "2017-03-02T19:25:56Z")

</div>

Hi,

Can someone send me a code for HX711 loadcell amplifier and DHT22 library?

I have tried this:

```
uint16_t weight = scale.get_units() * 100; 

// Read sensor values and multiply by 100 to effictively have 2 decimals
uint16_t humidity = dht.readHumidity(false) * 100;

// false: Celsius (default)
// true: Farenheit
uint16_t temperature = dht.readTemperature(false) * 100;

// Split both words (16 bits) into 6 bytes of 8
byte message[6];

message[0] = highByte(temperature);
message[1] = lowByte(temperature);
message[2] = highByte(humidity);
message[3] = lowByte(humidity);
message[4] = highByte(weight);
message[5] = lowByte(weight);

LMIC_setTxData2(1, message, sizeof(message), 0);
}

```

**On TTN side this is the payload function:**

function (bytes) {

var decodedValue1 = (bytes[4] \<\< 8) | bytes[5];  
var decodedValue2 = (bytes[2] \<\< 8) | bytes[3];  
var decodedValue3 = (bytes[0] \<\< 8) | bytes[1];

return { Weight: decodedValue1/100, Temp: decodedValue2/100, Hum: decodedValue3/100};  
}

**The result is this. It should be 4 decimal each:**

Hum 20.3  
Temp 1  
Weight 654.36

---

_[View the full topic](https://www.thethingsnetwork.org/forum/t/decoding-a-float-value-in-a-payload-function/4395)._
