spacemanspiff2007 / SmlLib

A library for the SML (Smart Message Language) protocol
GNU General Public License v3.0
27 stars 9 forks source link

Still open: InvalidBufferPos: Start pos bigger than buffer #15

Closed EckhardM closed 8 months ago

EckhardM commented 1 year ago

Even in version 1.2 I get the following error: File "/opt/daemon/ehz-daemon5.py", line 78, in <module> obis_values = sml_frame.get_obis() File "/usr/local/lib/python3.9/dist-packages/smllib/sml_frame.py", line 123, in get_obis self._parse_msg(data) File "/usr/local/lib/python3.9/dist-packages/smllib/sml_frame.py", line 108, in _parse_msg _lst[i] = v = self.get_value() File "/usr/local/lib/python3.9/dist-packages/smllib/sml_frame.py", line 27, in get_value raise InvalidBufferPos(f'Start pos bigger than buffer: {pos} > {self.buf_len}') smllib.errors.InvalidBufferPos: Start pos bigger than buffer: 244 > 244

`

spacemanspiff2007 commented 1 year ago

Could you provide the raw frame data so I can reproduce the issue?

EckhardM commented 1 year ago

Unfortunately not yet. It was running for many week without any error (every 2 seconds). I will enable the logging now so I will have the failing frame next time.

EckhardM commented 1 year ago

Here is a failing frame: 1b1b1b1b010101017605077707006200620072630101760107ffffffffffff05027d02560b0a01454d4800009f384672620165027d082b62016312980076050777070162006200726307017707ffffffffffff0b0a01454d4800009f3846070100620affff72620165027d082b7577070100603201010101010104454d480177070100600100ff010101010b0a01454d4800009f38460177070100010800ff641c010472620165027d082b621e52ff6501ddf5f40177070100020800ff0172620165027d082b621e52ff6501d4dc0d0177070100100700ff0101621b520053039f01010163ec0100760507770702620062007263020171016344d5001b1b1b1b1a008aa9

spacemanspiff2007 commented 1 year ago

Could you fall back to parse_frame() when get_obis() fails? This seems to be one of the rare messages where the shortcut doesn't work.

EckhardM commented 1 year ago

I currently catch the exception (with try/except) and ignore the problem frame. I will also try to investigate why a few frames are not working.

spacemanspiff2007 commented 1 year ago

You don't have to ignore the frame, use parse_frame() to get the values. get_obis() is a shortcut which works most of the time but in rare cases it doesn't and it seems you are hitting those.

EckhardM commented 1 year ago

How do I get the single values out of parse_frame()? (Sorry, maybe it's a stupid question.)

Nevertheless it's not a problem to skip one problem frame. The next one will be there in 2 seconds at latest.

spacemanspiff2007 commented 1 year ago

Typically in the middle message in the body there is a val_list

parse_frame()[1].message_body.val_list

Or generic like in sml2mqtt. Maybe it makes sense to improve the documentation ...

spacemanspiff2007 commented 8 months ago

I've modified the readme