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. Arduino Client Example For Multiple Meters

Arduino client example for multiple meters

By vladoam , 13 November, 2023
Forums
Gurux.DLMS

Hi, is there example on how to read two meters simultaneously with arduino? I'm using rs485 to ttl module. This is their client.init.
Client.init(true, 1, 145, DLMS_AUTHENTICATION_LOW, "11111111", DLMS_INTERFACE_TYPE_HDLC);
Client.init(true, 1, 146, DLMS_AUTHENTICATION_LOW, "11111111", DLMS_INTERFACE_TYPE_HDLC);
I searched on forum but I didn't find example how to read them all at once. Thanks.

Profile picture for user Kurumi

Kurumi

2 years 7 months ago

Hi, You need to read them…

Hi,

You need to read them one by one. Reading multiple meters simultaneously is not possible with Arduino is not possible because there is not enough memory available in Arduino.

It would be possible to read some instant data or register objects, but reading e.g. load profile (profile generic) will just use so much memory that this is not implemented.

BR,
Mikko

vladoam

2 years 7 months ago

Thanks for fast reply. So…

Thanks for fast reply. So basically I must duplicate all Client.init to Client1.init or ret = Client.GetData to ret1 = Client1.GetData. Sorry if this is stupid question.

Profile picture for user Kurumi

Kurumi

2 years 7 months ago

Hi, There are no stupid…

Hi,

There are no stupid questions.
You need to initialize the client, establish the connection read what you want to read , and then close the connection. After that initialize the 2th client for the new meter and do the reading, etc.

Client.init(true, 1, 145, DLMS_AUTHENTICATION_LOW, "11111111", DLMS_INTERFACE_TYPE_HDLC);
//Read
//Close connection
Client.init(true, 1, 146, DLMS_AUTHENTICATION_LOW, "11111111", DLMS_INTERFACE_TYPE_HDLC);
//Read
//Close connection

Next client, etc.

BR,
Mikko

vladoam

2 years 7 months ago

I will try it tomorrow. I'll…

I will try it tomorrow. I'll report it if i succeed or fail. :) Thanks again.

vladoam

2 years 6 months ago

So I tried to understand…

