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 Disconnect Control Failed

Arduino disconnect control failed

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 elvandry13 , 15 June, 2021
Forums
Gurux.DLMS

hello,

I want to disconnect and reconnect electricity meter using Arduino client code. Here is my code snippet for disconnect control:

gxDisconnectControl dc;
dlmsVARIANT params;
cosem_init(BASE(dc), DLMS_OBJECT_TYPE_DISCONNECT_CONTROL, "0.0.96.3.10.255");
com_method(BASE(dc), 1, &params);
com_read(BASE(dc), 2);
obj_toString(BASE(dc), &data);
GXTRACE(PSTR("Disconnect : "), data);
obj_clear(BASE(dc));
free(data);

after flash the program, I got the error :
:com_method failed. 258

Is there anything I missed? How should I use the method?
Thank you...

Profile picture for user Kurumi

Kurumi

4 years 12 months ago

Hi,

Hi,
Parameter value must be zero with data type Int8. Try with this:

dlmsVARIANT params;
var_init(&params);
var_setInt8(&params, 0);
com_method(BASE(dc), 1, &params);
BR,
Mikko
BR,
Mikko

elvandry13

4 years 12 months ago

In reply to Hi, by Kurumi

thank you for the fast

thank you for the fast response.
I have updated the disconnect code with this :

gxDisconnectControl dc;
dlmsVARIANT params;
var_init(&params);
var_setInt8(&params, 0);
cosem_init(BASE(dc), DLMS_OBJECT_TYPE_DISCONNECT_CONTROL, "0.0.96.3.10.255");
com_method(BASE(dc), 1, &params);
com_read(BASE(dc), 2);
obj_toString(BASE(dc), &data);
GXTRACE(PSTR("Disconnect : "), data);
obj_clear(BASE(dc));
free(data);

now I got this error :
:com_method failed. -2147483645
Stack smashing protect failure!

abort() was called at PC 0x4010562b on core 1

ELF file SHA256: 0000000000000000

Backtrace: 0x40086eac:0x3ffb1c30 0x40087129:0x3ffb1c50 0x4010562b:0x3ffb1c70 0x400d1699:0x3ffb1c90 0x400d1a9a:0x3ffb1cc0 0x400d1b49:0x3ffb1d60 0x400d1d26:0x3ffb1f90 0x400ec589:0x3ffb1fb0 0x4008813a:0x3ffb1fd0

Rebooting...
ets Jun 8 2016 00:22:57

I'm using ESP32 microcontroller and EDMI MK7MI meter.

Profile picture for user Kurumi

Kurumi

4 years 12 months ago

Hi,

Hi,

I did try this with and it worked without problems. Do you have disconnect control with logical name 0.0.96.3.10.255? Can you disconnect it with GXDLMSDirector?

Stack protect failure is strange and that should not happen.

Can you get a list of bytes that you are transporting between the client and the meter?

Check the authentication level and that you have enough access rights for the meter.

BR,
Mikko

elvandry13

4 years 12 months ago

thank you for the fast

okay, I will be back after I try disconnecting using GXDLMS Director

elvandry13

4 years 11 months ago

Hi,

Hi,

Finally I have tried disconnecting using GXDLMS Director and success! Previously, I used LOW authentication so I failed to disconnecting the meter. After I changed the authentication level to HIGH GMAC, I have succeeded to disconnecting the meter.

Next, I want to implement that to my arduino's firmware. Before that, how to implement the HIGH GMAC auth in client init? Where should I put the Block Cipher Key and Authentication Key in Arduino Client code?

Profile picture for user Kurumi

Kurumi

4 years 11 months ago

Hi,

Hi,

Client example is updated to handle System title, block cipher key and authentication key. Get the latest version and set correct parameters in setup.

BR,
Mikko

elvandry13

4 years 10 months ago

Hi,

Hi,

I have updated to the latest version and set the parameters in setup :

Client.init(true, 4, Client.GetServerAddress(1, 0x23, 1), DLMS_AUTHENTICATION_HIGH_GMAC, NULL, DLMS_INTERFACE_TYPE_HDLC);

