# OIP-0024: Event, RPC and sensor-API bindings: CloudEvents, gRPC, SensorThings and Connected Systems

| Field | Value |
|---|---|
| Status | DRAFT |
| Functions | `observe` (§5.5), `exchange` (§5.10), `prove` (§5.11), `describe` (§5.3); no new function (the register keeps exactly twelve) |
| Requires | OIP-0006 for the two sensing-API bindings (`sensorthings`, `connected-systems`), which name its Observer, Deployment, FeatureOfInterest and observation record 4.0.0. The patches apply to the current tree on their own; the acceptance order is below |
| Affects | §6 (one paragraph naming the four bindings, no key word); new bindings `bindings/cloudevents/`, `bindings/grpc/`, `bindings/sensorthings/`, `bindings/connected-systems/` with their tests and a shared test helper; new file `schemas/proto/obsp/v1/services.proto`; `registers/relations.yaml` (three new rows, one extended), `registers/implements-edges.json` and `registers/requirements.yaml` regenerated; cases CT-NODE-110 and 111, CT-GRID-110 to 113, CT-CONSUMER-110 and 111 (CT-NODE-110 and CT-GRID-110 automated by `binding-cloudevents-*` invariants over the events, `sdk/python/src/obsp/inv_oip0024.py`; the other six manual, with attestations); one assertion of `tests/test_runner_service.py` given the attestations of its example set |
| Protocol version | obsp/0.1 |
| Last call | 30 days (bindings of existing functions, no new object) unless the editors rule otherwise |

## Problem

Section 6 names the standards the protocol rides on, and four of them have no binding:

1. **Events.** "EventEnvelope ↔ CloudEvents 1.0" is one table row. Nothing says which CloudEvents `type`, `source`,
   `subject`, `id` and `time` an observation, a node state receipt or a correction notice gets, where the RequestContext
   of section 4.3 goes (CloudEvents has no array or object attribute type), or what a consumer does with a duplicate. Two
   publishers will pick different attribute names and neither sink can filter on the other's events.
2. **RPC.** Section 6 says the control plane uses "protobuf messages in package `obsp.v1` over gRPC or HTTP/2", but
   `schemas/proto/obsp/v1/common.proto` holds seven messages and no service: there is no rpc to call, no streaming
   shape for the at-least-once submission of section 6, and no rule for how an error reaches a gRPC client.
3. **Sensing APIs.** Section 6 lists SensorThings, and section 4.3 and the Consumer profile expect open exchange. A
   SensorThings or Connected Systems server fed from OBSP records can silently drop what makes a record trustworthy:
   write a missing value as zero, publish a longitude-latitude pair swapped, show a superseded value as current, and
   lose the evidence, origin and digest that tie the entity to the record.

## Change

### Normative text (§6, one paragraph after the wire-bindings table)

A paragraph names the four bindings and says that a publication or endpoint that names one of them is held to every
requirement of its profile. It carries no key word, so the requirement index keeps its ids; the binding requirements are
the normative content. `patches/spec.patch`.

### The four bindings (status proposed)

Each folder follows `bindings/README.md` and the worked pattern of OIP-0009 and OIP-0019: `PROFILE.md` (scope, standard,
every requirement, the mapping by name, examples, open questions), `binding.yaml`, `mapping.yaml` (every row
`checked: not checked`, elements not mapped with the reason), the artefact in the standard's own syntax, positive and
negative examples, and a test.

| Binding | Standard (edition) | Artefact | Requirements | Examples (+/-) |
|---|---|---|---|---|
| `cloudevents` | CloudEvents 1.0.2, JSON event format, HTTP protocol binding | `cloudevent.schema.json` and one data schema per event type | BND-CLOUDEVENTS-01 to -13 | 5 / 12 |
| `grpc` | Protocol Buffers proto3 with gRPC services, streaming and status codes | `schemas/proto/obsp/v1/services.proto`, `mapping.yaml` status table | BND-GRPC-01 to -11 | 5 / 9 |
| `sensorthings` | OGC SensorThings API Part 1: Sensing 1.1 | `sta-profile.schema.json` | BND-SENSORTHINGS-01 to -13 | 5 / 11 |
| `connected-systems` | OGC API - Connected Systems Part 1 and Part 2, 1.0 | `cs-profile.schema.json` | BND-CONNECTEDSYSTEMS-01 to -14 | 8 / 12 |

