# MQTT input quality and limits

> The quality codes and labels of eaxPLC's MQTT and Sparkplug B inputs (network I/O, not for safety functions), the quality outputs the program reads, the on_bad choices, the source counters, and the limits and ranges of an MQTT bus.

Product: eaxPLC · Type: Reference · Editions: Pro
Source: https://eaxware.com/docs/eaxplc/reference/mqtt-input-quality/
Verified against commit f67e38d.

MQTT inputs are network I/O, not for safety functions. This page lists what
the program sees of each entry. How to set up a bus, its sources and entries
is in [Connect MQTT and Sparkplug B inputs](/docs/eaxplc/how-to/connect-mqtt-sparkplug-inputs/).

## Quality codes

The codes are OPC quality codes, as everywhere in eaxware. The label is the
text the IDE and `GET /api/fieldbus` show.

| Code | Label | When |
|---|---|---|
| 192 (and 192 to 255 from the source) | Good | A value accepted from a live source. |
| 64 to 127 | Uncertain | The source says Uncertain; a Sparkplug B sequence gap (until the next NBIRTH); a retained JSON value not proven recent; a timestamp more than 5 s in the future; a JSON `quality` that is not an integer. |
| 68 | Stale | No update within `max_age_ms` (decided in the scan), or an update whose own timestamp was older than `max_source_age_ms` on arrival. |
| 24 | Bad (comm failure) | The connection to the broker is lost, NDEATH, DDEATH, or the JSON online topic is false. |
| 8 | Bad (not connected) | No value yet, no birth (or the birth does not name the metric), bus off, stopped or not started, or a simulated PLC. |
| 4 | Bad (config error) | A value that does not convert exactly, a malformed payload, or a source that says it is simulated. |
| 0 to 63, other | Bad | A Bad code the source sent. |

A code is Good when its two top bits are set (192 to 255). **Uncertain and
Stale are never Good.**

## Downstream quality (UNS, MQTT publisher, OPC UA)

A variable wholly inside an MQTT entry's value is served with the worse of
the PLC's quality (Good while the scan runs, Uncertain while it is stopped)
and the entry's code. The NATS UNS and the MQTT publisher send that code
(JSON `quality`, Sparkplug B `Quality` property). The OPC UA server gives it
as the value's status:

| Code | OPC UA status |
|---|---|
| 192 to 255 | `Good` |
| 68 (Stale) | `UncertainLastUsableValue` |
| 64 to 127, other than 68 | `Uncertain` |
| 24 (comm failure) | `BadCommunicationError` |
| 8 (not connected) | `BadNotConnected` |
| 4 (config error) | `BadConfigurationError` |
| any other code | `Bad` |

When only the entry's quality changes (its value does not), the UNS and the
MQTT publisher republish the variable, and the OPC UA server notifies its
subscriptions; the OPC UA server looks for such a change every 250 ms.
Variables no MQTT entry drives keep the PLC's quality.

### OPC UA Read: value and status from the same cycle

An OPC UA Read of many variables is served from one copy of the process
image, shared by the reads of the last 20 ms. The scan writes an MQTT
input's value and decides its quality in the same cycle, so the value and
the status a Read returns must come from the same cycle:

- the image copy is reused only while no input's quality has changed since
  it was taken; after a change, the next Read takes a fresh copy;
- a quality that changes while a Read is being served is read again with a
  new copy; after 3 tries, the worst quality seen is served;
- an entry's quality generation changes before its new quality is stored,
  so a Read never pairs the new quality with a copy from before the change.

Before, a Read within 20 ms of an earlier one could return an input's last
Bad value with `Good` status, just after the input turned Good. A Read now
costs a fresh image copy whenever an input's quality changed since the last
copy.

## Quality outputs

Each entry needs a quality signal: its quality bit, or its source's status
bit. The other outputs are optional. All are in `%I`.

| Output | Address | Value |
|---|---|---|
| `quality_address` | `%IX` | TRUE only while the code is Good. |
| `status_address` | `%IB` | The quality code (USINT). |
| `timestamp_address` | `%IL` | The source's timestamp, Unix ms (LINT). The receive time when the source sent none. |
| `age_address` | `%ID` | ms since the last accepted update (UDINT); 4 294 967 295 before the first value. |
| Source `status_address` | `%IX` | TRUE while the source is alive: connected and, for Sparkplug B, after its birth and before its death; for JSON with an online topic, after the topic said true and until it says false. |

