Repository navigation
Decode the Landis+Gyr push that carries no descriptors or OBIS codes - #1269
Merged
Merged
Conversation
A Landis+Gyr E450 (IDIS 2DLM, Slovenia) pushes a bare COSEM structure: no capture-object descriptor array and no OBIS codes, just the meter id followed by naked integers. Two shapes alternate every ~2 s -- a 9-item frame with the totals (1/2/3/4.7.0 and 1/2/3/4.8.0) and a 14-item frame with the per-phase values. LNG needs the descriptor array and LNG2 needs a long-unsigned first element, so neither claims these frames and IEC6205675 falls through to "unknown meter type". The reader decodes the frames all the way to DLMS but produces listType 0, so validDataReceived never reaches 2 and serial autodetect keeps rotating baud rates past the setting that works (2400 8N1). There is no configuration workaround. Add LNG3 for the two shapes. The format carries no identifier, so LNG3::matches() validates the structure tag, the element count and the type of every value before the payload is cast onto a layout struct. Iskra sends a 9-item structure of the same shape led by its "ISK..." list id, so the leading octet string must also be all digits -- every list identifier in this decoder contains letters, while this one is the bare serial. Voltage is whole volts here, so it is taken unscaled rather than divided by 10 as in the sibling lists. Frequency (element 2 of the 14-item frame) is named in the layout struct for offset correctness but not read: AmsData has no field for it. Costs 1372 bytes of flash on ESP8266 (98.1% -> 98.3%). The fixture serial is redacted and the HDLC FCS recomputed; every other byte is the original capture. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The push object lists the DSO supplied show the two frames lead with different registers: the 9-item frame with 0-0:96.1.0, the manufacturer serial, and the 14-item frame with 0-0:96.1.1, a serial the utility assigns separately. LNG3 assumed both were the same id and wrote meterId from whichever frame arrived. On the reporter's meter the two registers happen to hold the same digits, so the capture does not show it, but where they differ meterId would flip every couple of seconds and take the MQTT topic and the Home Assistant entity id with it. LNG uses 96.1.0 on the sibling L&G format, so follow that: only the 9-item frame sets meterId, and apply() carries it into the other frame. The same lists confirm the rest of the mapping register for register, including element 2 of the 14-item frame as 1-0:14.7.0 net frequency. Recorded in the layout structs and the payload README. Testing the carry-forward needs the parser to see the running meter state, the way PassiveMeterCommunicator::getData() passes it, so give the harness a sequencing entry point instead of always decoding against an empty state. Co-Authored-By: Claude Opus 5 <[email protected]>
🔧 PR Build ArtifactsVersion: All environments built successfully. Download the zip files:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A Landis+Gyr E450 (IDIS 2DLM) in Slovenia was reported as unsupported. The reader actually reads it fine — the failure is one layer up.
The problem
The meter pushes a bare COSEM structure: no capture-object descriptor array and no OBIS codes, just the meter id followed by naked integers. Two shapes alternate every ~2 s:
LNGneeds the descriptor array andLNG2needs a long-unsigned first element, so neither claims these frames andIEC6205675falls through toAMS unknown meter type, trying to identify....The knock-on effect is what the reporter sees. Framing, CRC and DLMS unwrapping all succeed — the debug log shows
Received valid DLMS at 30 +56at 2400 8N1 — but the parser returnslistType 0, sovalidDataReceivednever reaches 2 andhandleAutodetect()keeps rotating baud rates straight past the setting that works. It walked over the correct one twice in the submitted log. Pinning the port manually stops the rotation but still yields no data, so there is no configuration workaround.The fix
LNG3, a third parser alongsideLNG/LNG2, dispatched fromPassiveMeterCommunicator::getData().The format carries no identifier at all, so
LNG3::matches()validates the shape instead of a magic string: structure tag, element count 9 or 14, a leading octet string, and the type byte of every value checked against the expected run — plus a length guard, since a bad cast here reads off the end of the HAN buffer. The test is behind a static method rather than inline in the dispatch because the existingif/elsechain has no way back toIEC6205675once a branch is taken.Worth a look during review: Iskra sends a 9-item structure of exactly the same shape, led by its
ISK1030777478586list id (test/payloads/iskraemeco/gh869-6.hex). The first cut silently stole that frame and changed its decode; the golden sweep caught it.matches()now also requires the leading octet string to be all digits — every list identifier in this decoder contains letters, while this one is the bare serial.Voltage is whole volts on this meter, so it is taken unscaled rather than divided by 10 as in the sibling lists — this avoids reintroducing the 23.7 V-instead-of-237 V bug seen on
gh949/gh934.Confirmed against the DSO's documentation
The mapping was originally reverse-engineered from the capture. The reporter has since obtained the meter's push object lists from the DSO, which confirm it register for register:
9-item frame —
0-0:96.1.0Device ID 1 (manufacturer serial), then1-0:1.7.0+P,2.7.0-P,3.7.0+Q,4.7.0-Q,1.8.0+A (QI+QIV),2.8.0-A (QII+QIII),3.8.0+R (QI+QII),4.8.0-R (QIII+QIV).14-item frame —
0-0:96.1.1Device ID 2 (utility serial number 2), then1-0:14.7.0net frequency any phase,31/51/71.7.0currents,32/52/72.7.0voltages,21/41/61.7.0+P per phase,22/42/62.7.0-P per phase.Everything matched except one thing, now fixed in the second commit: the two frames lead with different id registers. The parser assumed they were the same and wrote
meterIdfrom whichever frame arrived. On this meter both registers happen to hold the same digits so the capture doesn't expose it, but where they differ the id would flip every couple of seconds, taking the MQTT topic and the Home Assistant entity id with it. Only the 9-item frame (96.1.0) setsmeterIdnow, matching whatLNGdoes on the sibling L&G format.Testing that carry-forward needed the parser to see the running meter state the way
PassiveMeterCommunicator::getData()passes it, sodecoder_harnessgained a sequencing entry point rather than always decoding against an empty state.The DSO also documents the port as 2400 8E1. The submitted log decoded five consecutive frames cleanly at 8N1 and autodetect never tried 8E1, so it settles there and runs — worth knowing, but nothing to change here.
Not addressed
AmsDatahas no field for it. It is named in the layout struct for offset correctness and left unread; adding the field would touchAmsData, the MQTT templates and the UI.elgama/gh1177-1.txtandkamstrup/gh1191-1.hexadded,gh175-2counter85820.920→0.000) come frommanifest.jsonbeing stale onmain— regenerating it on a clean tree reproduces them without any of these changes. Thegh175-2shift is state carry-over between fixtures in the golden sweep now thatgh1191-1decodes ahead of it, which is arguably a harness bug worth a separate look. Left alone rather than folded in here.Verification
New fixtures
test/payloads/landis-gyr/em-si2026-{1,2}.hex. The reporter's meter serial is redacted (replaced with999999999999, HDLC FCS recomputed); every other byte is the original capture.test_landisgyr_e450_sloveniaasserts both frames field by field. Golden sweep now records:Cross-check on the per-phase frame: 221 + 82 + 205 W = 508 W, exactly the 1.7.0 the meter pushes 3 s later.
pio test -e native— 25/25 pass, no other fixture's decode changedpio run -e esp8266dev— SUCCESS, +1372 bytes flash (98.1% → 98.3%, 18021 bytes still free)pio run -e esp32dev— SUCCESS🤖 Generated with Claude Code