What's the best way to convert payload to decimal?


#1

Hi there,
I receive the payload information but I want to separate and convert to decimal like to show for example 37 (ºC).
This is possible?


#2

What do you send ? Do you use any encoding format ?


#3

rand.Seed(time.Now().UnixNano() / 10000)
temp := [2]byte{uint8(rand.Intn(25)), uint8(rand.Intn(100))}
pressure := [3]byte{uint8(rand.Intn(2)), uint8(rand.Intn(20)), uint8(rand.Intn(100))}
humidity := [2]byte{uint8(rand.Intn(100)), uint8(rand.Intn(100))}

//Create the payload, data rate and rx info.

payload := []byte{temp[0], temp[1], pressure[0], pressure[1], pressure[2], humidity[0], humidity[1]}


#4

You can use the Custom JavaScript Codec Functions in application configuration which allows you to program a simple JS decoder. The data you receive are decrypted and encoded in base 64 so you just have to convert this in decimal.

You are sending a random temperature between 0,00 °C and 25.99°C right ?


#5

It’s possible with a programing in go?


#6

I don’t know.

You can probably add your custom function in loraserver src code but the easiest way is to use the JS pre-script available.

It’s not hard at all, I didn’t know anything about JS and I managed to decode my payload in 30min.


#7

Thanks for your help :slight_smile: