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. Forums
  3. Using GuruxDLMS.c With Arduino

Using GuruxDLMS.c with arduino

Forum Rules

Before commenting read Forum rules

Don't comment the topic if you have a new question.

You can create a new topic selecting correct category from Gurux Forum and then create a new topic selecting "New Topic" from the top left.

By luffy , 27 January, 2020
Forums
General discussion

Hello,

I need understanding and clarification regarding using the GuruxDLMS.c https://github.com/Gurux/GuruxDLMS.c with arduino.

I have used the Arduino_IDE example in the repo, but I am having a hard time to understand the working of the library.

My requirement is to read instantaneous Voltage, Current, and Power from the meter.

I am not able to figure out how to read these values using GuruxDLMS.c.

I have OBIS codes for these values as per Indian standards.

I need guidance on how to fetch these values from the meter

Thank you.

Profile picture for user Kurumi

Kurumi

6 years 4 months ago

Hello,

Hello,

DLMS is not easy protocol. Add and initialize register objects in same way that clock1 is added.
Then read values in loop.
Somethig like;
gxRegister r1;

void setup() {
bb_init(&frameData);
//Set frame size.
bb_capacity(&frameData, 128);
cl_init(&meterSettings, 1, 16, 1, DLMS_AUTHENTICATION_NONE, NULL, DLMS_INTERFACE_TYPE_HDLC);

cosem_init(BASE(r1), DLMS_OBJECT_TYPE_REGISTER, "OBIS CODE");

// start serial port at 9600 bps:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
}

void loop() {
int ret;
//Initialize connection.
ret = com_initializeConnection();
if (ret != DLMS_ERROR_CODE_OK)
{
return;
}
//Read register.
ret = com_read(BASE(r1), 2);
if (ret != DLMS_ERROR_CODE_OK)
{
return;
}
com_close();
}

BR,
Mikko

luffy

6 years 4 months ago

Hello,

Hello,

Thank you for your prompt response.

- I am using low authentication
- com_initializeConnection return OK.

I tried reading current, voltage registers using the code sample you gave above.
- current: cosem_init(BASE(r1), DLMS_OBJECT_TYPE_REGISTER , "1.0.31.7.0.255")
- voltage: cosem_init(BASE(r1), DLMS_OBJECT_TYPE_REGISTER , "1.0.32.7.0.255")

Reading current, voltage returns DLMS_ERROR_CODE_UNAVAILABLE_OBJECT.

I tried reading profile generic( gxProfileGeneric ), but it also returns unavailable object.
- gxProfileGeneric p1;
- cosem_init(BASE(p1), DLMS_OBJECT_TYPE_PROFILE_GENERIC , "1.0.94.91.0.255")
- com_read(BASE(p1), 2)

Can you tell me what does this error code means ?

Thank you Again. :)

Profile picture for user Kurumi

Kurumi

6 years 4 months ago

Hi,

Hi,

If you want to use Low aithentication you need to change initial settings for the client.
Change this:
cl_init(&meterSettings, 1, 16, 1, DLMS_AUTHENTICATION_NONE, NULL, DLMS_INTERFACE_TYPE_HDLC);
to;
cl_init(&meterSettings, 1, 16, 1, DLMS_AUTHENTICATION_LOW, "YOUR PASSWORD", DLMS_INTERFACE_TYPE_HDLC);

You also need to change the client address from 16 (0x10) to example 32 (0x20). I don't know what meter you try to read, so I don't know the right value. Try to read the meter with GXDLMSDirector and copy the value from there.
BR,
Mikko

luffy

6 years 4 months ago

Hello,

Hello,

I talked with the manufacturer, they gave me AARQ REQUEST bytes that should be sent:

7E A0 48 03 41 10 87 76 E6 E6 00 60 3A 80 02 02 84 A1 09 06 07 60 85 74 05 08 01 01 8A 02 07 80 8B 07 60 85 74 05 08 02 01 AC 0A 80 08 41 42 43 44 30 30 30 31 BE 10 04 0E 01 00 00 00 06 5F 1F 04 00 00 18 19 FF FF EB AB 7E

Can you tell me how on cl_init should be configured by this ?

Profile picture for user Kurumi

Kurumi

6 years 4 months ago

Hi,

Hi,

Change the password and all the settings are correct.

cl_init(&meterSettings, 1, 32, 1, DLMS_AUTHENTICATION_LOW, "ABCD0001", DLMS_INTERFACE_TYPE_HDLC);

BR,
Mikko

luffy

6 years 4 months ago

Hello,

Hello,

This worked like a charm.

Thank you very much.

Thank you for decoding the binary stream for me.

Can you point be to the documentation so that I can understand the protocol or at least help me decoding this kind of DLMS binary stream ?

Thank you :)

Profile picture for user Kurumi

Kurumi

6 years 4 months ago

Hi,

Hi,

DLMS is a standard and it's very well documented.
There are several documents that you need to read.

• IEC 62056-21 Direct local data exchange
• IEC 62056-42 Physical Layer Services and Procedures for Connection-Oriented Asynchronous Data Exchange
• IEC 62056-46 Data link layer using HDLC protocol
• IEC 62056-47 COSEM transport layers for IPv4 networks
• IEC 62056-53 COSEM application layer
• IEC 62056-61 OBIS Object identification system
• IEC 62056-62 Interface objects
• India Standard 15959 (Part-1) 2011: Data exchange for electricity meter reading, tariff and load control: companion specification
• India Standard 15959 (Part-2) 2016: Data exchange for electricity meter reading, tariff and load control: companion specification part2 for smart meter
• Italy Standard UNI/TS 11291-11-2

BR,

Mikko

luffy

6 years 4 months ago

Hello,

Hello,

Will read these spcifications.

Thank you very much.

luffy

6 years 4 months ago

Hello,

Hello,

I am calling cl_init:
cl_init(&meterSettings, 1, 32, 1, DLMS_AUTHENTICATION_LOW, "ABCD0001", DLMS_INTERFACE_TYPE_HDLC);
in setup

and in loop I read 3-4 registers:
ret = com_initializeConnection(); // open conn
cosem_init(BASE(r1), DLMS_OBJECT_TYPE_REGISTER , OBIS_VOLTAGE_R); // read V(R)
ret = com_read(BASE(r1), 2);
cosem_init(BASE(r1), DLMS_OBJECT_TYPE_REGISTER , OBIS_VOLTAGE_Y); // read V(Y)
ret = com_read(BASE(r1), 2);
ret = com_close();

The problem arises from the second iteration of the loop.
The com_initializeConnection returns DLMS_ERROR_CODE_AUTHENTICATION_FAILURE
If I called cl_init again on every loop iteration, it works fine.

I wanted to ask if cl_init is required everytime before openning connection ?

Thank you.

Profile picture for user Kurumi

Kurumi

6 years 4 months ago

Hi,

Hi,

Example reset all client settings after the read. This is done to release all buffers.
Find com_close and comment cl_clear(&connection->settings);

Now you can connect as many times as you want to.

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

Who's new

  • Tuanhgg
  • Adel
  • charnon
  • Paddles
  • Miguel Ángel
RSS feed
Privacy FAQ GXDN Issues Contact
Follow Gurux on Twitter Follow Gurux on Linkedin