UtilitechAS / amsreader-firmware

ESP8266 and ESP32 compatible firmware to read, interpret and publish data to MQTT from smart electrical meters, both DLMS and DSMR is supported
Other
380 stars 72 forks source link

Add support for Austrian meter #155

Closed gskjold closed 2 years ago

gskjold commented 2 years ago

Slightly different format

218_9_SmartMeter_Kundenschnittstelle_lektoriert_1410_Web.pdf Beschreibung_Kundenschnittstelle_Smart_Meter_TINETZ.pdf

manfi001 commented 2 years ago

The attachment contains 10 consecutive packets of 282 bytes ea received from my meter. maybe this helps to clarify the format. Sagemcom.txt

gskjold commented 2 years ago

Looking at it, the 282 bytes frame actually consist of two frames, one 263 (259+4) and a 19 byte frame which I am not sure what is for. The specified length 0x0d0d makes no sense. Makes me wonder if 0x0101 is actually a length, although it is consistent with a normal HDLC frame.

// 19b 68 0D 0D 68 53 FF 11 01 67 CD 6B CB 69 13 53 FF 98 34 16

// 263b 68 01 01 68 53 FF 00 01 67 DB 08 53 41 47 59 05 E6 D9 FD 81 F8 20 00 69 D1 50 55 28 2C E9 97 46 82 61 19 3E 23 78 8A E6 E2 42 D1 D6 44 BA 2C 3C 55 0E 59 47 02 DC 8D D4 10 91 67 6B 76 9B F0 2F 42 BF D9 D2 FE A2 B3 AA 11 B1 BF 7B 8B B3 36 FE 7E B0 22 D7 60 10 48 1B 77 AA C2 DC 99 8D C2 C4 5D 78 83 53 92 E8 66 44 CC 32 43 A9 E8 22 B2 0E DF D8 39 B3 21 5B E6 A8 F1 83 5E 85 5A A3 5D 2B 92 ED 59 D7 24 2C CC 26 AB A6 0A FE 78 B0 E9 D3 7C 6D B8 32 0F 36 C0 A0 9B A2 56 73 08 56 EE 9B AD 7C CC F3 6B EC 13 63 55 2A 28 0E 7A 9B D9 2A 62 08 D5 9C AD E8 43 6D 7A CA 8B DD BF DB 3F E1 88 3F 9D B9 7C 19 D3 68 8C 57 AB 82 46 4B 75 B8 F3 9E 2C 22 06 2A 93 78 56 56 76 51 65 11 C7 12 78 AB F2 97 97 51 2A 16 70 56 30 C9 12 00 08 BC 80 55 6E 44 51 A1 93 CD CF BA 9A DA CA 48 19 74 E4 70 1E AD 63 99 16

gskjold commented 2 years ago

A detailed description of all the fields in the frame:

68 // MBUS start flag 0x68 01 01 // Format (0x00) and total length (257) (Green book 8.4.1.3)

68 // Start 53 // Control field FF // Address (Broadcast address)

00 // Control information field 01 // Source SAP 67 // Destination SAP

DB // Encrypted 08 53 41 47 59 05 E6 D9 FD // System title, first byte specifies length 81 // Prefix for 1-byte length F8 // Length (248) 20 // Security tag 0010 0000, 0=Compression off, 0=Unicast, 1=Encryption, 0=No auth, 0000= Security Suite ID 00 72 00 76 // Frame counter // Encrypted frame follows 00 // 1 byte CRC 16 // End flag

This last part, from 0xDB and until the end is consistent with format from encrypted Kamstrup in Denmark, only they have authentication, adding 12 extra bytes to the footer, before CRC and end flag.

manfi001 commented 2 years ago

According to other Mbus protocol documentations, byte 3 is a repetition of byte 2, which would mean hex 01 01 is not dec 257. consequently hex 0D 0D = dec 13 would make sense at least for the second frame.

gskjold commented 2 years ago

Which doc are you referring to? Not able to find this in green book

manfi001 commented 2 years ago

this here: Anleitung_M-Bus_Protokoll_V1.0.pdf sorry to bother you with all this German docs

gskjold commented 2 years ago

No worries, I can deal with German :) Thanks!

manfi001 commented 2 years ago

Another one: M-Bus_DOC48.PDF

manfi001 commented 2 years ago

Found another project on Github dealing with the same meter: https://github.com/culvermelanie/SmartMeter

gskjold commented 2 years ago

