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. Arduino Extract Values

Arduino Extract Values

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 technoshell , 6 September, 2020
Forums
Gurux.DLMS

Respected Sir

For the Arduino how can we get integer or float values of Voltage , Current etc.
The data is returned in the example as a structure

Secondly My code is
gxRegister reg1;
cosem_init(BASE(reg1), DLMS_OBJECT_TYPE_REGISTER, "1.0.12.7.0.255");
com_read(BASE(reg1), 3);
com_read(BASE(reg1), 2);
obj_toString(BASE(reg1), &data);
GXTRACE(PSTR("Voltage"), data);
obj_clear(BASE(reg1));
free(data)

It Prints the following:
VoltageIndex: 3 Value: Scaler: -- Unit: Voltage
Index: 2 Value: 245441

The voltage is 245.441.
Why did it print Scaler as -- and how do I get voltage value in float.? How do I get the unit? For eg Volts or KWH?

Thanks and Regards
Ajit

Profile picture for user Kurumi

Kurumi

5 years 10 months ago

Hi,

Hi,

There was an issue on obj_toString that is now fixed. Scaler is shown correctly. Value is not convert using scaler in ANSI C, so you need to multiply the value with a scaler.

Quantity: Voltage(U), Unit name: Volt, SI definition: V.

BR,
Mikko

technoshell

5 years 10 months ago

Thank You sir,

Thank You sir,

I meant to ask how to get the value of individual voltage and scaler as integers rather than a converted string &data.

Regards
Ajit

Profile picture for user Kurumi

Kurumi

5 years 10 months ago

Hi,

Hi,

reg1.scaler, reg1.unit and reg1.value.

BR,
Mikko

technoshell

5 years 9 months ago

Respected Sir

Respected Sir

I tried the following
gxRegister reg1;

cosem_init(BASE(reg1), DLMS_OBJECT_TYPE_REGISTER, "1.0.12.7.0.255"); // For DLMS India Voltage
com_read(BASE(reg1), 3);
sprintf(str,"%s",&reg1.scalar); // Also tried reg1.unit
GXTRACE(PSTR("Unit:"), str);

This gave junk value. I need to get scalar value to multiply with Voltage value to get the float value result.

com_read(BASE(reg1), 2);
t_val=var_toInteger(&reg1.value);
sprintf(str, "%d\n", t_val);
GXTRACE(PSTR("Voltage"), str);

This gave correct value 242568. The voltage was 242.568V
How do I extract scalar value so I can multiply the scalar by voltage value as advised by you.?
I should get a float value of multiplication.
When read by DLMS Director the scalar is showing 0.001 which is correct. Please advise how to extract this value as a float value.

Thank You

BR
Ajit

Profile picture for user Kurumi

Kurumi

5 years 9 months ago

Hi,

Hi,

You need to multiply value with scaler like this:
var_toInteger(&reg1.value) * pow(10, reg1.scaler);

ANSI C differs from other programming languages and it shows the value that is read from the meter and doesn't multiply it with a scaler.

BR,
Mikko

technoshell

5 years 9 months ago

Thank You Sir,

Thank You Sir,

Further how do I extract unit?
I tried like this

cosem_init(BASE(reg1), DLMS_OBJECT_TYPE_REGISTER, "1.0.12.7.0.255"); // For DLMS India Voltage
com_read(BASE(reg1), 3);
sprintf(str,"%s",&reg1.unit); // Also tried reg1.unit
GXTRACE(PSTR("Unit:"), str);

It didnt work. Please advise correct method?

BR
Ajit

Profile picture for user Kurumi

Kurumi

5 years 9 months ago

HI,

HI,

This is the correct way. Do you want to show the unit as a string? If so, use obj_getUnitAsString-method.

BR,
Mikko

technoshell

5 years 9 months ago

Respected Sir

Respected Sir

As advised by I used the following code to get voltage value
I get some strange output like this
Unit# :Voltage-740319.000000

gxRegister reg1;
double scale;
cosem_init(BASE(reg1), DLMS_OBJECT_TYPE_REGISTER, "1.0.12.7.0.255");
com_read(BASE(reg1), 3);
sprintf(str, "%s", &reg1.unit);
GXTRACE(PSTR("Unit"), str);

com_read(BASE(reg1), 2);
scale=var_toInteger(&reg1.value)*reg1.scaler;
sprintf(str, "%f\n", scale);
GXTRACE(PSTR("Voltage"), str);

I changed the code to original like this
gxRegister reg1;
double scale;
cosem_init(BASE(reg1), DLMS_OBJECT_TYPE_REGISTER, "1.0.12.7.0.255");
com_read(BASE(reg1), 3);
com_read(BASE(reg1), 2);
obj_toString(BASE(reg1), &data);
GXTRACE(PSTR("Voltage"), data);
obj_clear(BASE(reg1));
free(data);
I got the following output.

:Start reading :com_initializeConnection SUCCEEDED 0 :VoltageIndex: 3 Value: Scaler: 1 Unit: Voltage
Index: 2 Value: 246175
The value is correct but the scaler is still wrong.
In DLMS director the scaler is 0.001.

Please help

BR
Ajit

Profile picture for user Kurumi

Kurumi

5 years 9 months ago

Hi,

Hi,

Use scaler like this:

var_toInteger(&reg1.value) * pow(10, reg1.scaler);

technoshell

5 years 9 months ago

Respected Sir,

Respected Sir,

Thank you. It worked.

BR
Ajit

  • 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

  • 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
  • Connecting Meter to Agent via serial
  • Reading block profile with Compact array
More

Who's new

  • nostra
  • cuiVEAwINCoyynjjn
  • qlMlMNfbqjNumKgGFIo
  • randx-super.ru
  • Arturolooth
RSS feed
Privacy FAQ GXDN Issues Contact
Follow Gurux on Twitter Follow Gurux on Linkedin