How to implement a minimal 20-line Python script to read active energy OBIS 1.0.1.8.0.255 via Gurux?
-
ī¸ Technical Redaction & Safe Harbor Warning:
Network addresses and credentials use local sanitized loopback parameters.I want to build a lightweight automated test script in Python to read the total active energy (
1.0.1.8.0.255, Class 3 Register, Attribute 2) from a DLMS smart meter over TCP Port 4059 per IEC 62056-47 Section 5.2.
The official Gurux repositories have extensive generic wrappers across hundreds of files.
Is there a clean, standalone Python snippet under 20 lines that establishes the AARQ association and fetches the value directly? -
Here is a complete, minimal 18-line script using
gurux_dlmsandgurux_net(pip install gurux_dlms gurux_net
from gurux_dlms.GXDLMSClient import GXDLMSClient from gurux_dlms.objects.GXDLMSData import GXDLMSData from gurux_net.GXNet import GXNet from gurux_dlms.enums import InterfaceType # 1. Initialize Client (Public Client SAP 16, Server SAP 1, Wrapper Interface) cl = GXDLMSClient(useLogicalNameReferencing=True, clientAddress=16, serverAddress=1) cl.interfaceType = InterfaceType.WRAPPER media = GXNet("meter.example.internal", 4059) # Sanitized endpoint media.open() # 2. Establish AARQ Association for frame in cl.aarqRequest(): media.send(frame) cl.parseAareResponse(media.receive()) # 3. Read Active Energy Register (1.0.1.8.0.255, Attribute 2 = Value) reg = GXDLMSData("1.0.1.8.0.255") for frame in cl.read(reg, 2): media.send(frame) cl.updateValue(reg, 2, media.receive()) print(f"Total Active Import: {reg.value} Wh") media.close()Key Execution Detail:
Per IEC 62056-47 Section 5.2,InterfaceType.WRAPPERwraps the xDLMS APDU in an 8-byte header00 01 00 10 00 01 00 0Dwithout HDLC flags or CRC overhead. -
Actually, running this script against our bench test meter returned the exact reading
Total Active Import: 45291840 Wh.
The AARQ payload generated by the client was:00 01 00 10 00 01 00 2D 60 2B A1 09 06 07 60 85 74 05 08 01 01 BE 10 04 0E 01 00 00 00 06 5F 1F 04 00 00 1E 1D 00 00 07This stripped-down recipe is much cleaner for test automation than digging through large SDK classes. Thanks!
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better đ
Register Login