Thanks, I've actually managed to make it work with the example payload from the document for your meter. A lot of the values are 0 though, so not very useful. But it works, so you can test it when you get the key

manfi001 commented 2 years ago

Great! The doc is based on a different meter (Kaifa MA309), but I hope, it will work with my Sagemcom too. will keep you informed.

manfi001 commented 2 years ago

Q: Is the debug data in the frame dump the raw data from the meter or is it already decrypted?

gskjold commented 2 years ago

It will be the decrypted frame. I just release v2.0.0 which I think should work with your meter. Let me know how it turns out.

manfi001 commented 2 years ago

thanks for your efforts 👍 Still waiting for the key :-( btw: is the missing verbose debug level in the ui intentional? and what is the difference between debug and verbose level?

gskjold commented 2 years ago

I have not taken advantage of verbose logging in the code, so I have not included it in the config either. It is up to the developer to use the difference levels of logging, and I guess verbose logging would just be an extended debugging log.

manfi001 commented 2 years ago

Just received my key, entered it, rebooted and >> Hurraaa, it's working. Thanks for your work! Wish you merry X'mas and Happy & healthy new Year!

AMS2MQTT_Sagemcom

gskjold commented 2 years ago

That is awesome! Thank you for the good words. Merry Christmas!

gskjold commented 2 years ago

By the way, could you provide me with meter model, baud and parity from the meter configuration page?

ArnieO commented 2 years ago

Just received my key, entered it, rebooted and >> Hurraaa, it's working.

Great!!

Would you be interested in sharing your hardware setup? I am curious to find out whether the Pow-U unit I currently sell from my webshop could be modified to work on your meter.

I see from the documentation in this thread that your meter is:

The Pow-U pulls its energy from the M-bus line; works on a Kamstrup meter where maximum power draw is 144 mW, so this should be OK. However, meters in Norway have their base voltage at 24V ("zero"), dropping to 12V ("one") during data transmission - so a minor modification would be needed to read data (I do not use the TSS721 chip).

From what I see in the above documentation, your meter seems to have a base voltage at 36V ("zero"), dropping to 24V ("one") during data transmission - can you confirm this?

Please contact me on post@amsleser.no if you are interested in discussing the possibility of me sending you a modified Pow-U unit for testing on your meter.

manfi001 commented 2 years ago

Hi,

the meter config page looks like this:

The meter is a Sagemcom T210-D. The grid operator is Netz NÖ

I think, my enthusiasm was a bit premature. There are still some issues:

  1. The reactive power data is always zero:

  2. The device is restarting every couple of hours

  3. In the log I get these messages

(I) (readHanPort) Valid HDLC, start at 44

(W) (readHanPort) Invalid HDLC, returned with -9

(I) (readHanPort) Valid HDLC, start at 44

(W) (readHanPort) Invalid HDLC, returned with -9

(I) (readHanPort) Valid HDLC, start at 44

(W) (readHanPort) Invalid HDLC, returned with -9

Are the 2 frames re-assembled before decoding, as described in the document ….TINETZ.pdf pg 6?

Regards

Manfred

From: Gunnar Skjold @.*** Sent: Dienstag, 21. Dezember 2021 11:43 To: gskjold/AmsToMqttBridge Cc: manfi001; Comment Subject: Re: [gskjold/AmsToMqttBridge] Add support for Austrian meter (Issue #155)

By the way, could you provide me with meter model, baud and parity from the meter configuration page?

— Reply to this email directly, view it on GitHub https://github.com/gskjold/AmsToMqttBridge/issues/155#issuecomment-998671244 , or unsubscribe https://github.com/notifications/unsubscribe-auth/ATQ5AAFLFPUKGXFNTPVSKZDUSBK3ZANCNFSM5JNDB7YA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub . You are receiving this because you commented. https://github.com/notifications/beacon/ATQ5AAHSP2HVUP6LTGC5SBLUSBK3ZA5CNFSM5JNDB7YKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOHODIHDA.gif Message ID: @.***>

gskjold commented 2 years ago

Reopening to have a look at that problem.

ArnieO commented 2 years ago

The setup is missing from his message, but his settings should be configured like this, according to https://github.com/gskjold/AmsToMqttBridge/files/7656628/Beschreibung_Kundenschnittstelle_Smart_Meter_TINETZ.pdf image

gskjold commented 2 years ago

Are the 2 frames re-assembled before decoding, as described in the document ….TINETZ.pdf pg 6?

Nice, this is the problem, will fix when I have time

gskjold commented 2 years ago

Try this firmware: esp8266.zip

I have tested it with data and key from first PDF in this issue. It looks like it is working. Tested with some of your data and it does at least assemble the data correctly, so lets hope it works for you.

It it doesn't work, enable debugger and send me the log.

manfi001 commented 2 years ago

Doesn't look good, HAN indicator goes from red to orange to green back to orange and red. Remember: data and key from pdf is for a Kaifa meter, not Sagemcom ams2mqttAustria.txt

gskjold commented 2 years ago

Doesn't look good, HAN indicator goes from red to orange to green back to orange and red.

I see there is a lot of buffer overflow here.. Could you try disabling temperature sensors? Save blank temp pin in GPIO.

Remember: data and key from pdf is for a Kaifa meter, not Sagemcom

I know it is not the same, but I need to implement this as generic as possible. Also, running the dump file you previously sent to me through my setup works just fine, only I do not have your key. Assembly is correct at hex level though.

manfi001 commented 2 years ago

This is my GPIO setup Screenshot 2021-12-24 154348

gskjold commented 2 years ago

Aha, sorry I thought I saw a temp update message in log > 0ms, but I was mistaken.

I moved around on some of the code, here is a new one: esp8266.zip

manfi001 commented 2 years ago

Same situation :-( ams2mqttAustria2.txt

gskjold commented 2 years ago

I would suggest trying UART2 and hook your meter up to GPIO13 so that a actual hardware serial is used. I feel like this could be related to some instability using software serial. Judging from the log, assembly is working fine now, but for some reason you are getting overflow in between.

manfi001 commented 2 years ago

The problem is, that I am using a Wemos D1 mini and it has the hw serial connected to the ftdi chip

manfi001 commented 2 years ago

Would my key help you for debugging?

gskjold commented 2 years ago

If you choose UART2 as HAN pin, the hardware serial pins will be swapped to pin 13 (RX) an 15 (TX) and will prevent USB chip from interfering

If it still does not work and you are OK with sharing your key, please send it to gunnar.skjold@gmail.com

gskjold commented 2 years ago

Try this firmware: esp8266.zip

manfi001 commented 2 years ago

Thanks! Looks better now, but: reactive part still all zeroes, btw: how can I delete the false historic data? ams_reader211227

Meter manufacturer and model not appearing amsreader21 12 27_2 HDLC errors solved: ams_reader_211227_log.txt (readHanPort) System title: (D) 53 41 47 59 05 E6 D9 FD converted to ascii/dec =SAGY 99015165 could be the meter manufacturer/type, the number in bold are the last 6 digits of my counter no.

gskjold commented 2 years ago

Good to hear! I see in your decrypted frame that reactive values are not present (OBIS 3.7.0, 4.7.0, 3.8.0 and 4.8.0) There is no function to manually clear the graph other than erasing flash and re-flashing. The meter model detection currently does not use system title, but I will definitely implement that.

manfi001 commented 2 years ago

Still restarting sporadically. Could this be caused by weak wifi signal? Seems that restart also causes weird values (+14.4, -22.2) and that hourly and monthly data are not updated correctly. ( compare to yesterday's screenshot) ams_reader211228

gskjold commented 2 years ago

Looks like it is never saving graph data? Would have to look at log to figure that one out. Not sure about that reboot..

gskjold commented 2 years ago

Added checksum verification and cleaned up some code. It may or may not help with reboot. esp8266.zip

gskjold commented 2 years ago

Updated a few core functions in the code, new firmware file:

esp8266.zip

manfi001 commented 2 years ago

After erasing and re-flashing version 211228.1 the hourly values seem to be updated correctly but daily values are still missing: ams2mqtt_2022-01-03 192608 reboots less frequently, longest interval was 2 days.

Updated to ver. 220105.02 just now and noticed first reboot after only 15 min, 2nd after 18 min. previous version transmitted mqtt data every 5 sec. (same interval as meter data) but the new firmware has breaks (see MQTTfx log below) 2022-01-05 21:20:58,375 INFO --- MqttFX ClientModel : messageArrived() with topic: tele/Sagemcom/DATA 2022-01-05 21:21:03,377 INFO --- MqttFX ClientModel : messageArrived() with topic: tele/Sagemcom/DATA 2022-01-05 21:21:17,993 INFO --- MqttFX ClientModel : messageArrived() with topic: tele/Sagemcom/DATA 2022-01-05 21:21:18,407 INFO --- MqttFX ClientModel : messageArrived() with topic: tele/Sagemcom/DATA 2022-01-05 21:21:23,377 INFO --- MqttFX ClientModel : messageArrived() with topic: tele/Sagemcom/DATA 2022-01-05 21:21:28,376 INFO --- MqttFX ClientModel : messageArrived() with topic: tele/Sagemcom/DATA 2022-01-05 21:21:41,797 INFO --- MqttFX ClientModel : messageArrived() with topic: tele/Sagemcom/DATA 2022-01-05 21:21:43,382 INFO --- MqttFX ClientModel : messageArrived() with topic: tele/Sagemcom/DATA 2022-01-05 21:21:48,399 INFO --- MqttFX ClientModel : messageArrived() with topic: tele/Sagemcom/DATA 2022-01-05 21:22:01,899 INFO --- MqttFX ClientModel : messageArrived() with topic: tele/Sagemcom/DATA 2022-01-05 21:22:03,382 INFO --- MqttFX ClientModel : messageArrived() with topic: tele/Sagemcom/DATA 2022-01-05 21:22:08,384 INFO --- MqttFX ClientModel : messageArrived() with topic: tele/Sagemcom/DATA 2022-01-05 21:22:23,513 INFO --- MqttFX ClientModel : messageArrived() with topic: tele/Sagemcom/DATA 2022-01-05 21:22:28,378 INFO --- MqttFX ClientModel : messageArrived() with topic: tele/Sagemcom/DATA 2022-01-05 21:22:33,384 INFO --- MqttFX ClientModel : messageArrived() with topic: tele/Sagemcom/DATA

and sometimes only transmits ESP data: { "id" : "84:CC:A8:A1:FB:B0", "name" : "", "up" : 1084, "vcc" : 3.3, "rssi" : -78, "temp" : -127.0 }

Telnet debugging stops after 2 blocks: *** Remote debug - over telnet - for ESP8266 (NodeMCU) - version 3.0.5

Strange observation: 1st frame of 2nd block starts with 68 00 00 68, normally it's 68 01 01 68

gskjold commented 2 years ago

Thanks for the feedback. Attached is a new firmware that may or may not fix the graph ;) Still not sure about those reboots... Regarding 68 00 00 68, this is a "fake" (271b) frame assembled by the two partial frames (263b + 19b). I just chose to use 00 in length parameter to make the code ignore the length field.

esp8266.zip

manfi001 commented 2 years ago

New firmware solved the irregular mqtt message intervals and the debug log freeze. still no daily data in graph, to exclude weak wifi as reason for reboots, I connected an external antenna. wifi is green now, but reboots still occur appr. every hour. observation: free mem sometimes drops to 12k. Is it normal, that the telnet log closes after 10 min.?

gskjold commented 2 years ago

Telnet has 10min timeout, yes. Upstream library, so I have no control over it.

Try disabling debugging, I've had many cases lately where having telnet/serial debugger enabled causes reboot. Set level to ERROR and disable both telnet and serial.

Regarding month plot, it need to pass two midnights before it can start calculating.

manfi001 commented 2 years ago

disabled debugging, but still 5-6 restarts/day. hourly values in graph are o.k. but daily values still erratic. ams_reader 2022-01-09 112410 will try a second unit connected in parallel, to see if it is hardware related. In principle it does what I need: mbus to mqtt. The graphical interface is a nice feature, but not essential for me. Thanks for your efforts.

gskjold commented 2 years ago

Still working on why the month graph is acting up for some user, but I have made stability improvements on the attached firmware

esp32.zip esp8266.zip

manfi001 commented 2 years ago

updated with the new firmware. 1st impression: apart from restarts every couple of hours, seems to work fine. will continue observing. another challenge: tried the reader with a Sagemcom T210-D from another Austrian grid operator. The user port follows the DSMR 5.0.2 standard with additional encryption ( like meters in Luxembourg) . Data is pushed every 10 sec. with 115200 baud, 8N1. I tried the 220106.1 and the standard 2.0.6 firmware, but get "unknown data format 8C"

gskjold commented 2 years ago

Although DSMR should be supported, I have not implemented decryption for it. Do you know of any documentation on that encryption?

manfi001 commented 2 years ago

Found something here: http://www.weigu.lu/microcontroller/smartyReader/index.html

manfi001 commented 2 years ago

With the new firmware it reached the longest interval between restarts (>20h) but since yesterday morning HAN is red and log shows "Frame timestamp is not correctly formatted"