//Un-comment this if you want to set system title, block cipher key or authentication key.
gxByteBuffer bb;
bb_Init(&bb);
bb_addHexString(&bb, "");
Client.SetSystemTitle(&bb);
bb_clear(&bb);
bb_addHexString(&bb, "");
Client.SetAuthenticationKey(&bb);
bb_clear(&bb);
bb_addHexString(&bb, "");
Client.SetBlockCipherKey(&bb);
bb_clear(&bb);

but I still get the same error :

:Start reading :com_initializeConnection failed -2147483645
Stack smashing protect failure!

abort() was called at PC 0x4010559b on core 1

ELF file SHA256: 0000000000000000

Backtrace: 0x40086eac:0x3ffb1d00 0x40087129:0x3ffb1d20 0x4010559b:0x3ffb1d40 0x400d16f1:0x3ffb1d60 0x400d1b05:0x3ffb1d90 0x400d1d1e:0x3ffb1f90 0x400ec4f9:0x3ffb1fb0 0x4008813a:0x3ffb1fd0

Rebooting...
ets Jun 8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x33 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:10124
load:0x40080400,len:5828
entry 0x400806a8

here I attached the screenshot of parameters I tested in GXDLMS Director

elvandry13

4 years 11 months ago

Sceenshot of device settings

Sceenshot of device settings

elvandry13

4 years 11 months ago

Screenshot of secured

Screenshot of secured connection tab

Profile picture for user Kurumi

Kurumi

4 years 11 months ago

Hi,

Hi,

Your authentication and block cipher keys are wrong. You try to give ASCII values and you should set hex values. Try with this:

bb_addHexString(&bb, "41 42 43 44 45 46 47 48");
Client.SetSystemTitle(&bb);
bb_clear(&bb);
bb_addHexString(&bb, "46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46");
Client.SetAuthenticationKey(&bb);
bb_clear(&bb);
bb_addHexString(&bb, "46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46");
Client.SetBlockCipherKey(&bb);

BR,
Mikko

elvandry13

4 years 10 months ago

Hi,

Hi,

I have edited my authentication and block cipher keys following your suggestion :
Client.init(true, 4, Client.GetServerAddress(1, 0x23, 1), DLMS_AUTHENTICATION_HIGH_GMAC, NULL, DLMS_INTERFACE_TYPE_HDLC);

//Un-comment this if you want to set system title, block cipher key or authentication key.
gxByteBuffer bb;
// bb_init(&bb);
bb_Init(&bb);
bb_addHexString(&bb, "");
Client.SetSystemTitle(&bb);
bb_clear(&bb);
bb_addHexString(&bb, "");
Client.SetAuthenticationKey(&bb);
bb_clear(&bb);
bb_addHexString(&bb, "");
Client.SetBlockCipherKey(&bb);
bb_clear(&bb);

but I still get the same error :

:Start reading :com_initializeConnection failed -2147483645
Stack smashing protect failure!

abort() was called at PC 0x4010559b on core 1

ELF file SHA256: 0000000000000000

Backtrace: 0x40086eac:0x3ffb1d00 0x40087129:0x3ffb1d20 0x4010559b:0x3ffb1d40 0x400d16f1:0x3ffb1d60 0x400d1b05:0x3ffb1d90 0x400d1d1e:0x3ffb1f90 0x400ec4f9:0x3ffb1fb0 0x4008813a:0x3ffb1fd0

Rebooting...
ets Jun 8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:10124
load:0x40080400,len:5828
entry 0x400806a8

I was thinking maybe it was caused by the ESP32 board, so I tried using different board, I used Arduino Mega 2560. When I'm using the Arduino Mega 2560 board, I got different error :

:Start reading :com_initializeConnection failed 3

Additional notes :
- for ESP32, I changed bb_init(&bb); to bb_Init(&bb);

Profile picture for user Kurumi

Kurumi

4 years 11 months ago

Hi,

Hi,

