ADR 0035 — Platform upstreams: live data to MQTT/UNS, Sparkplug B, ThingsBoard, Azure IoT Hub and AWS IoT Core
Status: proposed · 2026-11-04 (owner request: an extension that raises data to popular platforms, set up the way an upstream broker is (sys/upstream ▸ Add), several platforms at once).
Context
An upstream broker (ADR 0007, 0015, 0018) is added at runtime with one action (sys/upstream ▸ Add Upstream Connection {name, url, ca, token, enabled}) or in wyrmd.json5, and shows as sys/upstream/<site>/{url, status, enabled, …}. It carries the whole tree up to another WYRM broker over Zenoh. Sites also need their live values in the platforms the rest of the plant already uses: a Unified Namespace on an MQTT broker (HiveMQ, EMQX, Mosquitto), Ignition’s MQTT Engine and other Sparkplug B hosts, ThingsBoard, Azure IoT Hub, AWS IoT Core.
What exists: history sync (ADR 0026) sends the historian’s rows to databases in batches from a change journal, with a cursor, for watched points only, seconds behind. The mqtt link (links/mqtt) reads from an MQTT broker as a device driver. A portable App (ADR 0023, 0030) runs the same code embedded, as a process and as a WASM component, with tcp_connect/tls_connect under the link’s net allowlist, subtree subscriptions (<prefix>/**, ADR 0025), a sealed store and random_bytes.
Decision
- One portable App,
links/uplink, embedded atwy/<site>/downstream/uplinkin everywyrmd(uplink: {enabled, store_mb, net, upstreams}; id reserved asscheduleranddqlare; packagesuplink(WASM, worldwyrm:app@0.3.0) anduplink-processfor a broker that runs it elsewhere). It only reads:readon this site’sdownstream,dataflows,storageand on the sections of the downstream sites this broker reads (as the DQL link), neversys. It has no requester key use: nothing it does is a request to another link. - Set up as an upstream broker is. The link root has one Add action per platform (
add_mqtt,add_sparkplug,add_thingsboard,add_azure,add_aws), each withname,url,enabled, the keys to send (select) and the platform’s own fields;set_passwordkeeps the one secret (an MQTT password, a device access token, an Azure device key, an AWS secret key) in the link’s sealed store, never in a param (as history sync). Each upstream is a node<name>/{kind, url, status, error, enabled, connected_since, published, dropped, queued, last_publish}withedit,set_password,test_connection,remove;enabledis writable. Entries fromwyrmd.json5(uplink.upstreams) show withorigin: config, read-only but forset_password, assys/upstreamshows its config-file peers. Definitions live in the link’s store and come back after a restart; secrets with them. - What goes up: values, live. Each upstream names the keys it sends:
selectis a list of full node keys (wy/<site>/downstream/plc1,wy/<site>/storage); everything under each is sent as it changes, within the link’s grants. The link’s own subtree is never sent. Per pointmax_hz(0 = every change) keeps the latest value while the rate is over; a bounded queue per upstream (queue_max, default 10 000) drops the oldest when the platform is slower than the site and countsdropped. Delivery is live and at most once: the complement for completeness is a history sink (ADR 0026), which replays from the journal. - Formats, one engine. An MQTT 3.1.1 client of our own over the host’s TCP/TLS (CONNECT with username/password and a will, PUBLISH QoS 0 and 1 with a bounded window of unacknowledged packets, SUBSCRIBE, PINGREQ, a parser for CONNACK/PUBACK/SUBACK/PINGRESP/PUBLISH) serves four of the five platforms; AWS IoT Core goes over HTTPS.
mqtt(a UNS): topic<prefix>/<site>/<path>per point (the site’s name and the node path belowwy/<site>/), payload JSON{"v": …, "q": "<quality>", "t": <µs>}or the value alone (payload: value),retainon by default,qos0 or 1.sparkplug(Sparkplug B 3.0):spBv1.0/<group>/NBIRTH|NDATA|NDEATH/<edge node>andDBIRTH|DDATA|DDEATH/<device>; the edge node is the site (edge_node_id), a device is a link (downstream/<link>;dataflows,storageas devices of their own; another site’s link as<site>.<link>), a metric is the path below the device. Payloads encoded by a protobuf writer of ours (timestamp,metrics{name, timestamp, datatype, value},seq,bdSeq); numbers as Double, bools as Boolean, text as String;seq0..255;bdSeqfrom the store; NBIRTH on every connect with the metrics known so far, a DBIRTH again when a device gets a new metric; NDEATH as the will;Node Control/RebirthonNCMD(andDCMD) answered with a full rebirth.thingsboard: the gateway API over MQTT (username = the gateway’s access token):v1/gateway/connect {"device"}once per device per session,v1/gateway/telemetry {"<device>": [{"ts", "values": {<path>: v}}]}per flush; a device is a link, named<site>-<link>(device_prefixchanges the site part).azure: IoT Hub over MQTT with a SAS token from the device key (HMAC-SHA256,sr=<hub>/devices/<id>, renewed beforesas_ttl_sruns out by connecting again), username<hub>/<id>/?api-version=2021-04-12, topicdevices/<id>/messages/events/$.ct=application%2Fjson&$.ce=utf-8, payload a JSON array of{"key", "v", "q", "t"}per flush. X.509 devices wait for client certificates intls_connect.aws: IoT Core’s HTTPS publish (POST https://<endpoint>:8443/topics/<topic>?qos=1, Signature V4 foriotdatawith an access key id and the secret key from Set Password): one request per flush with a JSON array of samples to<topic>(default<prefix>/<site>). MQTT with mTLS waits for client certificates intls_connect.
- Flushing. One timer per upstream:
flush_ms(250 by default) while connected and anything is queued, a back-off (1 s ×2 up toretry_s) while it is not; a keep-alive ping at half the keep-alive. Each flush sends at most 64 KiB (the host’s bound per send) and reads what the platform sent back within the same event. A connection lost or a refused publish drops the connection, keeps the queue and connects again after the back-off; a refusal at CONNECT (bad credentials, not authorized) isfaileduntil Edit, Set Password or Resume. - Network. The embedded link’s
netcomes fromwyrmd.json5(uplink.net, ADR 0012 syntax:broker.example:8883, *.azure-devices.net:8883, 10.0.0.5:1883), as every portable link’s does: the app cannot widen it. An Add whose host no name or address entry covers is refused with the entry to add.
Consequences
- Amended 2026-11-05 (automated security review after the merge, decided under ADR 0029): an upstream keeps its author’s rights (
rights/<name>in the store,wyrm_link_api::Rights); Add and Edit refuse a token withoutauthand aselectoutside the caller’sread, and samples the author may not read are dropped, as DQL queries and alarm watches do. An Edit that moves the endpoint (host, port, TLS,insecure_plaintext,ca_pem) deletes the secret. - A site sends its live values to up to 16 platforms at once from one link, each with its own selection and rate; the same point may go to all of them.
- Values only. Meta (units, names) is not sent; a UNS consumer reads it from the broker or from the topic names. Sparkplug hosts get metric names and types.
- Live, at most once: a platform down for an hour misses that hour (the queue holds
queue_maxsamples, then drops the oldest). History sync (ADR 0026) is the path for complete data. - MQTT 3.1.1 only (no MQTT 5 properties); QoS 2 is not offered (Azure and AWS refuse it).
- No client certificates: AWS IoT Core goes over HTTPS, Azure needs SAS. A later world may add a client certificate to
tls_connect. - One more always-on in-process link with site-wide
read; nothing it does is a write. Off withuplink: {enabled: false}.
Alternatives
- A node under
sys/upstreamwith akind. An upstream broker is a peer with a CA, a certificate and an ACL subject; a platform upstream is a client with a secret. Mixing them would put platform clients into the admin actor (security review) and into the registry’s peer model. Refused; the root node is a link, as the scheduler and DQL are. - History sync targets for MQTT and the clouds. Complete and ordered, but seconds behind and only for watched points; a UNS needs the latest value as it changes. Both exist; a site uses either or both.
rumqttcor the AWS/Azure SDKs. Native crates would make the link process-only and pull in their own TLS and runtimes; the portable form needs a client over the host’s sockets, as history sync has for PostgreSQL and MongoDB.