Skip to main content
Home
for DLMS smart meters

Main navigation

  • Home
  • Products
  • About us
  • Open Source
  • Community
  • Forum
  • Downloads
User account menu
  • Log in

Breadcrumb

  1. Home
  2. Forums
  3. Make My Own DLMS Meter

Make my own DLMS Meter

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 blackhawk41, 16 December, 2022
Forums
Gurux.MQTT

Hello,

Currently i'm a student and working my final project assignment. my final project was creating my own kWH meter using DLMS protocol via TCP/IP and MQTT. i have reading this tutorial and i dont have any idea how to do that. this is my block diagram. i need help step by step how to do that

thank you very much

Image
Profile picture for user Kurumi

Kurumi

2 years 5 months ago

Hi,

Hi,

How to make the meter:
http://gurux.fi/Gurux.DLMS.Server

How to make a client:
http://gurux.fi/Gurux.DLMS.Client

The meter source code is here:
https://github.com/Gurux/GuruxDLMS.c/tree/master/Arduino_IDE/server

BR,
Mikko

blackhawk41

2 years 5 months ago

i've upload the arduino code.

i've upload the arduino code. how can i integrate the dlms server code and cs5460 sensor via ethernet dlms. i have no idea. thank you

Image
Profile picture for user Kurumi

Kurumi

2 years 5 months ago

Hi,

Hi,

Read this first.
http://gurux.fi/Arduino

I believe it will help you to get started.

BR,
Mikko

blackhawk41

2 years 5 months ago

i read that link and i follow

why my serial monitor result was different with yours. whats my fault ? thank you

Image
Profile picture for user Kurumi

Kurumi

2 years 5 months ago

Hi,

Hi,

I believe that your ESP32 serial port is different than Arduino Mega. For me it seems like old data is not read from the serial port before the new one is added. Try to add a small delay for the GXTRACE function or uncomment Serial1.flush();.

BR,
Mikko

blackhawk41

2 years 5 months ago

In reply to Hi, by Kurumi

Hi, Mr Mikko

Hi, Mr Mikko

finally i solve that problem with arduino mega, unfortunately i failed using esp32. i follow this link https://www.gurux.fi/node/19307 to my code. i replace <avr/pgmspace.h> to <pgmspace.h>, it compiled well with no error but it can't connect to my gxdlmsdirector. i need your suggestion how to connect it

thank you

Image
Profile picture for user Kurumi

Kurumi

2 years 5 months ago

Hi,

Hi,

Can you connect without authentication to ESP32?
Set Authentication to None and client address to 10.

What kind of ESP32 are you using?

BR,
Mikko

blackhawk41

2 years 5 months ago

In reply to Hi, by Kurumi

still doesn't work sir. i use

still doesn't work sir. i use esp32s microcontroller.

and i want to ask how to read value on register object using python. my teacher ask about that

thank you

Image
Profile picture for user Kurumi

Kurumi

2 years 5 months ago

Hi,

Hi,

There are a lot of different kits for ESP32s. I was asking that so I can check if we have same kit that can be used for testing with the same environment.

After you can connect for the meter with GXDLMSDirector you can see the command line argument for the python application. Something like:

python main.py -S COM1

You can download the client example for the python from here:

https://github.com/Gurux/Gurux.DLMS.Python/tree/master/Gurux.DLMS.Clien…

BR,
Mikko

blackhawk41

2 years 5 months ago

In reply to Hi, by Kurumi

Hi Mr Mikko,

Hi Mr Mikko,

i use Arduino IDE 1.8.13 with ESP32 Board Library version 2.0.2. i use ESP32 DEV Module on board setting.

python code read dlms working properly, thank you very much

... and i want to ask do you have dlms server using mqtt ?

thank you

blackhawk41

2 years 5 months ago

In reply to Hi Mr Mikko, by blackhawk41

and i want to ask, can i

and i want to ask, can i change the scale ?. because 1000 is too big

Profile picture for user Kurumi

Kurumi

2 years 5 months ago

Hi,

Hi,

