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

2 years 10 months 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

2 years 10 months 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

2 years 10 months 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 9 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

  • Tue, 06/09/2026 - 11:16
    gurux.dlms.java 4.0.95
  • Tue, 06/09/2026 - 10:03
    Gurux.DLMS.Python 1.0.199
  • Mon, 06/08/2026 - 13:39
    gurux.dlms.cpp 9.0.2606.0801
  • Mon, 06/01/2026 - 10:15
    gurux.dlms.cpp 9.0.2606.0101
  • Thu, 05/28/2026 - 16:06
    gurux.dlms.java 4.0.94

New forum topics

  • Error reading L&G Meter
  • Pass a TCP Client to GXNet
  • Australian EDMI Mk10D (Essential Energy area)
  • Strange mix of data notificiation vs get response
  • DLMS Connection
More
RSS feed
Privacy FAQ GXDN Issues Contact
Follow Gurux on Twitter Follow Gurux on Linkedin