Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Dark

Collapse
SHARUR
Community Wiki DLMS/COSEM Tools
Search Sign in

How to implement a minimal 20-line Python script to read active energy OBIS 1.0.1.8.0.255 via Gurux?

Scheduled Pinned Locked Moved General Discussion
pythonguruxcodesnippetobistutorial
3 Posts 2 Posters 17 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
  • M Offline
    M Offline
    marcus_vance
    wrote on last edited by
    #1

    đŸ›Ąī¸ 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?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sarah_jenkins
      wrote on last edited by
      #2

      Here is a complete, minimal 18-line script using gurux_dlms and gurux_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.WRAPPER wraps the xDLMS APDU in an 8-byte header 00 01 00 10 00 01 00 0D without HDLC flags or CRC overhead.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        marcus_vance
        wrote on last edited by
        #3

        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 07
        

        This stripped-down recipe is much cleaner for test automation than digging through large SDK classes. Thanks!

        1 Reply Last reply
        0

        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
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        Powered by NodeBB Contributors
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups