-
-
@Rene-Arts said:
Did you uncomment all lines to use softserial, i.e. also
mySerial.begin(115200);
at line 483 and verify the baud rate is correct for your meter?
Can you please also check the type of your meter, probably a MA105C? In that case the 115200 should be OK.Stupid fault: forgot (mixed up) mySerial.begin with Serial.begin.
Now I got output as it should. except maybe for the last line e.g.:
…
0-1:96.1.0(4730303139333430323738303230323136)
0-1:24.2.1(160316180000W)(00002.655*m3)
!F736Is this !F736 normal?
-
One thing left: it seems that the values are rounded up to whole integers:
1-0:1.8.2(000002.305*kWh)
…
// 1-0:1.8.2 = Elektra verbruik hoog tarief (DSMR v4.0)
if (strncmp(telegram, “1-0:1.8.2”, strlen(“1-0:1.8.2”)) == 0)
mEVHT = getValue(telegram, len);
…
// dtostrf(mEVHT,9,3,sFloatString);
sendData(mEVHT,“esp/elektra/mEVHT”);
…
Output of: bool sendData(float data, String topic)
esp/elektra/mEVHT
2.00I will have a look at this…
-
The
!F736
is the end-of-message signal and the checksum, so yes, that is completely normalThe checksum will change as the data changes.
Considering the rounding: try sending it as a string instead of a float.
I am using the pimatic API to read in the values, the data is converted to a string format using 3 decimal places.
Just checked in my previous versions which were using MQTT (as you seem to be doing) and there I used a string format as well to send the values; pimatic converted this to a number format which worked fine.
Within pimatic (current setup) the data is converted back, displayed and stored as a number:{ "id": "verbruik", "name": "Huidig elektriciteitsverbruik", "class": "VariablesDevice", "variables": [ { "name": "verbruik", "expression": "$mEAV", "type": "number", "unit": "kW", "discrete": true, "acronym": "Actual Electricity Consumption" } ] },
-
Indeed I’m using MQTT.
But the serial monitor output of ESP / Arduino also shows no decimals as you can see:
esp/elektra/mEVHT
2.00
So to me it looks like getValue(telegram, len) is returning no decimals? -
float getValue(char* buffer, int maxlen)
returns a float… so not really anything special about decimals.
If you somewhere convert it to an integer you will lose the decimals, as an integer by definition cannot have decimals.
Converting a float to a string is easy:String(float floatval, int decimals)
. I am not sure what happens when you do not enter the second argument, but it might assume zero decimals so it will round to integer values (so without decimals).If you need any further help please post your code somewhere (git/pastebin), without it I can only make some wild guesses about what is happening
-
Thanks for all the help Rene. I got two decimals now, but still wondering where the third one has gone. E.g.:
1-0:1.8.1(000002.386*kWh)
Result in the sendData function (topic / data):
esp/elektra/mEVLT
2.39
The code can be found : https://gist.github.com/etmcemi/95e47ffa8dc41bfe776e -
At line 245 in your code you convert the data into a string without specifying the number of decimals:
String(data)
. Change it toString(data,3)
and you should be fine. As I stated in my post before, if you do not specify the number of decimals it will revert to a default (which seems to be 2). -
Many thanks Rene, it works.
I was mislead by the fact that Serial.print(data) also showed two decimals. Apparently Serial.print uses a same kind of String() with default two decimals. -
Ah, good to hear it works! Glad to be able to help you, have fun!