Package: dlms-cosem
A Python library for DLMS/COSEM.Installationpip install dlms-cosemDocumentationFull documentation can be found atwww.dlms.devAboutdlms-cosemis 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 asans-ioimplementation
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 featuresAssociationRequest  and AssociationReleaseGET, GET.WITH_BLOCK, GET.WITH_LISTSETACTIONDataNotificationGlobalCiphering - Authenticated and Encrypted.HLS-GMAC, LLS, HLS-Common authSelective access via RangeDescriptorParsing of ProfileGeneric buffersExample use:A simple example of reading invocation counters using a public client:fromdlms_cosem.clientimportDlmsClientfromdlms_cosem.ioimportTcpTransport,BlockingTcpIOfromdlms_cosem.securityimportNoSecurityAuthenticationfromdlms_cosemimportenumerations,cosemtcp_io=BlockingTcpIO(host="localhost",port=4059)tcp_transport=TcpTransport(io=tcp_io,server_logical_address=1,client_logical_address=16)client=DlmsClient(transport=tcp_transport,authentication=NoSecurityAuthentication())withclient.session()asdlms_client:data=dlms_client.get(cosem.CosemAttribute(interface=enumerations.CosemInterface.DATA,instance=cosem.Obis(0,0,0x2B,1,0),attribute=2,))Look at the different files in theexamplesfolder get a better feel on how to fully
use the library.Supported metersTechnically 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 productionPietro Fiorentini RSE 1,2 LA N1. Italian gas meterIskraemeco AM550. IDIS compliant electricity meter.Itron SL7000Hexing HXF300LicenseThedlms-cosemlibrary is released under the Business Source License 1.1 .
It is not a fully Open Source License but will eventually be made available under an Open Source License
(Apache License, Version 2.0), as stated in the license document.Our goal with this licence is to provide enough freedom for you to use and learn from the software withoutharmful free-riding.You may make use of the Licensed Work for any Permitted Purpose other than a Competing Use.
A Competing Use means use of the Licensed Work in or for a commercial product or service that
competes with the Licensed Work or any other product or service we offer using the Licensed Work
as of the date we make the Software available.Competing Uses specifically include using the Licensed Work:as a substitute for any of our products or services;in a way that exposes the APIs of the Licensed Work; andin a product or service that offers the same or substantially similar
functionality to the Licensed Work.Permitted Purposes specifically include using the Software:for your internal use and access;for non-commercial education; andfor non-commercial research.For information about alternative licensing arrangements or questions about permitted use of the library,
please contact us atinfo(at)pwit.se.DevelopmentThis 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 add features depending on our own, and our clients use cases. If you
need a feature implemented please contact us.Training / Consultancy / Commercial Support / ServicesWe offer consultancy service and training services around this library and general DLMS/COSEM.
If you are interested in our services just reach atìnfo(at)pwit.seThe library is an important part of ourSmart meter platform Utilitarian, https://utilitarian.io. If you need to
collect data from a lot of DLMS devices or meters, deploying Utilitarian might be the smoothest
solution for you.ChangelogAll notable changes to this project will be documented in this file.The format is based onKeep a Changelog,
and this project adheres toCalendar VersioningUnreleasedAddedChangedDeprecatedRemovedFixedSecurity24.1.0 - 2024-01-22AddedSupport for HDLC over TCP via composition of IO-implementation separate from
transport implementation.Support for LLS (Low Level Security)Support for HLS (method 2) using common method of AES128-ECB.Structlog logging.Implemented VisibleStringData.DlmsConnectionSettings to handle manufacturer specific quirks in communication.ChangedChanged License from MIT to BSL v1.1Refactor of authentication to make it simpler support more authentication types. And make
it possible to supply manufacturer specific implementations.RemovedShorthand class methods to create DlmsClients. Now composition has to be used.FixedError in DataArray dlms data type[21.3.2] - 2021-11-07ChangedUpdated dependencies and made it a bit more lenient so installing in other environments
will allow for more versions.[21.3.1] - 2021-06-14AddedTo handle the more complicated parsing problem of GET.WITH_LIST with compound data
elements a new parser, DlmsDataParser, was added that focuses on only A-XDR DLMS data.
Hopefully this can be be used instead of the A-XDR Parser when the parsing of ACSE
services APDUs is built away[21.3.0] - 2021-06-08AddedAdded HDLC UnnumberedInformationFrame.Ability to set timeout of transport layer at client level.A simpler way to change client address and invocation counter of aDlmsClientto
that reuseing a connection goes smootherAddedfrom_stringonObisthat can parse any viable string as OBIS.Added GET.WITH_LIST service.ChangedRenamed classes to excludeApduin class names. To have it consistent over the
project.Simplified DataNotificationImproved handling of pre-established associationsUsing the wrong data to decrypt now raisesDecryptionErrorinstead of InvalidTagTheto_stringmethod onObisnow returns in the format1-8:1.8.0.255with a
possible override of the separator.RemovedRemoved thefrom_dotted,dotted_reprandverbose_reprfromObisFixedSome DLMS over TCP implementations will return partial data. TheBlockingTcpTransportnow keeps on trying to read the data until all data is
received. Fixes#35.Fixed a bug in the HDLC layer that prevented correct sending of segmented information
frames.[21.2.2] - 2021-03-02FixedFixed missing state management for general ACTION usage[21.2.1] - 2021-02-18FixedFixed#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-28AddedSupport for basic SET service. No support for WITH_LIST or service specific block
transfer[21.1.2] - 2021-01-22FixedThe 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-13AddedBetter handling of TCP errors inBlockingTcpTransportChangedIt is now explicitly possible to connect and disconnect a transport in theDlmsClientinstead 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.RemovedRemoved 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-12AddedHDLC transport implementationTCP transport implementationDlMS client implementationSupport for Get service including service specific block transferSupport for selective access via range descriptorSupport for HLS authentication using HLS-GMAC.Support for GlobalCipheringParsing of ProfileGeneric bufferChangedChanged project versioning scheme to Calendar versioningv0.0.2ChangedUDP messages are now based WrapperProtocolDataUnit to be able to reuse
WrapperHeader for TCP messages.Parsing of DLMS APDUsv0.0.1Initial implementation.