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
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();.
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
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:
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
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
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
Hi,
Hi,
Read this first.
http://gurux.fi/Arduino
I believe it will help you to get started.
BR,
Mikko
i read that link and i follow
why my serial monitor result was different with yours. whats my fault ? thank you
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
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
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
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
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
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
and i want to ask, can i
and i want to ask, can i change the scale ?. because 1000 is too big
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
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
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
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
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
Hi Mr Mikko,
Hi Mr Mikko,
thank you that code was working for me. can i add another register on my meter ?.
Thank you
... 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
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
Hi mr Mikko,
Hi mr Mikko,
thank you i can add new registers. how can i connect to tcp dlms server using arduino
thanks
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);
}
}
}
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
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
do you have an example for
do you have an example for that case ? im sorry i dont get it
thank you
Hi,
Hi,
Add this to the beginning of your file.
#define ARDUINO_ARCH_ESP8266
BR,
Mikko
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
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);
}
}
Hi,
Hi,
i use ethernet shield enc28j60, what should i do to config my ethernet
thank you
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