# OIP-0019: Field connector bindings: LoRaWAN, OPC UA, WIS 2.0 and BUFR ingest, NMEA 0183 and SDI-12

| Field | Value |
|---|---|
| Status | DRAFT |
| Function | `observe` (§5.5); no new function (the register keeps exactly twelve). A connector is part of Observe |
| Requires | OIP-0007 (connector contract CON-1 to CON-10, schemas `connector-mapping` and `connector-output`), with the two enum additions of "Amendments asked of OIP-0007" below. The patches apply to the current tree on their own; the acceptance order is below |
| Uses | OIP-0006 (observed-property register): every mapped property id and every BUFR descriptor is one its register patch names; the binding tests check it against `registers/observed-properties.yaml` once that register exists |
| Affects | §5.5 (one bullet naming the field connector bindings, no new key word); new bindings `bindings/lorawan/`, `bindings/opcua/`, `bindings/wis2-ingest/`, `bindings/nmea/`, `bindings/sdi12/` with their tests and a shared test helper; `registers/relations.yaml` (new rows `EXT-LORAWAN`, `EXT-OPCUA`, `EXT-WMOBUFR`, `EXT-NMEA`, `EXT-SDI12`); `registers/implements-edges.json` and `registers/requirements.yaml` regenerated; new cases CT-NODE-080 to CT-NODE-084 (automated: the golden examples of each binding replayed, `obsp.golden`) with replay evidence in the OBSP-NODE example sets and the invariant module `sdk/python/src/obsp/inv_oip0019.py`; the demo-binding helper of `tests/test_validate.py` made independent of the shipped bindings |
| Protocol version | obsp/0.1 |
| Last call | 30 days (bindings of an existing function, no new object) unless the editors rule otherwise |

## Problem

Section 5.5 says a node "MAY also speak LoRaWAN, OPC UA or vendor buses through a connector", and OIP-0007 states what
every connector must do (CON-1 to CON-10) with one worked binding, Sparkplug. The field technologies most stations use
besides Sparkplug have no binding: LoRaWAN sensors behind a network server, OPC UA servers in plants and utilities, WMO
stations that report in BUFR through WIS 2.0, marine and buoy instruments speaking NMEA 0183, and hydrological and
agricultural sensors on an SDI-12 bus. Without a binding, two connectors for the same technology can take different
native identifiers as identity (a LoRaWAN DevAddr that changes every session, an OPC UA namespace index a server may
renumber, a WIGOS identifier built from block and station numbers), read a server clock as the observation time, flag a
value good because the instrument said "valid", ignore a checksum or a CRC, shift SDI-12 values by one position, or fill
a frame counter gap silently. A consumer cannot compare their outputs and a verifier cannot replay them.

## Change

### Normative text (§5.5, one bullet after "Field-side transport")

- Field connector bindings: `bindings/lorawan/` (LoRaWAN uplinks from a network server), `bindings/opcua/` (OPC UA,
  IEC 62541, PubSub and client reads), `bindings/wis2-ingest/` (WMO BUFR announced by WIS 2.0), `bindings/nmea/` (NMEA
  0183) and `bindings/sdi12/` (SDI-12) fix the connector mapping for each technology; a connector that names one of them
  in its mapping is held to every requirement of that binding's profile.

The bullet carries no key word, so the requirement index keeps its ids; the binding requirements are the normative
content. §6 is not edited: its Data (field) row already names connectors for LoRaWAN, OPC UA and vendor buses, and
OIP-0001, OIP-0005 and OIP-0009 edit the lines around it.

### The five bindings (status proposed)

