I want to push value with mqtt.
With this I can read meter and push to mqtt:
//Read active power 1.8.1
gxRegister rdn1;
cosem_init(BASE(rdn1), DLMS_OBJECT_TYPE_REGISTER, "1.0.1.8.1.255");
com_read(BASE(rdn1), 2);
obj_toString(BASE(rdn1), &data);
GXTRACE(GET_STR_FROM_EEPROM("Active1"), data);
client.publish(topic, data);
obj_clear(BASE(rdn1));
free(data);
How can I get value only like: 8560182 without: Index: 3 Value: Scaler: 1 Unit: None
Index: 2 Value: 8560182?
Hi, You can get the register…
Hi,
You can get the register value as a string like this:
gxByteBuffer ba;
BYTE_BUFFER_INIT(&ba);
ret = var_toString(&rdn1.value, &ba);
BR,
Mikko
Hi, I'm getting value 0…
Hi,
I'm getting value 0 instead of 8560182.
gxRegister rdn1;
cosem_init(BASE(rdn1), DLMS_OBJECT_TYPE_REGISTER, "1.0.1.8.1.255");
com_read(BASE(rdn1), 2);
obj_toString(BASE(rdn1), &data);
GXTRACE(GET_STR_FROM_EEPROM("Active1:"), data);
client.publish(topic, data);
obj_clear(BASE(rdn1));
free(data);
gxByteBuffer ba;
BYTE_BUFFER_INIT(&ba);
ret = var_toString(&rdn1.value, &ba);
Serial.println(ret);
sprintf(msg_out, "%d",ret);
client.publish(topic, msg_out);
Hi, You are sending a error…
Hi,
You are sending a error code, not a string value. This is wrong:
sprintf(msg_out, "%d",ret);
Change it to:
int value = var_toInteger(&rdn1.value);
sprintf(msg_out, "%s", value);
BR,
Mikko
There was some problems if I…
There was some problems if I used sprintf(msg_out, "%s", value); The board resets when it tries to read value. But this works form me. I'm posting it if anybody needs something like this.
//Read active power 1.8.1
gxRegister rdn1;
cosem_init(BASE(rdn1), DLMS_OBJECT_TYPE_REGISTER, "1.0.1.8.1.255");
com_read(BASE(rdn1), 2);
obj_toString(BASE(rdn1), &data);
GXTRACE(GET_STR_FROM_EEPROM("Active1:"), data);
int value1 = var_toInteger(&rdn1.value);
char msgout1[10];
snprintf(msgout1, sizeof(msgout1), "%u", value1);
client.publish(topic, msgout1);
obj_clear(BASE(rdn1));
free(data);
//Read active power 1.8.2
gxRegister rdn2;
cosem_init(BASE(rdn2), DLMS_OBJECT_TYPE_REGISTER, "1.0.1.8.2.255");
com_read(BASE(rdn2), 2);
obj_toString(BASE(rdn2), &data);
GXTRACE(GET_STR_FROM_EEPROM("Active2"), data);
int value2 = var_toInteger(&rdn2.value);
char msgout2[10];
snprintf(msgout2, sizeof(msgout2), "%u", value2);
client.publish(topic, msgout2);
obj_clear(BASE(rdn2));
free(data);
Now is there an option to send these as one string? like 123456|654321 when I read all values? And can i convert mac adddress from hex to asci and send it together with values like MAC123456|123456|654321? Maybe I should start new topic? Thanks
Hi, My bad. This is a typo…
Hi,
My bad. This is a typo.
int value = var_toInteger(&rdn1.value);
sprintf(msg_out, "%d", value);
I'm glad that you solved this.
BR,
Mikko
Hi. So, I managed to get all…
Hi. So, I managed to get all values that I need. Now I can push them as one message comma separated. And that is great. But how to get just value for Logical device name (mac address)? My idea is to strip MAC and use only integers of ldn.
gxData ldn;
cosem_init(BASE(ldn), DLMS_OBJECT_TYPE_DATA, "0.0.42.0.0.255");
com_read(BASE(ldn), 2);
obj_toString(BASE(ldn), &data);
GXTRACE(GET_STR_FROM_EEPROM("Logical Device Name"), data);
client.publish(topic, data);
obj_clear(BASE(ldn));
free(data);
Thanks.
Hi, The Logical Device Name…
Hi,
The Logical Device Name usually is the serial number of the meter, not the MAC address. The content of the Logical Device Name is not defined by DLMS standards and different meters are using different values here.
BR,
Mikko