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. Get Value Only

Get value only

By vladoam , 15 November, 2023
Forums
Gurux.DLMS

I want to push value with mqtt.
With this I can read meter and push to mqtt:

//Read active power 1.8.1
gxRegister rdn1;
cosem_init(BASE(rdn1), DLMS_OBJECT_TYPE_REGISTER, "1.0.1.8.1.255");
com_read(BASE(rdn1), 2);
obj_toString(BASE(rdn1), &data);
GXTRACE(GET_STR_FROM_EEPROM("Active1"), data);
client.publish(topic, data);
obj_clear(BASE(rdn1));
free(data);

How can I get value only like: 8560182 without: Index: 3 Value: Scaler: 1 Unit: None
Index: 2 Value: 8560182?

Profile picture for user Kurumi

Kurumi

2 years 6 months ago

Hi, You can get the register…

Hi,

You can get the register value as a string like this:

gxByteBuffer ba;
BYTE_BUFFER_INIT(&ba);
ret = var_toString(&rdn1.value, &ba);

BR,
Mikko

vladoam

2 years 6 months ago

Hi, I'm getting value 0…

Hi,
I'm getting value 0 instead of 8560182.
gxRegister rdn1;
cosem_init(BASE(rdn1), DLMS_OBJECT_TYPE_REGISTER, "1.0.1.8.1.255");
com_read(BASE(rdn1), 2);
obj_toString(BASE(rdn1), &data);
GXTRACE(GET_STR_FROM_EEPROM("Active1:"), data);
client.publish(topic, data);
obj_clear(BASE(rdn1));
free(data);
gxByteBuffer ba;
BYTE_BUFFER_INIT(&ba);
ret = var_toString(&rdn1.value, &ba);
Serial.println(ret);
sprintf(msg_out, "%d",ret);
client.publish(topic, msg_out);

Profile picture for user Kurumi

Kurumi

2 years 6 months ago

Hi, You are sending a error…

Hi,

You are sending a error code, not a string value. This is wrong:

sprintf(msg_out, "%d",ret);

Change it to:

int value = var_toInteger(&rdn1.value);
sprintf(msg_out, "%s", value);

BR,
Mikko

vladoam

2 years 6 months ago

There was some problems if I…

There was some problems if I used sprintf(msg_out, "%s", value); The board resets when it tries to read value. But this works form me. I'm posting it if anybody needs something like this.

//Read active power 1.8.1
gxRegister rdn1;
cosem_init(BASE(rdn1), DLMS_OBJECT_TYPE_REGISTER, "1.0.1.8.1.255");
com_read(BASE(rdn1), 2);
obj_toString(BASE(rdn1), &data);
GXTRACE(GET_STR_FROM_EEPROM("Active1:"), data);
int value1 = var_toInteger(&rdn1.value);
char msgout1[10];
snprintf(msgout1, sizeof(msgout1), "%u", value1);
client.publish(topic, msgout1);
obj_clear(BASE(rdn1));
free(data);
//Read active power 1.8.2
gxRegister rdn2;
cosem_init(BASE(rdn2), DLMS_OBJECT_TYPE_REGISTER, "1.0.1.8.2.255");
com_read(BASE(rdn2), 2);
obj_toString(BASE(rdn2), &data);
GXTRACE(GET_STR_FROM_EEPROM("Active2"), data);
int value2 = var_toInteger(&rdn2.value);
char msgout2[10];
snprintf(msgout2, sizeof(msgout2), "%u", value2);
client.publish(topic, msgout2);
obj_clear(BASE(rdn2));
free(data);

Now is there an option to send these as one string? like 123456|654321 when I read all values? And can i convert mac adddress from hex to asci and send it together with values like MAC123456|123456|654321? Maybe I should start new topic? Thanks

Profile picture for user Kurumi

Kurumi

2 years 6 months ago

Hi, My bad. This is a typo…

Hi,

My bad. This is a typo.

int value = var_toInteger(&rdn1.value);
sprintf(msg_out, "%d", value);

I'm glad that you solved this.

BR,
Mikko

vladoam

2 years 6 months ago

Hi. So, I managed to get all…

Hi. So, I managed to get all values that I need. Now I can push them as one message comma separated. And that is great. But how to get just value for Logical device name (mac address)? My idea is to strip MAC and use only integers of ldn.
gxData ldn;
cosem_init(BASE(ldn), DLMS_OBJECT_TYPE_DATA, "0.0.42.0.0.255");
com_read(BASE(ldn), 2);
obj_toString(BASE(ldn), &data);
GXTRACE(GET_STR_FROM_EEPROM("Logical Device Name"), data);
client.publish(topic, data);
obj_clear(BASE(ldn));
free(data);

Thanks.

Profile picture for user Kurumi

Kurumi

2 years 6 months ago

Hi, The Logical Device Name…

Hi,

The Logical Device Name usually is the serial number of the meter, not the MAC address. The content of the Logical Device Name is not defined by DLMS standards and different meters are using different values here.

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