arduino-dsmr icon indicating copy to clipboard operation
arduino-dsmr copied to clipboard

Print raw-format of a telegram

Open mrWheel opened this issue 6 years ago • 4 comments

How do I use this :

    /**
     * Returns the data read so far.
     */
    const String &raw() {
      return buffer;
    }

If it should do what I think... It would be very nice to be able to print the raw format of the telegram!

mrWheel avatar Sep 19 '18 06:09 mrWheel

IIRC, you should be able to do:

  if (reader.available()) {
    Serial.println("Message:");
    Serial.println(reader.raw());
    MyData data;
    String err;
    if (reader.parse(&data, &err)) {
      // Parse succesful, print result
      data.applyEach(Printer());
    } else {
      // Parser error, print error
      Serial.println(err);
    }
  }

This is taken from the read.ino example, but with the first two printlns added. IOW, raw() returns the data read so far, but once you call parse(), the buffer is cleared again. So if you retrieve the buffer when available() is true, but before calling parse(), you should get the complete message. Note that the buffer does not include the leading / and the trailing checksum.

matthijskooijman avatar Sep 19 '18 15:09 matthijskooijman

@mrWheel, could you confirm if my suggestion worked?

matthijskooijman avatar May 04 '19 19:05 matthijskooijman

@mrWheel thanks for your response. HOwever, AFAICS your code does not print the raw, unparsed message which was the subject of this issue :-)

I would want to close this issue, but ideally by adding the raw printing to the read.ino example. But I only want that after making sure it actually works (and I do not have a DSMR-attached setup currently to test with, so I was hoping you could confirm).

matthijskooijman avatar May 05 '19 16:05 matthijskooijman

@matthijskooijman Yes, the code is OK!

if (reader.available()) {
    Debugln("Message:");
    Debugln(reader.raw());
    MyData data;
    String err;
    if (reader.parse(&data, &err)) {
      // Parse succesful, print result
      data.applyEach(Printer());
    } else {
      // Parser error, print error
      Debugln(err);
    }
}

Output:

Message:
identification: XMX5LGBBLB2410065887
p1_version: 50
timestamp: 160611025601S
equipment_id: 4530303336303033373839373339363136
energy_delivered_tariff1: 50370.91kWh
energy_delivered_tariff2: 48518.44kWh
energy_returned_tariff1: 28885.50kWh
energy_returned_tariff2: 38127.31kWh
electricity_tariff: 0002
power_delivered: 168.89kW
power_returned: 71.90kW
voltage_l1: 241.00V
voltage_l2: 235.00V
voltage_l3: 237.00V
current_l1: 0A
current_l2: 1A
current_l3: 0A
power_delivered_l1: 36.30kW
power_delivered_l2: 83.83kW
power_delivered_l3: 48.76kW
power_returned_l1: 40.70kW
power_returned_l2: 25.75kW
power_returned_l3: 5.45kW
gas_device_type: 3
gas_equipment_id: 4730303339303031363532303530323136
gas_delivered: 4870.24m3
Message:
XMX5LGBBLB2410065887

1-3:0.2.8(50)
0-0:1.0.0(160611025701S)
0-0:96.1.1(4530303336303033373839373339363136)
1-0:1.8.1(050370.934*kWh)
1-0:1.8.2(048518.441*kWh)
1-0:2.8.1(028885.498*kWh)
1-0:2.8.2(038127.328*kWh)
0-0:96.14.0(0002)
1-0:1.7.0(121.25*kW)
1-0:2.7.0(077.78*kW)
0-0:96.7.21(00010)
0-0:96.7.9(00000)
1-0:99.97.0(0)(0-0:96.7.19)
1-0:32.32.0(00002)
1-0:52.32.0(00003)
1-0:72.32.0(00003)
1-0:32.36.0(00000)
1-0:52.36.0(00000)
1-0:72.36.0(00000)
0-0:96.13.0()
1-0:32.7.0(241.0*V)
1-0:52.7.0(239.0*V)
1-0:72.7.0(237.0*V)
1-0:31.7.0(002*A)
1-0:51.7.0(003*A)
1-0:71.7.0(000*A)
1-0:21.7.0(59.400*kW)
1-0:41.7.0(35.350*kW)
1-0:61.7.0(26.500*kW)
1-0:22.7.0(69.300*kW)
1-0:42.7.0(04.120*kW)
1-0:62.7.0(04.360*kW)
0-1:24.1.0(003)
0-1:96.1.0(4730303339303031363532303530323136)
0-1:24.2.1(160611025701S)(04870.238*m3)

mrWheel avatar May 05 '19 16:05 mrWheel