Each folder follows `bindings/README.md` and the Sparkplug binding of OIP-0007: `PROFILE.md` (scope, standard, every
requirement, the mapping table by clause, examples, open questions), `binding.yaml`, `mapping.yaml` (every row with its
clause and `checked: not checked`, the decoder described as data, elements not mapped with the reason),
`connector-mapping.json` (a `connector-mapping` record whose `decoderDigest` is the SHA-256 of the canonical JSON form of
the decoder tables and whose `goldens` list every example with its digest), positive and negative golden examples (the
native message rendered as JSON, the connector's state before it, and the expected output as a projection), and a test.

| Binding | Standard (edition) | Native id (scheme) | Quality | Time source | Sequence | Requirements | Examples (+/-) |
|---|---|---|---|---|---|---|---|
| `lorawan` | LoRaWAN L2 1.0.4 (2020), LoRaWAN 1.1 (2017) | DevEUI (`LORAWAN_DEVEUI`) | none: `NOT_CHECKED` | `NETWORK_SERVER` (receive time) | FCnt, modulo 2^32 per device, reset at a new session | BND-LORAWAN-01 to -13 | 5 / 5 |
| `opcua` | IEC 62541 parts 3, 4, 6, 8, 14 (2020 or later) | server URI and object NodeId with namespace URI (`OPCUA_NODEID`) | StatusCode severity: Good, Uncertain, Bad | `DEVICE` (SourceTimestamp) | PubSub DataSetMessage sequence number, modulo 2^16; client read none | BND-OPCUA-01 to -13 | 4 / 5 |
| `wis2-ingest` | WMO FM 94 BUFR edition 4 (WMO-No. 306), WIGOS identifier (WMO-No. 1160), WIS2 Notification Message (WMO-No. 1061) | WIGOS station identifier from the subset (`WIGOS_STATION_ID`) | quality control indication 033020 (`WMO_BUFR_QC`) | `DEVICE` (subset time) | none | BND-WIS2INGEST-01 to -12 | 4 / 4 |
| `nmea` | NMEA 0183 4.11 (IEC 61162-1:2016); NMEA 2000 named only | port and talker (`NMEA_SOURCE`) | status field A or V (`NMEA_STATUS`) | `CONNECTOR` (receive time) | none | BND-NMEA-01 to -13 | 7 / 4 |
| `sdi12` | SDI-12 1.4 | bus and address (`SDI12_ADDRESS`) | none: `NOT_CHECKED` | `GATEWAY` (datalogger) | none | BND-SDI12-01 to -13 | 5 / 4 |

What each binding pins down beyond the contract:

- **LoRaWAN**: identity by DevEUI, never DevAddr; FPort 0 and 224 to 255 never converted; payload decoders are byte
  layouts described as data (offset, type, scale, decimals, no-data sentinel); a no-data sentinel is `MISSING`; a
  repeated FCnt (retransmission) gives nothing; gateway EUI, RSSI, SNR and gateway time and the radio parameters are
  link evidence, never a result time; the MIC is the network server's.
- **OPC UA**: identity by ExpandedNodeId with `nsu=`, never `ns=<index>`; variables by BrowseName under the instrument
  object; DataValue Value to result by a data type table, an absent Value is `MISSING`; StatusCode severity Good, Uncertain,
  Bad to `GOOD`, `SUSPECT`, `BAD` (reserved severity never `GOOD`); SourceTimestamp only, never ServerTimestamp;
  EngineeringUnits by a UNECE common code to UCUM table (21 units), a unit other than the mapped one gives no
  observation; no Write or Call.
- **WIS 2.0 and BUFR ingest**: identity from descriptors 001125 to 001128 of the subset, never the notification alone
  and never built from block and station numbers; the retrieved bytes must have the announced digest before decoding;
  descriptors to properties only by the table (each descriptor is the WMO code of its property in the OIP-0006 register
  patch: 012101, 012103, 013003, 010004, 010051, 011001, 011002, 011041), converted from the Table B unit (K to Cel, Pa to
  hPa) and rounded to the table's decimals; quality from 033020 by table; time from 004001 to 004006; one output per
  subset. It is the inbound counterpart of `bindings/wis2/` (OIP-0009, exchange) and does not overlap it.
- **NMEA 0183**: identity `<port>/<talker>`; the checksum is checked and recorded as raw evidence (CON-7), a sentence
  that fails it gives nothing else; native fields carry their unit or reference letter (`MWV.speed.N`) and each letter has
  its own conversion; an MWV angle, measured from the bow, is never a direction from north; GGA gives a trajectory point
  (`obsp.trajectory`), never usable at fix quality 0; ZDA gives a clock sample (`obsp.time`); NMEA 2000 parameter groups
  are listed only.
- **SDI-12**: identity `<bus>/<address>`, converted only when the identification response matches the mapping's
  (an address is reused when a sensor is replaced); the k-th value across the data pages is native field `M.k` (`M1.k`,
  `C.k`), mapped by position from the sensor metadata; an announced value not delivered is `MISSING`; a data page that
  fails its CRC gives nothing; the datalogger clock stamps the measurement.

### Amendments asked of OIP-0007

The connector-mapping schema of OIP-0007 has closed lists (its open question 7 says further native id schemes each need
an OIP). This proposal is that OIP for two of them and for two quality schemes:

| List in `connector-mapping.schema.json` | Addition |
|---|---|
| `$defs/NativeId/properties/scheme/enum` | `NMEA_SOURCE` (`<port>/<talker>`), `SDI12_ADDRESS` (`<bus>/<address>`, address one of 0-9, A-Z, a-z) |
| `$defs/QualityMap/properties/scheme/enum` | `WMO_BUFR_QC` (code table 0 33 020), `NMEA_STATUS` (status field A or V) |

Because the schema is not in the tree, these additions cannot be a patch of this proposal that applies on its own. They
are applied to OIP-0007's schema when OIP-0007 is accepted (if this proposal is accepted with it) or by a one-line patch
at this proposal's acceptance; `tests/connector_golden.py` states them (`AMENDMENT`) and validates every connector
mapping against the OIP-0007 schema with them as soon as the schema exists. Nothing else in OIP-0007 changes: the
bindings use only its time sources, sequence schemes, unmapped reasons and the namespaced `extensions` bag
(`obsp.trajectory`, `obsp.time` on outputs, `obsp.sdi12` on a mapping).

### Registers

- `registers/relations.yaml`: five new external rows, each naming its binding folder in `artefacts`, function
  `observe`, profile OBSP-NODE and schemas `observation-record` and `time-quality` (the schemas in the tree today). No
  existing row states these standards, so extending one was not possible.
- `registers/implements-edges.json` regenerated (46 edges); `registers/requirements.yaml` regenerated (the §5.5
  requirements gain the five cases; the new bullet has no key word, so no id changes).

### Acceptance order

1. OIP-0007 is accepted first (its schemas, cases CT-NODE-071 to CT-NODE-075 and Sparkplug binding), with the
   amendments above in its connector-mapping schema.
2. This proposal's patches are applied together. Then, in the same change: `connector-mapping` and `connector-output`
   join `schemas` of each `binding.yaml` and of the five relation rows; `python3 tools/build_edges.py` and
   `python3 tools/requirements.py` are run again; the binding tests then also validate each connector mapping against
   the schema (they skip that check today).
3. When OIP-0006 is accepted, the tests check every mapped property and descriptor against the register (they skip
   that check today).

## Compatibility

Additive: five bindings, five relation rows, five automated cases, one non-normative bullet. No existing document changes
meaning and no schema changes in this proposal. The OBSP-NODE example set gains five replay evidence documents (the digests of the golden outputs) and the OBSP-NODE
negative set gains the same five, so that it still fails only the two cases it was built to fail. `tests/test_validate.py` checks the
demo binding alone, so it no longer depends on how many bindings ship (the same hunk as OIP-0009's).

## Tests

| Requirement | Case | Kind |
|---|---|---|
| BND-LORAWAN-01 to -13 | CT-NODE-080 | automated: replay of every golden uplink (`binding-replay-lorawan`); `tests/test_lorawan_binding.py` |
| BND-OPCUA-01 to -13 | CT-NODE-081 | automated: replay of every golden example (`binding-replay-opcua`); `tests/test_opcua_binding.py` |
| BND-WIS2INGEST-01 to -12 | CT-NODE-082 | automated: replay of every golden example (`binding-replay-wis2-ingest`); `tests/test_wis2_ingest_binding.py` |
| BND-NMEA-01 to -13 | CT-NODE-083 | automated: replay of every golden example (`binding-replay-nmea`); `tests/test_nmea_binding.py` |
| BND-SDI12-01 to -13 | CT-NODE-084 | automated: replay of every golden example (`binding-replay-sdi12`); `tests/test_sdi12_binding.py` |

The case numbers 080 to 084 follow OIP-0007's 071 to 075 and leave 076 to 079 free. Each binding test derives every
positive example's expected output from its native message and the binding's tables, shows that each negative example
breaks exactly the requirement its file name states (and only that one), checks the decoder digest against the decoder
tables and the golden digests against the files, checks each connector mapping structurally against the OIP-0007
contract with the amendments, and has binding-specific checks (frame counter wrap, unknown source, OPC UA unit ids
against the common code encoding, StatusCode severity, NMEA checksum, SDI-12 CRC and value order).

Negative examples, one broken requirement each: LoRaWAN `devaddr-as-identity` (-01), `no-data-sentinel-as-value` (-05),
`frame-counter-gap-not-recorded` (-06), `repeated-frame-counter-recorded` (-07), `gateway-time-as-result-time` (-08);
OPC UA `namespace-index-identity` (-01), `uncertain-as-good` (-06), `server-timestamp-as-result-time` (-07),
`unit-mismatch-converted` (-08), `sequence-gap-not-recorded` (-09); WIS 2.0 and BUFR `traditional-id-as-wigos` (-01),
`integrity-mismatch-accepted` (-03), `kelvin-not-converted` (-05), `qc-doubtful-as-good` (-07); NMEA
`checksum-ignored` (-03), `knots-not-converted` (-05), `relative-angle-as-direction` (-06), `void-status-as-good` (-08);
SDI-12 `identity-mismatch-accepted` (-03), `values-shifted` (-04), `missing-value-as-zero` (-07), `crc-ignored` (-08).

## Open questions

1. Every clause number, code, field order and unit code in the five bindings is `checked: not checked` against the
   published texts (LoRaWAN 1.0.4 and 1.1, IEC 62541 parts, WMO-No. 306, 1160 and 1061, NMEA 0183 4.11 and IEC 61162-1,
   SDI-12 1.4, UNECE Recommendation 20). A person must compare them before any binding leaves proposed status.
2. Unmapped reasons: OIP-0007 has `NOT_IN_MAPPING`, `TRANSIENT` and `UNSUPPORTED_TYPE`. OPC UA uses `NOT_IN_MAPPING` for
   a unit that differs from the mapped one and `UNSUPPORTED_TYPE` for a value without a source timestamp; LoRaWAN uses
   `UNSUPPORTED_TYPE` for a payload of the wrong length. Should OIP-0007 add `UNIT_MISMATCH`, `NO_TIME` and
   `LENGTH_MISMATCH`?
3. Source-declared quality: NMEA status A and OPC UA Good map to `GOOD`, as Sparkplug quality 192 does in OIP-0007. Should
   a flag that only repeats what the source declares be `GOOD`, or `NOT_CHECKED` with the native code kept, until a
   protocol test has run (OIP-0007 open question 3)?
4. Payload digests where the connector sees no bytes: the OPC UA binding digests a canonical JSON form of the DataValues
   and the SDI-12 binding the response lines with their line ends. Is a canonical form acceptable raw evidence under CON-7?
5. Should byte layouts (LoRaWAN), descriptor tables (BUFR) and unit tables (OPC UA) become registers with digests, so
   that two operators can show they decode the same way, instead of living in each binding's `mapping.yaml`?
6. The WIS 2.0 ingest binding reads instantaneous values only; accumulated and extreme values need the interval form of
   the universal observation (OIP-0006). Should the period descriptors wait for it?
7. Should the connector cases move to an optional connector overlay instead of OBSP-NODE (OIP-0007 open question 5)? A
   node that speaks one of these technologies natively has no connector.

Acceptance needs appointed editors and a last-call window. Until then this proposal stays at DRAFT and none of the five
bindings exists in the protocol.
