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. ESP32 Assert In Cl_clear

ESP32 assert in cl_clear

By dvosp , 15 February, 2024
Forums
Gurux.DLMS

Hi

I'm using DLMS.c on an ESP32. I can do register reads without issue, but I get an assert in cl_clear. Below the code

uint16_t srv = cl_getServerAddress(1, 7662, 0);

cl_init(&settings, 1, 1, srv, DLMS_AUTHENTICATION_LOW, "12345678", DLMS_INTERFACE_TYPE_HDLC);

int ret = com_initializeConnection();
if (ret == DLMS_ERROR_CODE_OK)
{
// read the kWh register
gxRegister reg;
int err;
err = cosem_init(BASE(reg), DLMS_OBJECT_TYPE_REGISTER, "1.0.1.8.0.255");
err = com_read(BASE(reg), 3); // scaler
err = com_read(BASE(reg), 2); // value
ESP_LOGI(TAG, "value %d", reg.value.lVal);
obj_clear(BASE(reg));

#if 1
// profile generic
gxProfileGeneric pg;
err = cosem_init(BASE(pg), DLMS_OBJECT_TYPE_PROFILE_GENERIC, "1.0.99.1.0.255");
com_read(BASE(pg), 3); // capture objects
com_read(BASE(pg), 4); // period
com_read(BASE(pg), 7); // entries in use

gxtime startTime, endTime;

time_initUnix(&startTime, 1707264000);
time_initUnix(&endTime, 1707321600);

err = com_readRowsByRange(&pg, &startTime, &endTime);
if (err == DLMS_ERROR_CODE_OK)
{
showRows(&pg.buffer);
}
obj_clear(BASE(pg));
#endif
com_close();
}
cl_clear(&settings);

If i change the #if 1 to #if 0, commenting out the profile generic read I have no issue. With the code in I get an assert in cl_clear at the following line

bb_clear(&settings->password);

Am I doing the object clearing correctly?

Profile picture for user Kurumi

Kurumi

2 years 3 months ago

Hi, At first, try to comment…

Hi,

At first, try to comment showRows. It might use so much memory that it causes problems.
//showRows(&pg.buffer);

You try to read for four hours at once. Try to read for only one hour. The amount of memory is always a problem when reading DLMS historical data. How many columns there are in this profile generic?

You should also check the error code for each com_read and handle it somehow.

BR,
Mikko

dvosp

2 years 3 months ago

Hi, I have already commented…

Hi,

I have already commented showRows, no effect.

The date range returns 13 rows and there's 8 columns per row.

Free heap before the call is about 230k.

I do error checking, just removed it for clarity.

Changed the date range to return two rows, problem still there.

dvosp

2 years 3 months ago

Another thing I would like…

Another thing I would like to mention is that there are a few references to bb_init instead of BYTE_BUFFER_INIT. As I'm using an ESP32 this is a problem and I changed all references to BYTE_BUFFER_INIT.

Profile picture for user Kurumi

Kurumi

2 years 3 months ago

Hi, bb_init might cause this…

Hi,

bb_init might cause this.

What compiler are you using?

If it's Arduino, can you select "File" and "Preferences"?
What Additional Boards Manager URLs you are using?

BR,
Mikko

dvosp

2 years 3 months ago

Hi Mikko, I'm using esp-idf…

Hi Mikko,

I'm using esp-idf.

I can confirm that settings.password.data is clobbered by the following line
com_read(BASE(pg), 3); // capture objects

I use the following to print the password before and after the call

ESP_LOGI(TAG, "%s: %s %d %d %d",
prefix,
settings.password.data,
settings.password.capacity,
settings.password.size,
settings.password.position
);

Before:
PW2: 12345678 9 8 0

after:
PW3: 9 8 0

dvosp

2 years 3 months ago

Hi Mikko, I enabled the esp…

Hi Mikko,

I enabled the esp-idf heap trace.

uint16_t srv = cl_getServerAddress(1, 7662, 0);
ESP_ERROR_CHECK( heap_trace_start(HEAP_TRACE_LEAKS) );
cl_init(&settings, 1, 1, srv, DLMS_AUTHENTICATION_LOW, "12345678", DLMS_INTERFACE_TYPE_HDLC);
int ret = com_initializeConnection();
if (ret == DLMS_ERROR_CODE_OK)
{
// read the kWh register
int err;
err = cosem_init(BASE(reg), DLMS_OBJECT_TYPE_REGISTER, "1.0.1.8.0.255");
err = com_read(BASE(reg), 3); // scaler
err = com_read(BASE(reg), 2); // value
ESP_LOGI(TAG, "value %d", reg.value.lVal);
obj_clear(BASE(reg));
err = cosem_init(BASE(pg), DLMS_OBJECT_TYPE_PROFILE_GENERIC, "1.0.99.1.0.255");
com_read(BASE(pg), 3); // capture objects
com_read(BASE(pg), 4); // period
com_read(BASE(pg), 7); // entries in use
time_initUnix(&startTime, 1707296400);
time_initUnix(&endTime, 1707296400 + (3600));
err = com_readRowsByRange(&pg, &startTime, &endTime);
if (err == DLMS_ERROR_CODE_OK)
{
//showRows(&pg.buffer);
//char *data;
//obj_toString(BASE(pg), &data);
//GXTRACE(GET_STR_FROM_EEPROM("Load profile"), data);
//free(data);
}
obj_clear(BASE(pg));
com_close();
}
cl_clear(&settings);
ESP_ERROR_CHECK( heap_trace_stop() );
heap_trace_dump();

I commented out the bb_clear(&settings->password); line in cl_clear. The code runs now and does not assert, but as you can see the trace indicates correctly the 9 bytes leaked, No other leaks indicated. When I un-comment the line, the code asserts.

1 allocations trace (1000 entry buffer)
9 bytes (@ 0x3ffbc64c) allocated CPU 0 ccount 0x43073b74 caller 0x400da1e7:0x400da4da
0x400da1e7: bb_allocate at /media/pierre/Portable2/Projects/Modems/ME16-Firmware/ME16-ESP32/GuruxDLMS.c/development/src/bytebuffer.c:275
0x400da4da: bb_set at /media/pierre/Portable2/Projects/Modems/ME16-Firmware/ME16-ESP32/GuruxDLMS.c/development/src/bytebuffer.c:532
9 bytes 'leaked' in trace (1 allocations)
total allocations 267 total frees 266

  • 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