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

bytearray index out of range #49

Closed
ghost opened this issue Jul 14, 2018 · 10 comments
Closed

bytearray index out of range #49

ghost opened this issue Jul 14, 2018 · 10 comments

Comments

@ghost
Copy link

ghost commented Jul 14, 2018

My program stop as below:

Press Ctrl+C to quit.

2018-07-14 10:40:08.420778
Sensor - DF:25:8D:F6:45:47
Temperature: -21.46 C
Humidity: 57.0
Pressure: 1011.97

.......
Encoded value: �
not valid
Traceback (most recent call last):
File "/home/pi/.local/lib/python3.6/site-packages/ruuvitag_sensor/decoder.py", line 88, in decode_data
'temperature': self._get_temperature(decoded),
File "/home/pi/.local/lib/python3.6/site-packages/ruuvitag_sensor/decoder.py", line 59, in _get_temperature
temp = (decoded[2] & 127) + decoded[3] / 100
IndexError: bytearray index out of range
Traceback (most recent call last):
File "bryant.py", line 38, in
line_tem = str.format('Temperature: {0} C', data['temperature'])
TypeError: 'NoneType' object is not subscriptable

@ttu
Copy link
Owner

ttu commented Jul 14, 2018

Thanks for creating the issue.

Does this happen all the time or just occasionally?

Can you try if you can repeat the error with the code from Bleson branch?

@ghost
Copy link
Author

ghost commented Jul 14, 2018

it's will happened when I display on the screen. I will try the bleson branch first.

@ghost
Copy link
Author

ghost commented Jul 15, 2018

Could it be the return value it more than str data type
here i found some return value it super huge after decimal.
20180715_174257
Attached is the some image i took .

@ttu
Copy link
Owner

ttu commented Jul 15, 2018

Decoding the data fails and instead of dictionary it returns None.
https://github.com/ttu/ruuvitag-sensor/blob/master/ruuvitag_sensor/decoder.py#L95

As None is not dictionary data['temperature'] raises an exception.

There is something wrong with convert_data function, as it returns �.
https://github.com/ttu/ruuvitag-sensor/blob/master/ruuvitag_sensor/ruuvi.py#L42

Can you add log.info(raw) to that function so we can see what it tries to decode before it fails.

@fiasko
Copy link

fiasko commented Jun 3, 2019

I'm seeing similar errors in my raspbian with my Raspi 3B. I've started seing this error few weeks back, and I think it might have started after some Raspbian update. Anyway, I have several Ruuvitags with 1.2.12 firmware installed and I'm using RAW mode. What should I do?

Here are the errors:

Traceback (most recent call last):
  File "/home/pi/.local/lib/python3.5/site-packages/ruuvitag_sensor/decoder.py", line 94, in decode_data
    'temperature': self._get_temperature(decoded),
  File "/home/pi/.local/lib/python3.5/site-packages/ruuvitag_sensor/decoder.py", line 62, in _get_temperature
    temp = (decoded[2] & 127) + decoded[3] / 100
IndexError: bytearray index out of range
Decoded data is null. MAC: FC:34:B1:03:04:8B - Raw: 1502010611FF990403411540C84AFC72FE2FFFC50B89C6
Encoded value:
                not valid

There's also few other datapoints with same error messages:

MAC: FC:34:B1:03:04:8B - Raw: 1502010611FF990403411544C850FC72FE2FFFC60B89B9
MAC: FC:34:B1:03:04:8B - Raw: 1502010611FF990403411540C855FC72FE2FFFC30B83C7
MAC: FC:34:B1:03:04:8B - Raw: 1502010611FF990403411539C842FC72FE2FFFC60B89C5
MAC: FC:34:B1:03:04:8B - Raw: 1502010611FF990403411536C842FC72FE2FFFC40B95C0
MAC: FC:34:B1:03:04:8B - Raw: 1502010611FF990403421534C813FC72FE2FFFC50B8FD5
MAC: FC:34:B1:03:04:8B - Raw: 1502010611FF990403441536C810FC72FE2FFFC70B83C7

@ttu
Copy link
Owner

ttu commented Jun 3, 2019

@fiasko Thanks for the messages. I updated logging few days ago, so could get that RAW data and fix the encoding.

Ran some tests with the RAW data you provided and was wondering why everything seems to be working correctly. Then noticed that the app is using decoder for data type 2 and 4 although should be using data type 3 decoder.

Will make a fix for code that decides which decoder should be used. Thanks again for the data!

@ttu
Copy link
Owner

ttu commented Jun 3, 2019

@fiasko Fix is now in the master (352e0d7).

Could you try if it works now?

@ttu ttu added the in progress label Jun 4, 2019
@ttu ttu self-assigned this Jun 4, 2019
@fiasko
Copy link

fiasko commented Jun 4, 2019

Few hours of testing is now passed and so far I haven't seen any errors. I'm quite confident that the issue is now fixed. I'll let you know if new errors shows up.

@ttu
Copy link
Owner

ttu commented Jun 5, 2019

Added another fix to master (f6e6212).

This could also affect to this issue as after encoding other manufacturers device might have been considered as a RuuviTag sending data with data format 2/4 if broadcasted data contained r/.

e.g. error log from the first message had Encoded value: �, so it is possible that value was [something]r/�

@ttu ttu closed this as completed Jun 5, 2019
@fiasko
Copy link

fiasko commented Jun 6, 2019

I guess it's working. I haven't seen any error so far after ~24h of testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants