OlegZv / Python-CayenneLPP

Decoding library for CayenneLPP payload
Apache License 2.0
9 stars 4 forks source link

Floating point analog input values aren't decoded correctly #1

Closed amcewen closed 4 years ago

amcewen commented 4 years ago

The analog_input value type will include up to two decimal places of any floating-point value that's stored in it. Currently the decoder only returns integers, and so throws away the decimal part of any value.

For example, if I encode (in micropython on a pycom board:

lpp = CayenneLPP()
lpp.add_analog_input(1, 123.456)
lpp.add_analog_input(2, -123.456)

Then the resulting buffer is '010230390202cfc6'

Passing that into decode I get:

>>> decode('010230390202cfc6')
[{'value': 123, 'name': 'Analog Input', 'channel': 1}, {'value': -124, 'name': 'Analog Input', 'channel': 2}]

Changing the 100 in analog_input_output in methods.py to 100.0 seems to fix things. (Presumably there'll be similar issues in other methods like temperature, humidty, etc., but I've not tested those)

(It's not causing any issues for me, but I figured I should report it so you're aware of it)

OlegZv commented 4 years ago

@amcewen Thanks a lot for reporting this! Good catch

OlegZv commented 4 years ago

I appreciate the report @amcewen once again.

Changes have been pushed to the master branch