spacemanspiff2007 / SmlLib

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

parse_frame fails #4

Closed EckhardM closed 2 years ago

EckhardM commented 2 years ago

get_obis is working fine but parse_frame is failing with my data:

from smllib import SmlStreamReader

file = open("sml.stream", "rb")

daten = file.read(396)

stream = SmlStreamReader()
stream.add(daten)
sml_frame = stream.get_frame()
if sml_frame is None:
    print('Bytes missing')

# Shortcut to extract all values without parsing the whole frame
obis_values = sml_frame.get_obis()
print(obis_values)

# return all values but slower
parsed_msgs = sml_frame.parse_frame()
for msg in parsed_msgs:
    # prints a nice overview over the received values
    print(msg.format_msg())

Output:

`[<obis: 0100000009ff, value: 06454d480104c56c97db>, <obis: 0100010800ff, status: 65954, unit: 30, scaler: -1, value: 117854333>, <obis: 0100020800ff, status: 65954, unit: 30, scaler: -1, value: 325350196>, <obis: 0100010801ff, unit: 30, scaler: -1, value: 117854333>, <obis: 0100020801ff, unit: 30, scaler: -1, value: 325350196>, <obis: 0100010802ff, unit: 30, scaler: -1, value: 0>, <obis: 0100020802ff, unit: 30, scaler: -1, value: 0>, <obis: 0100100700ff, unit: 27, scaler: -1, value: -1772>]
Traceback (most recent call last):
  File "/home/eckhard/smllibtest.py", line 24, in <module>
    parsed_msgs = sml_frame.parse_frame()
  File "/usr/local/lib/python3.9/dist-packages/smllib/sml_frame.py", line 82, in parse_frame
    raise ValueError(
ValueError: No start of SML Message found at 281: 0x77
7607000e1ef6d82a620062007263010176010107000e10e4480e0b06454d480104c56c97db0101635584007607000e1ef6d82b620062007263070177010b06454d480104c56c97db070100620affff7262016510e460887a77078181c78203ff0101010104454d480177070100000009ff010101010b06454d480104c56c97db0177070100010800ff640101a201621e52ff56000706507d0177070100020800ff640101a201621e52ff5600136473340177070100010801ff0101621e52ff56000706507d0177070100020801ff0101621e52ff5600136473340177070100010802ff0101621e52ff5600000000000177070100020802ff0101621e52ff5600000000000177070100100700ff0101621b52ff55fffff9140177078181c78205ff017262016510e46088010183026bcb474c058afe4d88b009910a958432f7c76ef11e1ba5d13d047051d5b189e1263e62d73058e3f03e219b24804ecac4010101632538007607000e1ef6d82e62006200726302017101639eda00

Is this a SML data problem?

spacemanspiff2007 commented 2 years ago

It's currently either get_obis() or parse_frame() but not both. If you call only parse_frame() it works properly or call parse_frame() before get_obis()

Also check #3 for a workaround for negative consumption

EckhardM commented 2 years ago

Thank you very much, that is working!

spacemanspiff2007 commented 2 years ago

Works with 0.8