So I tried to understand code but failed, as I suspected. This is what is bothering me. If I put second meter in void setup:
void setup() {
GXTRACE(GET_STR_FROM_EEPROM("Start application"), NULL);
BYTE_BUFFER_INIT(&frameData);
//Set frame capacity.
bb_capacity(&frameData, 128);
Client.init(true, 1, 145, DLMS_AUTHENTICATION_LOW, "11111111", DLMS_INTERFACE_TYPE_HDLC);
//Second meter
Client2.init(true, 1, 146, DLMS_AUTHENTICATION_LOW, "11111111", DLMS_INTERFACE_TYPE_HDLC);

Now how can I call second meter in void loop to read and close connection?

void loop() {
int ret;
if (millis() - runTime > 5000)
{
runTime = millis();
GXTRACE(GET_STR_FROM_EEPROM("Start reading"), NULL);
//TODO: Change logical name of the frame counter if it's used.
ret = com_readAllObjects("0.0.43.1.0.255");
com_close();
}
}

Profile picture for user Kurumi

Kurumi

2 years 6 months ago

Hi, It's the easiest if you…

Hi,
It's the easiest if you have only one instance of the client and you init it on the loop like this:

void loop() {
if (meter1)
{
//Initialize meter 1 settings.
Client.init(true, 1, 145, DLMS_AUTHENTICATION_LOW, "11111111", DLMS_INTERFACE_TYPE_HDLC);}
else
{
//Initialize Meter 2 settings.
Client2.init(true, 1, 146, DLMS_AUTHENTICATION_LOW, "11111111", DLMS_INTERFACE_TYPE_HDLC);
}
ret = com_readAllObjects("0.0.43.1.0.255");
com_close();
}

This is only a simple example and not very sophisticated, but I hope you get the idea and you can modify it for your needs.

BR,
Mikko

vladoam

2 years 6 months ago

Thanks for code, but yea I…

Thanks for code, but yea I am unable to compile. Suprise suprise. I added int meter1 to pass meter1 is not declared in this scope error but then I get Client2 is not declared in this scope.
void loop() {
int ret;
int meter1;
if (millis() - runTime > 5000)
{
if (meter1)
{
//Initialize Meter 1 settings.
Client.init(true, 1, 145, DLMS_AUTHENTICATION_LOW, "11111111", DLMS_INTERFACE_TYPE_HDLC);}
else
{
//Initialize Meter 2 settings.
Client2.init(true, 1, 146, DLMS_AUTHENTICATION_LOW, "11111111", DLMS_INTERFACE_TYPE_HDLC);}
runTime = millis();
GXTRACE(GET_STR_FROM_EEPROM("Start reading"), NULL);
//TODO: Change logical name of the frame counter if it's used.
ret = com_readAllObjects("0.0.43.1.0.255");
com_close();
}
//ret = com_readAllObjects("0.0.43.1.0.255");
//com_close();

}
I know you can't babysit me through this code so if anybody has working example on how to read multiple meters with arduino I will be very grateful. Thanks

vladoam

2 years 6 months ago

There is some progress. I…

There is some progress. I can compile and run code like this:
void loop() {
int ret;
if (millis() - runTime > 5000)
{
Client.init(true, 1, 145, DLMS_AUTHENTICATION_LOW, "11111111", DLMS_INTERFACE_TYPE_HDLC);
runTime = millis();
GXTRACE(GET_STR_FROM_EEPROM("Start reading meter1"), NULL);
//TODO: Change logical name of the frame counter if it's used.
ret = com_readAllObjects("0.0.43.1.0.255");
com_close();
}
if (millis() - runTime > 9000)
{
Client.init(true, 1, 146, DLMS_AUTHENTICATION_LOW, "11111111", DLMS_INTERFACE_TYPE_HDLC);
runTime = millis();
GXTRACE(GET_STR_FROM_EEPROM("Start reading meter2"), NULL);
//TODO: Change logical name of the frame counter if it's used.
ret = com_readAllObjects("0.0.43.1.0.255");
com_close();
}
}
But it only reads meter with lower millis in this case 5000. I assume this is because millis resets every time when meter1 is read. How can I read one meter every 5 seconds and another every 9 seconds? Any help is appreciated.

vladoam

2 years 6 months ago

So I managed to make it work…

So I managed to make it work if I read all meters in same interval.
void loop() {
int ret;
if (millis() - runTime > 10000)
{
Client.init(true, 1, 145, DLMS_AUTHENTICATION_LOW, "11111111", DLMS_INTERFACE_TYPE_HDLC);
//runTime = millis();
GXTRACE(GET_STR_FROM_EEPROM("Start reading meter1"), NULL);
//TODO: Change logical name of the frame counter if it's used.
ret = com_readAllObjects("0.0.43.1.0.255");
com_close();
delay (200);
Client.init(true, 1, 146, DLMS_AUTHENTICATION_LOW, "11111111", DLMS_INTERFACE_TYPE_HDLC);
runTime = millis();
GXTRACE(GET_STR_FROM_EEPROM("Start reading meter2"), NULL);
//TODO: Change logical name of the frame counter if it's used.
ret = com_readAllObjects("0.0.43.1.0.255");
com_close();
}
}
I've added small delay between meter read because sometimes I get unable to initialise connection on second meter. Probably because esp32 still receives something from first meter. Also I comment out runTime = millis() in first meter and leave it on second. Can those two changes make some problems in code.Thanks.

Profile picture for user Kurumi

Kurumi

2 years 6 months ago

Hi, Adding a small delay is…

Hi,

Adding a small delay is good because some meters need it after the connection is closed. But that depends on the meter model.

I don't think that your changes will cause any problems.

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