We can't repeat this. I have ordered an ESP32 board so we can check if this can be repeated with different HW. Let's wait a few days and get back to this after we have the ESP32 board.

BR,
Mikko

elvandry13

4 years 11 months ago

Hi,

Hi,

May I know what HW do you use usually for testing Arduino client firmware? Maybe I will try in same environment.

Profile picture for user Kurumi

Kurumi

4 years 11 months ago

Hi,

Hi,

There are a few different Arduino boards that are used to read the meters, but all tests are run with ATmega328.

BR,
Mikko

elvandry13

4 years 11 months ago

Hi,

Hi,

I have tried using Arduino Uno and Arduino Nano (which use ATmega328) but it doesnt compile. I used Serial0 for flash and send trace / debugging, and Arduino Uno doesnt have Serial1 or Serial2 so I used software serial for communicate with meter. Here is the reference : https://www.arduino.cc/reference/en/language/functions/communication/se…

When I compile the program, I got this error :
/home/elvandry13/arduino-1.8.13/hardware/tools/avr/bin/../lib/gcc/avr/7.3.0/../../../../avr/bin/ld: /tmp/arduino_build_389754/modem-pln.ino.elf section `.text' will not fit in region `text'
/home/elvandry13/arduino-1.8.13/hardware/tools/avr/bin/../lib/gcc/avr/7.3.0/../../../../avr/bin/ld: region `text' overflowed by 32474 bytes
/tmp/ccbN18q9.ltrans0.ltrans.o: In function `GetTe':
/tmp/arduino_build_389754/sketch/src/ciphering.c:223: undefined reference to `pgm_read_dword_far'
/tmp/ccbN18q9.ltrans0.ltrans.o: In function `GetRcon':
/tmp/arduino_build_389754/sketch/src/ciphering.c:214: undefined reference to `pgm_read_dword_far'
collect2: error: ld returned 1 exit status
Using library SoftwareSerial at version 1.0 in folder: /home/elvandry13/arduino-1.8.13/hardware/arduino/avr/libraries/SoftwareSerial
exit status 1
Error compiling for board Arduino Uno.

Do you use custom HW which have ATmega328 and multiple hardware serial? And do you have try with ESP32?

hattareza

4 years 11 months ago

Hi Mr Mikko Kurunsaari

Hi Mr Mikko Kurunsaari

i have same problem about this, is there any suggestion related to programming languages or library and board. for example board like raspberry pi, 1SJ,arduino and programming language like java , c# ,c. if i try the code possible running well and establish ?

Thanks and Best Regards

Profile picture for user Kurumi

Kurumi

4 years 11 months ago

Hi,

Hi,

Your error message says that you don't have enough memory on your board. You need a bigger flash to save this. DLMS is not an easy protocol.

BR,
Mikko

elvandry13

4 years 11 months ago

Hi,

Hi,

I have tried with Arduino Uno, Nano and Pro Mini (with ATMega328) but didn't work, what board should I use? Do you have any recommendation? Do you have try with ESP32?

Profile picture for user Kurumi

Kurumi

4 years 11 months ago

Hi,

Hi,

I have order ESP32 and we'll make an example for that after it arrives. You can use any bard that has enough memory.

BR,
Mikko

elvandry13

4 years 11 months ago

In reply to Hi, by Kurumi

Thank you very much

Thank you very much

Profile picture for user Kurumi

Kurumi

4 years 10 months ago

In reply to Hi, by elvandry13

Hi,

Hi,

Can you add the send and received bytes as hex to here so I can try to check what is causing this?

BR,
Mikko

elvandry13

4 years 10 months ago

In reply to Hi, by Kurumi

Hi Mikko,

Hi Mikko,

This case solved after you fixed it in latest commit in github. Thanks a lot!

  • 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

Who's new

  • Tuanhgg
  • Adel
  • charnon
  • Paddles
  • Miguel Ángel
RSS feed
Privacy FAQ GXDN Issues Contact
Follow Gurux on Twitter Follow Gurux on Linkedin