Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error running Parse Example Code in Readme.md #16

Closed
jsavage opened this issue Jun 7, 2017 · 4 comments
Closed

Error running Parse Example Code in Readme.md #16

jsavage opened this issue Jun 7, 2017 · 4 comments

Comments

@jsavage
Copy link

jsavage commented Jun 7, 2017

The following is some example code under the heading of Parse Data within the Readme file:

from ruuvitag_sensor.ruuvi import RuuviTagSensor
from ruuvitag_sensor.decoder import UrlDecoder
full_data = '043E2A0201030157168974A5F41E0201060303AAFE1616AAFE10EE037275752E76692341412C3E672B49246AB9'
data = full_data[26:]
encoded = RuuviTagSensor.convert_data(data)
sensor_data = UrlDecoder().decode_data(encoded)
print(sensor_data)

When I run this code as follows , I get the following error:

$ python3 parse_data.py
Encoded value: (None, None) not valid
Traceback (most recent call last):
  File "/home/pi/.local/lib/python3.4/site-packages/ruuvitag_sensor/decoder.py", line 72, in decode_data
    decoded = bytearray(base64.b64decode(encoded, '-_'))
  File "/usr/lib/python3.4/base64.py", line 83, in b64decode
    s = _bytes_from_decode_data(s)
  File "/usr/lib/python3.4/base64.py", line 46, in _bytes_from_decode_data
    "string, not %r" % s.__class__.__name__) from None
TypeError: argument should be a bytes-like object or ASCII string, not 'tuple'
None
@mikaelho
Copy link

mikaelho commented Jun 8, 2017

Running Python 3.6.0, all I get with the above code is 'None'. No errors.

Which version of Python are you using?

@ttu
Copy link
Owner

ttu commented Jun 8, 2017

Forgot to update parse data example when added support for different data types. Also not sure if data in that example is valid. I'll have to inspect more.

b85047f#diff-12c3cc89af19a6fa3f633f7fca29f169R57

Can you try if this works?

from ruuvitag_sensor.ruuvi import RuuviTagSensor
from ruuvitag_sensor.decoder import UrlDecoder

full_data = '043E2A0201030157168974A5F41E0201060303AAFE1616AAFE10EE037275752E76692F23416A7759414D4663CD'
data = full_data[26:]

# convert_data returns a tuple which has data type id and encoded data
encoded = RuuviTagSensor.convert_data(data)

sensor_data = UrlDecoder().decode_data(encoded[1])

print(sensor_data)

@jsavage
Copy link
Author

jsavage commented Jun 8, 2017

Ok
That example seems to work although I suspect it may need example data with an identifier in it

pi@raspberrypi7:~ $ python3 parse_data2.py
{'identifier': None, 'pressure': 995.0, 'humidity': 30.0, 'temperature': 24.0}

Thanks

@ttu
Copy link
Owner

ttu commented Jun 8, 2017

Old firmware sent base91 encoded data and that example is still from that time. Good that you noticed this, so we got correct example to README.

Updated example 7fd32ec

@ttu ttu closed this as completed Jun 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants