Skip to main content

A Python library for DLMS/COSEM

Project description

A Python library for DLMS/COSEM.

codecov run-tests build-docs

dlms_logo

Installation

We only support Python 3.6+

pip install dlms-cosem

Documentation

Full documentation can be found at www.dlms.dev

About

dlms-cosem is designed to be a tool with a simple API for working with DLMS/COSEM enabled energy meters. It provides the lowest level function, as protocol state management, APDU encoding/decoding, APDU encryption/decryption.

The library aims to provide a sans-io implementation of the DLMS/COSEM protocol so that the protocol code can be reused with several io-paradigms. As of now we provide a simple client implementation based on blocking I/O. This can be used over either a serial interface with HDLC or over TCP.

We have not implemented full support to be able to build a server (meter) emulator. If this is a use-case you need, consider sponsoring the development and contact us.

Supported features

  • AssociationRequest and AssociationRelease
  • GET, GET.WITH_BLOCK
  • SET
  • ACTION
  • DataNotification
  • GlobalCiphering - Authenticated and Encrypted.
  • HLS-GMAC auth
  • Selective access via RangeDescriptor
  • Parsing of ProfileGeneric buffers

Example use:

A simple example:

from dlms_cosem.clients.dlms_client import DlmsClient
from dlms_cosem import enumerations, cosem

# read current client invocation counter
with DlmsClient.with_tcp_transport(
    server_logical_address=1,
    client_logical_address=16,
    host="localhost",
    port=4059
).session() as client:

    data = client.get(
        cosem.CosemAttribute(
            interface=enumerations.CosemInterface.DATA,
            instance=cosem.Obis(0, 0, 0x2B, 1, 0),
            attribute=2,
        )
    )

Look at the different files in the examples folder get a better feel on how to fully use the library.

Supported meters

Technically we aim to support any DLMS enabled meter. The library is implementing all the low level DLMS, and you might need an abstraction layer to support everything in your meter.

DLMS/COSEM specifies many ways of performing tasks on a meter. It is customary that a meter also adheres to a companion standard. In the companion standard it is defined exactly how certain use-cases are to be performed and how data is modeled.

Examples of companion standards are:

  • DSMR (Netherlands)
  • IDIS (all Europe)
  • UNI/TS 11291 (Italy)

On top of it all your DSO (Distribution Service Operator) might have ordered their meters with extra functionality or reduced functionality from one of the companion standards.

We have some meters we have run tests on or know the library is used for in production

  • Pietro Fiorentini RSE 1,2 LA N1. Italian gas meter
  • Iskraemeco AM550. IDIS compliant electricity meter.

Development

This library is developed by Palmlund Wahlgren Innovative Technology AB. We are based in Sweden and are members of the DLMS User Association.

If you find a bug please raise an issue on Github.

We welcome contributions of any kind.

We add features depending on our own, and our clients use cases. If you need a feature implemented please contact us.

Training / Consultancy / Commercial Support

We offer consultancy service and training services around this library and general DLMS/COSEM. If you are interested in our services just reach out to us.

If you have implemented a solution based on this library we also offer a commercial support scheme.

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Calendar Versioning

Unreleased

Added

Changed

Deprecated

Removed

Fixed

  • Fixed missing state management for general ACTION usage

Security

[21.2.1] - 2021-02-18

Fixed

  • Fixed #23. Typo in A-XDR Parser. Just referenced the function and did not call it. Now DLMS data is interpreted correctly.

  • Fixed #20. It was possible that not calling the .shutdown() on socket before disconnecting made remote modems on meters, that have an embedded TCP/IP stack, keep the socket open and blocking subsequent calls.

[21.2.0] - 2021-01-28

Added

  • Support for basic SET service. No support for WITH_LIST or service specific block transfer

[21.1.2] - 2021-01-22

Fixed

  • The standard DLMS way of dealing with timezones in datetime are via UTC offset. But the offset is the deviation from normal time to UTC not deviation from UTC. This results in -60 min deviation for UTC+01:00 for example. Previous solution assumed 60 min for UTC+01:00. Solved by negating all values for offset. Note that some DLMS companion standards handles the offset the previous way and in the future there will be need to handle both ways correctly.

  • Included typing-extensions in required packages.

[21.1.1] - 2021-01-13

Added

  • Better handling of TCP errors in BlockingTcpTransport

Changed

  • It is now explicitly possible to connect and disconnect a transport in the DlmsClient instead of it being done automatically in .associate() and .release_association(). Context manager .session() works the same.

  • Client to server challenge of DlmsConnection is always created independent of auth method. But only used if needed.

Removed

  • Removed conformance validation in DlmsConnection. It seems like meters don't always follow it so better to leave it up to the client.

[21.1.0] - 2021-01-12

Added

  • HDLC transport implementation
  • TCP transport implementation
  • DlMS client implementation
  • Support for Get service including service specific block transfer
  • Support for selective access via range descriptor
  • Support for HLS authentication using HLS-GMAC.
  • Support for GlobalCiphering
  • Parsing of ProfileGeneric buffer

Changed

  • Changed project versioning scheme to Calendar versioning

v0.0.2

Changed

  • UDP messages are now based WrapperProtocolDataUnit to be able to reuse WrapperHeader for TCP messages.
  • Parsing of DLMS APDUs

v0.0.1

Initial implementation.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dlms-cosem-21.2.2rc1.tar.gz (79.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dlms_cosem-21.2.2rc1-py3-none-any.whl (118.8 kB view details)

Uploaded Python 3

File details

Details for the file dlms-cosem-21.2.2rc1.tar.gz.

File metadata

  • Download URL: dlms-cosem-21.2.2rc1.tar.gz
  • Upload date:
  • Size: 79.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.4.2 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.8.0 tqdm/4.23.3 CPython/3.6.4

File hashes

Hashes for dlms-cosem-21.2.2rc1.tar.gz
Algorithm Hash digest
SHA256 ec1710ae01c8b9eb4dcf33e59db1cae810c50f09fe5f2889f979de2118f3f57e
MD5 2f6326e42e0efad94b180e0da46cf44f
BLAKE2b-256 e76b3c525dc77ee1220d33f5ad83e34f87c0408c04a9db803f108fdf6f16ded0

See more details on using hashes here.

File details

Details for the file dlms_cosem-21.2.2rc1-py3-none-any.whl.

File metadata

  • Download URL: dlms_cosem-21.2.2rc1-py3-none-any.whl
  • Upload date:
  • Size: 118.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.4.2 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.8.0 tqdm/4.23.3 CPython/3.6.4

File hashes

Hashes for dlms_cosem-21.2.2rc1-py3-none-any.whl
Algorithm Hash digest
SHA256 dd27a7793a21b67a4d82bf580a336a5bcb0fe9f45b7f6e193b91bb3a53b75ff9
MD5 5b8840eccc54f82f917707f0aca2b84c
BLAKE2b-256 aece70c35ee94875220f52113d946c2867eeb024ce4ab89313e2b21a4d35acc5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page