Can you share a link to your microcontroller?
There is no server example for MQTT at the moment.

You can change the scaler as you want to. It will only affect the meter reading.

BR,
Mikko

blackhawk41

2 years 5 months ago

this link ?https://raw

this link ?https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/pack…. or another link ?

how can i change scale ? on software i can't change the number of scale

Profile picture for user Kurumi

Kurumi

2 years 5 months ago

Hi,

Hi,

No, I mean actual microcontroller hardware.

You need to connect with High authentication to change it. Without authentication, you can't modify anything for the meter. You can only read it.

BR,
Mikko

blackhawk41

2 years 5 months ago

In reply to Hi, by Kurumi

Hi Mr Mikko,

Hi Mr Mikko,

this is my actual hardware

and i've change autentication to high with password "Gurux" still cant change scale

thank you

Image
Profile picture for user Kurumi

Kurumi

2 years 5 months ago

Hi,

Hi,

find getRegisterAttributeAccess and update it to this:

//Get attribute access level for register.
DLMS_ACCESS_MODE getRegisterAttributeAccess(
dlmsSettings* settings,
unsigned char index)
{
//Write is allowed only for High authentication.
if (settings->authentication > DLMS_AUTHENTICATION_LOW && index == 3)
{
return DLMS_ACCESS_MODE_READ_WRITE;
}
return DLMS_ACCESS_MODE_READ;
}

BR,
Mikko

blackhawk41

2 years 5 months ago

In reply to Hi, by Kurumi

Hi Mr Mikko,

Hi Mr Mikko,

thank you that code was working for me. can i add another register on my meter ?.

Thank you

Image

blackhawk41

2 years 4 months ago

In reply to Hi Mr Mikko, by blackhawk41

... and how can i use media

... and how can i use media Net through the ethernet cable. i was try change serial.write to server.write use tcp protocol and nothing work

Image
Profile picture for user Kurumi

Kurumi

2 years 4 months ago

In reply to Hi Mr Mikko, by blackhawk41

Hi,

Hi,

1. Create instance from the register like this:

static gxRegister activePowerL2;

2. Add activePowerL2 to ALL_OBJECTS.
static gxObject* ALL_OBJECTS[] = {..., BASE(activePowerL2)}

3. Copy addRegisterObject and handle activePowerL2 in it.

4. Call addRegisterObject2 in createObjects.

BR,
Mikko

blackhawk41

2 years 4 months ago

In reply to Hi, by Kurumi

Hi mr Mikko,

Hi mr Mikko,

thank you i can add new registers. how can i connect to tcp dlms server using arduino

thanks

Image
Profile picture for user Kurumi

Kurumi

2 years 4 months ago

Hi,

Hi,

You need to change serial port handling for TCP/IP handling in your Arduino. This is done in loop-method as below.

BR,
Mikko

void loop() {
static unsigned char tmp[50];
uint32_t start = time_current();
int available;
//Execute invokes when needed.
if (executeTime <= start)
{
Server.run(start, &executeTime);
}
#ifdef ARDUINO_ARCH_ESP8266
WiFiClient client = tcpServer.available();
if (client)
{
if (client.connected())
{
GXTRACE(PSTR("Client Connected"), NULL);
}
while (client.connected()) {
//Execute invokes when needed.
if (executeTime <= start)
{
Server.run(start, &executeTime);
}
available = client.available();
if (available > 0)
{
if (available > sizeof(tmp))
{
available = sizeof(tmp);
}
available = client.readBytes(tmp, available);
if ((available = Server.handleRequest(tmp, available, &reply)) != 0)
{
GXTRACE_INT(PSTR("handleRequest failed:"), available);
bb_clear(&reply);
}
if (reply.size != 0)
{
//Send reply.
client.write(reply.data, reply.size);
bb_clear(&reply);
}
}
}
client.stop();
GXTRACE(PSTR("Client disconnected"), NULL);
}
#endif //ARDUINO_ARCH_ESP8266
available = Serial.available();
if (available > 0)
{
if (available > sizeof(tmp))
{
available = sizeof(tmp);
}
available = Serial.readBytes((char*) tmp, available);
if ((available = Server.handleRequest(tmp, available, &reply)) != 0)
{
GXTRACE_INT(GET_STR_FROM_EEPROM("handleRequest failed:"), available);
bb_clear(&reply);
}
if (reply.size != 0)
{
//Send reply.
Serial.write(reply.data, reply.size);
Serial.flush();
bb_clear(&reply);
}
}
}