## What the value shows when it is not Good

| `on_bad` | Value |
|---|---|
| `hold` (default) | The last accepted value. Before any value: the substitute, or 0 without one. |
| `substitute` | The `substitute` literal of the entry's type (required). |
| `zero` | 0. |

Before the first value, every entry has code 8 and shows its substitute
(0 with `zero` or without a substitute).
An entry's `on_bad` defaults to its source's, which defaults to `hold`.

## Staleness

`max_age_ms` is checked in the scan, on the monotonic receive time: a Good
value older than that turns Stale (68) even if the network side has stopped.
An entry's own `max_age_ms` overrides its source's; 0 turns the check off.
On a JSON source, `max_age_ms` (on the source or on every entry) or an
`online_topic` is required. On a Sparkplug B source the default is 0.

## Source counters

`GET /api/fieldbus` shows, per MQTT source, whether it is connected and
alive, `seq_gap` and `no_bdseq`, each entry's code, label, value and age,
and these counters. They are not
exported as Prometheus metrics.

| Counter | Counts |
|---|---|
| `received` | Messages on the source's topics. |
| `accepted` | Values accepted. |
| `dropped_rate`, `dropped_size` | Messages dropped by a rate limit, or by the payload or metric limit. |
| `malformed` | Payloads that could not be decoded. |
| `historical`, `retained` | Historical Sparkplug metrics ignored; retained messages (Sparkplug: ignored; JSON: taken as Uncertain). |
| `conversion` | Values refused because they do not convert exactly. |
| `seq_gaps` | Sparkplug B sequence gaps or repeats. |
| `births`, `deaths` | Births and deaths applied. |
| `old_deaths` | NDEATH messages ignored because their `bdSeq` differs from the birth's. |
| `births_without_bdseq` | NBIRTH messages without `bdSeq`. |
| `clock_skew` | Timestamps more than 5 s in the future. |
| `unknown_alias` | Metrics with an alias the last birth did not define. |
| `simulated` | Values refused from a source that says it is simulated. |
| `rebirth_requests` | Rebirth requests sent. |

Per bus: `bus_dropped_rate` (over the bus limit) and `bus_unmapped_topics`
(messages on a topic no source maps).

## Limits

| Setting | Default | Range |
|---|---|---|
| `keepalive_sec` | 5 | 2 to 60 |
| `bus_max_msgs_per_sec` (whole bus) | 10 000 | 1 to 1 000 000 |
| `max_msgs_per_sec` (per source) | 1000 | 1 to 100 000 |
| `max_payload_bytes` | 262 144 (256 KiB) | 1024 to 4 194 304 (4 MiB) |
| `max_metrics` (per Sparkplug B payload) | 10 000 | 1 to 100 000 |
| `max_age_ms`, `max_source_age_ms` | 0 (off) | 0 to 86 400 000 |
| `client_id` | `eaxPLC-<plc id>-in` (at most 23 characters) | at most 128 characters, no `/`, `+`, `#` |
| `plaintext_reason` | | at least 8 characters |

- **Rates** are token buckets that allow a burst of twice the rate. The
  source's limit is checked before the bus's. Sparkplug B NBIRTH, NDEATH,
  DBIRTH and DDEATH are never dropped for rate; the size limits apply to
  every message.
- **Rebirth requests**: at most one per node every 30 s.
- **Clock skew**: a timestamp more than 5 s ahead of the PLC's clock is
  accepted as Uncertain.
- **Test connection** times out after 15 s. **Browse** listens 5 s by
  default (`wait_ms`, 500 to 9000 ms), connection included, and lists at
  most 5000 metrics or topics.

## Routes

| Route | Role | Does |
|---|---|---|
| `PUT /api/fieldbus` | engineer, e-signed | Saves and applies the configuration; secrets in `secrets` and `clear_secrets`, write-only. `422 SAFETY_TARGET` when an entry covers a safety target. |
| `POST /api/fieldbus/validate` | engineer | Checks a configuration; nothing is applied. |
| `POST /api/fieldbus/mqtt/test` | engineer | Connects once with a bus's settings and disconnects. |
| `POST /api/fieldbus/mqtt/browse` | engineer | Listens for a source's births or topics; nothing is sent. |

The AI co-pilot is refused on all of them, and a simulated PLC answers `409`
on test and browse. All routes: [Runtime HTTP API](/docs/eaxplc/reference/generated/http-api-runtime/).
