I've connected an RPi to my smart meter with a serial cable. The smart meter automatically starts sending 20 lines of data, about every 10 seconds.
Smart meter output example data:
Code:
/ISk5\2ME382-1003
0-0:96.1.1(4B414C37303035313039)
1-0:1.8.1(00180.724*kWh)
1-0:1.8.2(00001.416*kWh)
1-0:2.8.1(00000.000*kWh)
1-0:2.8.2(00000.000*kWh)
[...]
!
However, when retrieving the data using PySerial I often get data like this:
Code:
b'\x00\n'
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
\x00\x00\x00\x00\x00\x00\x00\x00
Eventually, I do get some data, but not even all.
My script:
Code:
import sys
import serial
ser = serial.Serial()
ser.baudrate = 9600
ser.bytesize=serial.SEVENBITS
ser.parity=serial.PARITY_EVEN
ser.stopbits=serial.STOPBITS_ONE
ser.xonxoff=0
ser.rtscts=0
ser.timeout=None
ser.port="/dev/ttyUSB0"
ser.open()
count=0
stack=[]
while count < 25:
p1_raw = str(ser.readline())
print(p1_raw)
count=count+1
ser.close()
exit
The problem seems to be with Python/PySerial. When using cu or minicom the data is received properly.
Is this perhaps a PySerial bug?