Skip to main content
Home
for DLMS smart meters
Open source solutions for DLMS smart metering

Main navigation

  • Home
  • Products
  • About us
  • Open Source
  • Community
  • Forum
  • Downloads
User account menu
  • Log in

Breadcrumb

  1. Home
  2. Forums
  3. GXDLMSTranslator Help Needed (python)

GXDLMSTranslator help needed (python)

Forum Rules

Before commenting read Forum rules

Don't comment the topic if you have a new question.

You can create a new topic selecting correct category from Gurux Forum and then create a new topic selecting "New Topic" from the top left.

By Rufinus , 8 December, 2021
Forums
Gurux.DLMS

Hello,

The "Netz Noe" uses some strange encrypted mbus communication. I was able to decrypt the payload. but i cant get the XML of the decrypted APU. The Online Transltor at https://www.gurux.fi/GuruxDLMSTranslator can convert it to xml.

Here is the used code and the output from Online Translator:
tr = GXDLMSTranslator(TranslatorOutputType.SIMPLE_XML)
daten = recv(ser).hex()
if (daten == '' or daten[0:8] != "68010168"):
continue
print ("Daten: ", daten);
systemTitel = daten[22:38]
frameCounter = daten[44:52]
frame = daten[52:560]

frame = unhexlify(frame)
encryption_key = unhexlify(evn_schluessel)
init_vector = unhexlify(systemTitel + frameCounter)
cipher = AES.new(encryption_key, AES.MODE_GCM, nonce=init_vector)
apdu = cipher.decrypt(frame)
print("APDu: ", apdu.hex())
print("MessageToXml: ",tr.messageToXml(apdu.hex()))

--> Invalid DLMS framing.

APDu: 0f802306720c07e50c08030d0c0a00ffc4020223090c07e50c08030d0c0a00ffc40209060100010800ff060054d1a402020f00161e09060100020800ff0600557da802020f00161e09060100010700ff06000003f202020f00161b09060100020700ff060000005f02020f00161b09060100200700ff12092502020fff162309060100340700ff12092a02020fff162309060100480700ff12093502020fff1623090601001f0700ff1200de02020ffe162109060100330700ff12019102020ffe162109060100470700ff12005c02020ffe1621090601000d0700ff1002d302020ffd16ff090c31373832574343dec9ce1ecbacd76e660f64d2256fea8d

Result from Online Translator:
<DataNotification>
<LongInvokeIdAndPriority Value="80230672" />
<!--2021-12-08 13:12:10-->
<DateTime Value="07E50C08030D0C0A00FFC402" />
<NotificationBody>
<DataValue>
<Structure Qty="23" >
<!--2021-12-08 13:12:10-->
<OctetString Value="07E50C08030D0C0A00FFC402" />
<!--1.0.1.8.0.255-->
<OctetString Value="0100010800FF" />
<UInt32 Value="0054D1A4" />
<Structure Qty="02" >
<Int8 Value="00" />
<Enum Value="1E" />
</Structure>
<!--1.0.2.8.0.255-->
<OctetString Value="0100020800FF" />
<UInt32 Value="00557DA8" />
<Structure Qty="02" >
<Int8 Value="00" />
<Enum Value="1E" />
</Structure>
<!--1.0.1.7.0.255-->
<OctetString Value="0100010700FF" />
<UInt32 Value="000003F2" />
<Structure Qty="02" >
<Int8 Value="00" />
<Enum Value="1B" />
</Structure>
<!--1.0.2.7.0.255-->
<OctetString Value="0100020700FF" />
<UInt32 Value="0000005F" />
<Structure Qty="02" >
<Int8 Value="00" />
<Enum Value="1B" />
</Structure>
<!--1.0.32.7.0.255-->
<OctetString Value="0100200700FF" />
<UInt16 Value="0925" />
<Structure Qty="02" >
<Int8 Value="FF" />
<Enum Value="23" />
</Structure>
<!--1.0.52.7.0.255-->
<OctetString Value="0100340700FF" />
<UInt16 Value="092A" />
<Structure Qty="02" >
<Int8 Value="FF" />
<Enum Value="23" />
</Structure>
<!--1.0.72.7.0.255-->
<OctetString Value="0100480700FF" />
<UInt16 Value="0935" />
<Structure Qty="02" >
<Int8 Value="FF" />
<Enum Value="23" />
</Structure>
<!--1.0.31.7.0.255-->
<OctetString Value="01001F0700FF" />
<UInt16 Value="00DE" />
<Structure Qty="02" >
<Int8 Value="FE" />
<Enum Value="21" />
</Structure>
<!--1.0.51.7.0.255-->
<OctetString Value="0100330700FF" />
<UInt16 Value="0191" />
<Structure Qty="02" >
<Int8 Value="FE" />
<Enum Value="21" />
</Structure>
<!--1.0.71.7.0.255-->
<OctetString Value="0100470700FF" />
<UInt16 Value="005C" />
<Structure Qty="02" >
<Int8 Value="FE" />
<Enum Value="21" />
</Structure>
<!--1.0.13.7.0.255-->
<OctetString Value="01000D0700FF" />
<Int16 Value="02D3" />
<Structure Qty="02" >
<Int8 Value="FD" />
<Enum Value="FF" />
</Structure>
<OctetString Value="31373832574343DEC9CE1ECB" />
</Structure>
</DataValue>
</NotificationBody>
</DataNotification>

Any Help would be much appreciated. TIA

Rufinus

Profile picture for user Kurumi

Kurumi

4 years 6 months ago

Hi,

Hi,

You are using messageToXml, but you have removed the frame and you have PDU.
You need to use pduToXml to convert PDU to XML.

Peplace this line:
print("MessageToXml: ",tr.messageToXml(apdu.hex()))
with this:
print("PDUToXml: ", tr.pduToXml(apdu.hex()))

BR,
Mikko

Rufinus

4 years 6 months ago

hi,

hi,

thanks. I swear i had pduToXml as i started and it wasnt working. no it does.
Thanks for the pointer.

Profile picture for user Kurumi

Kurumi

4 years 6 months ago

Hi,

Hi,

You can also use findNextFrame to find frames from the byte stream.
If you set systemTitle, blockCipherKey and authenticationKey for the XML parser it will encrypt the data for you.

Your solution will work now, but it doesn't work when you have more complex data or if you want to use HDLC framing.

BR,
Mikko

  • Create new account
  • Reset your password

Hire Us!

Latest Releases

  • Tue, 06/09/2026 - 11:16
    gurux.dlms.java 4.0.95
  • Tue, 06/09/2026 - 10:03
    Gurux.DLMS.Python 1.0.199
  • Mon, 06/08/2026 - 13:39
    gurux.dlms.cpp 9.0.2606.0801
  • Mon, 06/01/2026 - 10:15
    gurux.dlms.cpp 9.0.2606.0101
  • Thu, 05/28/2026 - 16:06
    gurux.dlms.java 4.0.94

New forum topics

  • Error reading L&G Meter
  • Pass a TCP Client to GXNet
  • Australian EDMI Mk10D (Essential Energy area)
  • Strange mix of data notificiation vs get response
  • DLMS Connection
More

Who's new

  • Tuanhgg
  • Adel
  • charnon
  • Paddles
  • Miguel Ángel
RSS feed
Privacy FAQ GXDN Issues Contact
Follow Gurux on Twitter Follow Gurux on Linkedin