blackhawk41

2 years 4 months ago

In reply to Hi, by Kurumi

hi,

hi,

i have changed void loop, add ethernet library and set ip. it can ping each it other. i use arduino mega and ethernet shield. it still work. my aim was transmit data trough the ethernet shield and read the data using gxdlmsdirector

thanks

Image
Profile picture for user Kurumi

Kurumi

2 years 4 months ago

Hi,

Hi,

Check that you can receive TCP/IP data in your Arduino. Make sure that you have defined
ARDUINO_ARCH_ESP8266 or you are reading serial port.

BR,
Mikko

blackhawk41

2 years 4 months ago

do you have an example for

do you have an example for that case ? im sorry i dont get it

thank you

Profile picture for user Kurumi

Kurumi

2 years 4 months ago

Hi,

Hi,

Add this to the beginning of your file.

#define ARDUINO_ARCH_ESP8266

BR,
Mikko

blackhawk41

2 years 4 months ago

Hi,

Hi,

i add #define ARDUINO_ARCH_ESP8266 on top of my code. and found this error

server_eksperimen:1025:16: error: expected initializer before 'onTime'
void IRAM_ATTR onTime() {
^~~~~~
server_eksperimen:1024:1: error: 'hw_timer_t' does not name a type; did you mean '__size_t'?
hw_timer_t * timer = NULL;
^~~~~~~~~~
__size_t
server_eksperimen:1025:16: error: expected initializer before 'onTime'
void IRAM_ATTR onTime() {
^~~~~~
D:\-----\Power Meter\GuruxDLMS.c-master\GuruxDLMS.c-master\Arduino_IDE\server_eksperimen\server_eksperimen.ino: In function 'void setTimer()':
server_eksperimen:1054:3: error: 'timer' was not declared in this scope
timer = timerBegin(0, 80, true);
^~~~~
D:\-----\Power Meter\GuruxDLMS.c-master\GuruxDLMS.c-master\Arduino_IDE\server_eksperimen\server_eksperimen.ino:1054:3: note: suggested alternative: 'setTimer'
timer = timerBegin(0, 80, true);
^~~~~
setTimer
server_eksperimen:1054:11: error: 'timerBegin' was not declared in this scope
timer = timerBegin(0, 80, true);
^~~~~~~~~~
D:\-----\Power Meter\GuruxDLMS.c-master\GuruxDLMS.c-master\Arduino_IDE\server_eksperimen\server_eksperimen.ino:1054:11: note: suggested alternative: 'time_init'
timer = timerBegin(0, 80, true);
^~~~~~~~~~
time_init
server_eksperimen:1055:32: error: 'onTime' was not declared in this scope
timerAttachInterrupt(timer, &onTime, true);
^~~~~~
D:\-----\Power Meter\GuruxDLMS.c-master\GuruxDLMS.c-master\Arduino_IDE\server_eksperimen\server_eksperimen.ino:1055:32: note: suggested alternative: 'unixTime'
timerAttachInterrupt(timer, &onTime, true);
^~~~~~
unixTime
server_eksperimen:1055:3: error: 'timerAttachInterrupt' was not declared in this scope
timerAttachInterrupt(timer, &onTime, true);
^~~~~~~~~~~~~~~~~~~~
D:\-----\Power Meter\GuruxDLMS.c-master\GuruxDLMS.c-master\Arduino_IDE\server_eksperimen\server_eksperimen.ino:1055:3: note: suggested alternative: 'detachInterrupt'
timerAttachInterrupt(timer, &onTime, true);
^~~~~~~~~~~~~~~~~~~~
detachInterrupt
server_eksperimen:1056:3: error: 'timerAlarmWrite' was not declared in this scope
timerAlarmWrite(timer, 1000000, true);
^~~~~~~~~~~~~~~
D:\-----\Power Meter\GuruxDLMS.c-master\GuruxDLMS.c-master\Arduino_IDE\server_eksperimen\server_eksperimen.ino:1056:3: note: suggested alternative: 'time_clearTime'
timerAlarmWrite(timer, 1000000, true);
^~~~~~~~~~~~~~~
time_clearTime
server_eksperimen:1057:3: error: 'timerAlarmEnable' was not declared in this scope
timerAlarmEnable(timer);
^~~~~~~~~~~~~~~~
D:\-----\Power Meter\GuruxDLMS.c-master\GuruxDLMS.c-master\Arduino_IDE\server_eksperimen\server_eksperimen.ino:1057:3: note: suggested alternative: 'time_clearDate'
timerAlarmEnable(timer);
^~~~~~~~~~~~~~~~
time_clearDate
Using library EEPROM at version 2.0 in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM
exit status 1
expected initializer before 'onTime'

is there another step ?

thank you

Image
Profile picture for user Kurumi

Kurumi

2 years 4 months ago

Hi,

Hi,

You aren't using the ESP board, so I'm not quite sure why you get this error. Try to remove the define and use this code. It's handling only TCP/IP.

void loop() {
static unsigned char tmp[50];
uint32_t start = time_current();
int available;
//Execute invokes when needed.
if (executeTime <= start)
{
Server.run(start, &executeTime);
}
WiFiClient client = tcpServer.available();
if (client)
{
if (client.connected())
{
GXTRACE(PSTR("Client Connected"), NULL);
}
while (client.connected()) {
//Execute invokes when needed.
if (executeTime <= start)
{
Server.run(start, &executeTime);
}
available = client.available();
if (available > 0)
{
if (available > sizeof(tmp))
{
available = sizeof(tmp);
}
available = client.readBytes(tmp, available);
if ((available = Server.handleRequest(tmp, available, &reply)) != 0)
{
GXTRACE_INT(PSTR("handleRequest failed:"), available);
bb_clear(&reply);
}
if (reply.size != 0)
{
//Send reply.
client.write(reply.data, reply.size);
bb_clear(&reply);
}
}
}
client.stop();
GXTRACE(PSTR("Client disconnected"), NULL);
}
}

blackhawk41

2 years 4 months ago

Hi,

Hi,

i use ethernet shield enc28j60, what should i do to config my ethernet

thank you

Image
Profile picture for user Kurumi

Kurumi

2 years 4 months ago

Hi,

Hi,

We haven't use enc28j60 so you need to check that from the shield documentation.
I believe it's something like this:

//Start Wifi.
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.waitForConnectResult() != WL_CONNECTED) {
GXTRACE(GET_STR_FROM_EEPROM("Connection Failed! Rebooting..."), NULL);
delay(2000);
}

BR,
Mikko

  • Log in or register to post comments
  • Create new account
  • Reset your password

Hire Us!

Latest Releases

  • Tue, 05/20/2025 - 08:40
    gurux.dlms.c 9.0.2505.2001
  • Mon, 05/19/2025 - 10:19
    gurux.net.java 1.0.30
  • Mon, 05/19/2025 - 10:00
    gurux.dlms.c 9.0.2505.1901
  • Thu, 05/15/2025 - 16:26
    gurux.dlms.c 9.0.2505.1501
  • Wed, 05/14/2025 - 08:30
    gurux.dlms.c 9.0.2505.1401

New forum topics

  • HDLC Adress resolver configuration
  • Reading all "Data" object type parameter together
  • com_read getting failed for billing profile and instantaneous profile
  • Simulator connection closed
  • Regarding the dlms android project
More

Who's new

  • David2221
  • david1212
  • peters1
  • Basv@1
  • ymgr86
RSS feed
Privacy FAQ GXDN Issues Contact
Follow Gurux on Twitter Follow Gurux on Linkedin