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. How To Read Single Obis Code With Python

How to read single Obis code with python

By Reese , 21 July, 2023
Forums
Gurux.DLMS

Hi

I need to know how to read a single Obis code with python, i've tried the following obis code which is for voltage value 1.1.32.7.0.255, I've been using GXDLMSDemandRegister, GXDLMSData, GXDLMSRegister and all I get is an error.

- Is it possible to pass an obis code as a string to those functions?
- is it possible to read single obis code without reading the getAssociationView first?

Also, among all the codes I've been using lately, this is the most generic one
obis = "1.1.32.7.0.255"
obj = GXDLMSRegister (obis, sn=1)
val = self.read(obj, 2)
self.showValue(2, val)

I also used this code, to separate obis code from index
main.py
reader.initializeConnection()
voltage = 0.0
try:
obis = "1.1.32.7.0.255.2"
voltage = reader.readByObis(obis=obis)
reader.showValue(2, voltage)
except Exception as ex:
print(ex)
GXDLMSReader.py
def readByObis(self, obis):
try:
aObjects = []
tmp = obis.split(":")
if len(tmp) != 2:
raise ValueError("Invalid Logical name or attribute index.")
aObjects.append((tmp[0].strip(), int(tmp[1].strip())))
for k, v in aObjects:
obj = self.client.objects.findByLN(ObjectType.NONE, k)
if obj is None:
raise Exception("Unknown logical name:" + k)
val = reader.read(obj, v)
return val
except (KeyboardInterrupt, SystemExit):
self.media = None
raise
finally:
self.close()

But nothing happend :(

Reese

3 years ago

I solved it, I found the way…

I solved it, I found the way to get it done :)
But it has a problem, It only works if I use GetAssociationView(), and data are saved in a text file named logFile.text (output file).
Is it possible read data from the meter but without saving data in a file?

great job with the library

Profile picture for user Kurumi

Kurumi

3 years ago

Hi, You don't need the…

Hi,

You don't need the association view or you can save it to the file so it's not read from the meter after the initial read. You can use -o output.xml argument for that.

You can also add objects like this

obj = GXDLMSRegister ("OBIS CODE")
self.read(obj, 2)

BR,
Mikko

Reese

3 years ago

Hi, I did that and It works…

Hi,

I did that and It works but just one time, I'm reading the meter every 2 minutes. After the first read I get the following error Failed to receive reply from the device in given time.

Authentication: 0
ClientAddress: 0x10
ServerAddress: 0x4a92
Standard: 0
Data send failed. Try to resend 1/3
Data send failed. Try to resend 2/3
RX: 00:15:52 7E A0 21 21 00 02 2A 25 73 DC D6 81 80 12 05 01 80 06 01 3E 07 04 00 00 00 01 08 04 00 00 00 01 07 22 7E 7E A0 21 21 00 02 2A 25 73 DC D6 81 80 12 05 01 80 06 01 3E 07 04 00 00 00 01 08 04 00 00 00 01 07 22 7E 7E A0 21 21 00 02 2A 25 73 DC D6 81 80 12 05 01 80 06 01 3E 07 04 00 00 00 01 08 04 00 00 00 01 07 22 7E

This is part of the code i'm using
reader = GXDLMSReader(settings.client, settings.media, settings.trace, settings.invocationCounter)
settings.media.open()
reader.initializeConnection()
voltage = 0.0
try:
obis = "1.1.32.7.0.255"
obj = GXDLMSRegister(obis)
resultV = reader.read(obj, 2)
settings.invocationCounter = 1 + obj.value
except Exception as ex:
data.update({'error': True, 'message': str(ex)})
else:
reader.showValue(2, resultV)
voltage = round(float(resultV / 10), 1)
data['measures'].update({'voltage': voltage})
data.update({'error': False, 'message': ''})

I read in a topic that it's necesary to increase the value of invocationCounter
What would be the problem ?

Profile picture for user Kurumi

Kurumi

2 years 11 months ago

Hi, There is a inactivity…

Hi,

There is a inactivity timeout and I believe that it's less than two minutes.
If you wait two minutes, the meter believes that the connection is closed and you need to establish a new connection.

You can try to establish the connection, read the data, and close the connection.

You can also try to read values every minute. If you are not receiving a reply. then try to establish a new connection.

BR,
Mikko

  • Create new account
  • Reset your password

Hire Us!

Latest Releases

  • Mon, 07/27/2026 - 12:37
    gurux.dlms.cpp 9.0.2607.2701
  • Thu, 07/23/2026 - 16:19
    gurux.dlms.java 4.0.96
  • Thu, 07/09/2026 - 14:34
    Gurux.DLMS.Python 1.0.201
  • Fri, 06/26/2026 - 16:32
    Gurux.Service 3.0.2606.2601
  • Wed, 06/24/2026 - 08:36
    Gurux.DLMS.Python 1.0.200

New forum topics

  • gurux_dlms.GXDateTime.GXDateTime object Error in Python
  • T_APPL_DATA_LN_N1 subtest 3 fails on an LN-only server regardless of the response to a non-existing-object GET
  • Version mismatch between Gurux.DLMS 9.x and Gurux.Common/Gurux.Serial 8.x
  • Service not known error on gprs communication
  • Help Needed: Interfacing Saral 100 Energy Meter with Microcontroller via RS232
More
RSS feed
Privacy FAQ GXDN Issues Contact
Follow Gurux on Twitter Follow Gurux on Linkedin