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.
Forums
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
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.
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
I will try it tomorrow. I'll…
I will try it tomorrow. I'll report it if i succeed or fail. :) Thanks again.
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();
}
}
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
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
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.
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.
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