Python Push Listener

11 posts / 0 new
Last post
tofuSCHNITZEL
Python Push Listener

Hi,

I was very happy to see that you provided a full example to receive and decrypt push messages from the meter with python a couple of days ago!

but after testing it I noticed that you read the serial until you encounter 7E but this byte can also occur as part of the "regular packet". its even quite often because if I let the python push listener run even though I get a push message every second, only once every 20 seconds a packet is received correctly and can be decrypted.

this issue bugged me also while trying to implement a simple serial reader script myself... and when I saw you provided an example I was hopefull that you figured it out how to read the push packet without relying on "reading until 7E" but instead something like... buffer the serial input until its a correct HDLC packet (with matching CRC and length data etc.)

I'm not sure how to tackle this problem so that its solved "correctly".
Maybe its something like: Read the serial and if the first byte you read is NOT 7E stop reading because we are "in the middle" of a packet.. (there is still the edge case that we could start reading in the middle of a serial burst and it COULD start with a 7E...)
so maybe the lib should then read the next bytes where the length of the whole packet is defined and then serial read only for this amount? so its save to assume that a whole DLMS push packet is in the buffer?

Happy for your thoughts on this...

cheers,
Tobias

Kurumi
Kurumi's picture

Hi Tobias,

Can you post one of the failed messages here so we can test with that?
BR,
Mikko

________________________________________
Mikko Kurunsaari
Gurux Ltd
http://www.gurux.fi

tofuSCHNITZEL

Hey,
I've uploaded the file for you here:

https://upload.bitconnect.at/files/output.txt

the command was:
python3 main.py -S /dev/ttyS7 -t Verbose -B X...X

and by the way:
on the WSL (windows subsystem on linux) bash the "available devices" is always empty.
but for example serial.tools.list_ports.comports() lists them all.

my naive approach was to just read 105 Bytes and check if first and last byte are the same... but I also saw that not all austrian smart meters send 105 Bytes long messages...

cheers,
Tobias

greenMike

Hello Tobias, I'm from Austria and I'm currently reading my smart meter. Can you give me a link for example a code?

And if you want, we can also keep in touch via e-mail

tofuSCHNITZEL

Hi, you need help with your mbus interface so you should check out this:
http://www.gurux.fi/comment/19798#comment-19798

tofuSCHNITZEL

Hey Mikko,
do you have an Idea how to go about reading the serial interface? since reading until 7E does not work... maybe the only way is to read and interpret the first bytes where the length is encoded...

Kurumi
Kurumi's picture

Hi,

It depends on what kind of framing your meter is using.
Are you receiving data that starts with 0x7E or something else?

BR,
Mikko

________________________________________
Mikko Kurunsaari
Gurux Ltd
http://www.gurux.fi

tofuSCHNITZEL

yes it starts and ends with 7E but 7E can also be part of the message so reading until 7E is not an option.

Kurumi
Kurumi's picture

Hi,

Gurux DLMS client can handle this. Just read bytes from the serial port and use GXDLMSClient.GetData method to get parsed value.

BR,
Mikko

________________________________________
Mikko Kurunsaari
Gurux Ltd
http://www.gurux.fi

tofuSCHNITZEL

yeah, isn't this what this script is doing?
https://github.com/Gurux/Gurux.DLMS.Python/blob/master/Gurux.DLMS.Push.L...
but this produces the output I sent above since it seems to not read some packages in full since the messages contain 7E also as part of the message...

Kurumi
Kurumi's picture

Hi,

This waits for 0x7e before the client tries to parse the data. Data parsing is done in GXDLMSClient getData-method. Use GXDLMSClient to parse the data. There are several reasons that might cause problems with data reading and GXDLMSClient can handle them all.

BR,
Mikko

________________________________________
Mikko Kurunsaari
Gurux Ltd
http://www.gurux.fi