What each binding pins down beyond the standard:

- **CloudEvents.** One type for each event of the field contract (`schemas/asyncapi/obsp-field.asyncapi.yaml`):
  `obsp.observation.recorded`, `obsp.node.state.observed`, `obsp.correction.issued`, and `obsp.event.<eventType>` for the
  generic EventEnvelope. The data is the whole unchanged record, so its digest survives the envelope; `dataschema` is the
  URN of one JSON Schema per type (the artefact). `source` is the publishing authority's https URI, `subject` the UNI of
  the record, `id` the record's own key (so a redelivery repeats `source` and `id` and the consumer absorbs it), `time`
  the record's own time and never the publication time. Extension attributes are lower case letters and digits, as
  CloudEvents requires, all starting `obsp`: the eight required fields of the RequestContext (every event carries one,
  section 4.3), the optional ones, the first evidence reference as `obspevidenceuri` and `obspevidencedigest`, and the
  sequence, aggregate version, causation and correction fields of the record. An attribute that copies a record field
  equals it, and a consumer discards an event where they differ.
- **gRPC.** Three services: `Observe` (`SubmitObservations`, a bidirectional stream with an idempotency key and a
  sequence per record, acknowledged in order, a repeated key answered DUPLICATE and not as an error), `Exchange`
  (`GetObservation`, `ListObservations`, `GetProduct`, `ListCorrectionNotices`, each response carrying the correction
  state, withdrawn and recalled records only on request) and `Prove` (`Challenge`, `Verify`, whose result is the receipt
  result vocabulary). A protocol document travels whole as a `Document` (RFC 8785 canonical JSON and its OBSP digest), so
  JSON Schema stays the one definition. The `RequestContext` is field 1 of every request. A failed call carries an
  `ErrorProblem` in the status details and the gRPC status code that `mapping.yaml` gives for its category (sixteen
  categories, one code each).
- **SensorThings.** Observer to Sensor (the passport as `metadata` and in `properties`), Deployment to Thing with its
  Location and HistoricalLocation, observed property register id to ObservedProperty `definition`, a derived Datastream
  (one per observer, property, procedure and unit, id `uni:datastream:` and sixteen hex digits of a hash, unit symbol the
  UCUM code), FeatureOfInterest to FeatureOfInterest, record to Observation. Geometry is CRS84 with longitude first or
  omitted. A value that is not PRESENT is a null result with `obsp:resultState`, never zero. Origin, subject class,
  procedure, record digest and every evidence reference are in `parameters`; a record that is not CURRENT carries its
  state and, if superseded, its successor. The endpoint is read only.
- **Connected Systems.** The same objects as System, Deployment, Sampling Feature, Property (Part 1) and Datastream,
  Observation (Part 2); the class table gives each observer class its system type; the passport and the evidence are
  `describedby` and `evidence` links with digests; the Datastream id is the SensorThings binding's, so an endpoint
  offering both names one datastream once. The endpoint is read only.

`Datastream` is not an OIP-0006 object: both sensing bindings derive it, so this proposal adds no protocol object and no
schema to `schemas/json/`.

### Registers

- `registers/relations.yaml`: `EXT-STA` gains its artefact `bindings/sensorthings/` and the schemas it touches; new
  external rows `EXT-OGCCS`, `EXT-GRPC` and `EXT-CLOUDEVENTS`, each naming its folder in `artefacts`.
- `registers/implements-edges.json` regenerated (44 edges); `registers/requirements.yaml` regenerated (no new section
  requirement; the new cases are attached by the generator).

### Acceptance order

