just using a python script to access the Kaifa MA309 smartmeter using a serial RJ12 cable with an FT232 USB device on an armbian using python 3.7
I get the following error:
root@renegade:~# sudo python3 /root/EvnSmartmeterMQTTKaifaMA309.py
Raw data: 00f168fae9a19be90114ecb65b844b196ba9134aa7b66281e120000e9e319de1014379595ad70d9d7eae8203a9a888e562caccad55d635a357f9195ca1f9c6d28c9cae2a7e14d8b966f593885250ac5331c649db26d8e55414b9732befc549caef9daceb3c69a97a2191dbe38ef941628edfb676da51b67dbc6081d8b532a85872e9b7b82d5154ecb3a92cbe70ffe7870de3940a32b68bc563c933fd2a52eeb1ba2ddc1036c4b1f28640691941d55bc35655c9c5956272accf57a6a273c9aedb4dfa0fa8e5ec75c8cb8b9d2a2d512ed3dc5457da7ce153648e095be9cd87ccdb90174f91146bad9c8412c1dad55d045965a5d4850d5e4d1a2edfa7f545c955f9ab699d77c016a231fc590a8412b5babea5a1433116681451429b
Traceback (most recent call last):
File "/root/EvnSmartmeterMQTTKaifaMA309.py", line 61, in <module>
while tr.findNextFrame(msg, pdu):
File "/usr/local/lib/python3.7/dist-packages/gurux_dlms/GXDLMSTranslator.py", line 195, in findNextFrame
found = GXDLMS.getData(settings, data, reply, None)
File "/usr/local/lib/python3.7/dist-packages/gurux_dlms/GXDLMS.py", line 2269, in getData
GXDLMS.__getWirelessMBusData(settings, reply, target)
File "/usr/local/lib/python3.7/dist-packages/gurux_dlms/GXDLMS.py", line 1114, in __getWirelessMBusData
man = _GXCommon.decryptManufacturer(manufacturerID)
File "/usr/local/lib/python3.7/dist-packages/gurux_dlms/internal/_GXCommon.py", line 1810, in decryptManufacturer
return str(c2, c1, c)
TypeError: decoding str is not supported
root@renegade:~# lsusb
Bus 005 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 004 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 002: ID 0403:6001 Future Technology Devices International, Ltd FT232 Serial (UART) IC
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
I do not use a Wireless MBUS adapter.
Please take a look and would be glad if someone could help me!
thanks for the reply. The Meter is a Kaifa MA-309 and it pushes the data every 5seconds.
The serial parameters are 2400baud, 8 Bits and no parity which matches the specification (2400baud) from the energy provider.
Received data is not DLMS data. Is it possible that someone has changed the serial port settings? For example, change the baud rate?
Can you try this with GXDLMSDirector? Select "Tools" and "Serial Monitor". Set the same serial port settings and add received data here so I can compare them.
The problem is not in the code. It's on the data that you receive from the serial port and that is not valid data. So, I believe that one of your settings is wrong. What is the version number of the Gurux.Serial.Python that you are using?
You are using pyserial and not gurux-Serial. Your raw data is invalid and you need to find reason for that.
I propose that you find Windows PC and try to get data with GXDLMSDirector. It's the fastest way to solve is the problem on serial port settings or is it something else.
Hi Thomas,
Hi Thomas,
The received data looks strange. Is the meter sending this data as a push message or are you sending a request for the meter?
If the meter is sending this I believe your serial port settings are wrong. Check them first.
BR,
Mikko
Hi Mikko,
Hi Mikko,
thanks for the reply. The Meter is a Kaifa MA-309 and it pushes the data every 5seconds.
The serial parameters are 2400baud, 8 Bits and no parity which matches the specification (2400baud) from the energy provider.
Br, Thomas
Hi,
Hi,
Received data is not DLMS data. Is it possible that someone has changed the serial port settings? For example, change the baud rate?
Can you try this with GXDLMSDirector? Select "Tools" and "Serial Monitor". Set the same serial port settings and add received data here so I can compare them.
BR,
Mikko
BR,
Mikko
Hi Mikko,
Hi Mikko,
this is the code snippet used for setting the baud rate in python
tr = GXDLMSTranslator()
tr.blockCipherKey = GXByteBuffer(evn_schluessel)
tr.comments = True
ser = serial.Serial( port=comport,
baudrate=2400,
bytesize=serial.EIGHTBITS,
parity=serial.PARITY_NONE,
)
And here is the read-part:
while 1:
daten = ser.read(size=282).hex()
print('Raw data: ' + daten)
msg = GXDLMSTranslatorMessage()
msg.message = GXByteBuffer(daten)
xml = ""
pdu = GXByteBuffer()
tr.completePdu = True
while tr.findNextFrame(msg, pdu):
pdu.clear()
xml += tr.messageToXml(msg)
soup = BeautifulSoup(xml, 'lxml')
results_32 = soup.find_all('uint32')
results_16 = soup.find_all('uint16')
Unfortunatly I do not have a windows machine to try this with GXDLMSDirector
Br Thomas
Hi Thomas,
Hi Thomas,
The problem is not in the code. It's on the data that you receive from the serial port and that is not valid data. So, I believe that one of your settings is wrong. What is the version number of the Gurux.Serial.Python that you are using?
BR,
Mikko
Hi Mikko,
Hi Mikko,
here is the extract of "pip3 list"
root@renegade:~# pip3 list
Package Version
------------------- ---------
beautifulsoup4 4.10.0
certifi 2021.10.8
cffi 1.15.0
charset-normalizer 2.0.12
cryptography 36.0.1
distro-info 0.21
gurux-dlms 1.0.121
idna 3.3
iotop 0.6
lxml 4.3.2
Naked 0.1.31
paho-mqtt 1.6.1
pip 22.0.4
pycparser 2.21
pycryptodome 3.14.1
pycurl 7.43.0.2
PyGObject 3.30.4
pyserial 3.5
python-apt 1.8.4.3
PyYAML 6.0
requests 2.27.1
setuptools 60.9.3
shellescape 3.8.1
soupsieve 2.3.1
unattended-upgrades 0.1
urllib3 1.26.8
wheel 0.37.1
root@renegade:~#
How does the first bytes look like which you are expetcing?
Br, Thomas
Hi Thomas,
Hi Thomas,
You are using pyserial and not gurux-Serial. Your raw data is invalid and you need to find reason for that.
I propose that you find Windows PC and try to get data with GXDLMSDirector. It's the fastest way to solve is the problem on serial port settings or is it something else.
BR,
Mikko