1. OIP-0006 is accepted first for the two sensing bindings; once its schemas exist the two sensing-binding tests also
   check their source documents against the Observer, Deployment, FeatureOfInterest and ObservationRecord schemas (they
   skip that check today and use constants copied from OIP-0006's example documents).
2. This proposal's patches are applied together (any order among themselves), then `python3 tools/build_edges.py` and
   `python3 tools/requirements.py` are run again if another proposal landed in between.

## Compatibility

Additive: four bindings, one protobuf file, three new relation rows, one extended row, eight cases (two automated, six manual), one paragraph
without a key word. `common.proto` is unchanged and no existing message changes shape. No schema changes. The OBSP-NODE,
OBSP-GRID and OBSP-CONSUMER example sets gain attestations for the manual cases (the OBSP-GRID set gains its file, as OIP-0009's does) and the CloudEvents events as evidence for the two automated ones.
`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 and OIP-0019's). `tests/test_runner_service.py` uploads its OBSP-NODE evidence with the example set's
attestations, because the set now has manual cases and its JSON upload does not carry them.

## Tests

| Requirements | Case | Kind |
|---|---|---|
| BND-CLOUDEVENTS-01 to -11 | CT-NODE-110, CT-GRID-110 | automated: the events validated against the binding schema and compared with their records (`binding-cloudevents-node`, `-grid`); `tests/test_cloudevents_binding.py` |
| BND-CLOUDEVENTS-01, -02, -07, -09 to -12 | CT-CONSUMER-110 | manual, attested |
| BND-GRPC-01 to -05, -09 | CT-NODE-111 | manual (a stream over TLS 1.3 with mutual authentication; a plaintext connection refused), attested; `tests/test_grpc_binding.py` |
| BND-GRPC-01 to -10 | CT-GRID-111 | manual (a running service), attested |
| BND-SENSORTHINGS-01 to -11, -13 | CT-GRID-112 | manual (a running service; a write request refused), attested; `tests/test_sensorthings_binding.py` |
| BND-CONNECTEDSYSTEMS-01 to -12, -14 | CT-GRID-113 | manual (a running service; a write request refused), attested; `tests/test_connected_systems_binding.py` |
| BND-GRPC-07, -11; BND-SENSORTHINGS-10 to -12; BND-CONNECTEDSYSTEMS-10 to -13 | CT-CONSUMER-111 | manual, attested |

Each binding test derives every positive example from its fixtures (and, for the sensing bindings, the OIP-0006
example documents), shows that each negative example breaks exactly the requirement its file name states, and has
binding-specific checks: the CloudEvents attribute register equals the schema and every event type of the AsyncAPI
contract is mapped; the protobuf files are read by a structural parser because `protoc` is not assumed (services, rpc
shapes, request context as field 1, unique field numbers, enum vocabularies equal to the JSON Schemas, a status code for
every `error-problem` category; `make proto` remains the compiler check); the SensorThings and Connected Systems
datastream ids agree and the class table covers every observer class. `tests/binding_sources.py` holds the schema
registry and the shared sources.

## Open questions

1. Every external reference is `checked: not checked`. In particular the publication status, document numbers and member
   names of OGC API - Connected Systems Part 1 and Part 2, the SensorThings 1.1 document number, and whether a null
   `result` is allowed; gRPC has no numbered edition, so the manifest names the proto syntax. The manifests state
   `editionStatus: published`, a claim the editors must check before acceptance.
2. CloudEvents asks for a reverse-DNS prefix on `type`; `obsp.` is a placeholder until the steward names the domain.
   Where the schemas are published, and so their identifiers, is a hosting decision for the steward.
3. `Prove` follows the live `proof-receipt`; OIP-0002 revises the challenge and the receipt, and the rpc messages then
   follow its `proof-challenge` and `verification-report`.
4. The unit label and definition of a SensorThings Datastream have no source until the observed-property register carries
   unit labels; both sensing bindings write the UCUM code and, for SensorThings, the UCUM specification address.
5. Whether correction state belongs in `parameters` (as written) or in a second Observation, and whether the link relation
   `evidence` should be a URI relation.
6. Whether a gRPC message size limit needs a chunked `Document`, and whether a signed batch (OIP-0008) is also accepted
   by `SubmitObservations`.
7. A Connected Systems Sampling Feature names the feature it samples; OIP-0006's FeatureOfInterest has no such member.
