Edge
Edge Agent driver protocol
The fpEdge1 protocol between an Edge Agent and the drivers that talk to its devices, carried over a local MQTT broker.
The driver protocol connects an Edge Agent to the drivers that talk to its devices.
The protocol divides an Edge Agent into two halves. The top half is the Edge Agent itself. It holds the configuration, decodes data into metrics, applies report by exception and speaks Sparkplug to the rest of Factory+. The bottom half is the driver. A driver talks to one southbound device or data source in that device’s own protocol and passes raw data up to the agent. The device protocol might be OPC UA, Modbus, MQTT, a REST API or another protocol.
The split exists so that adding a device protocol means writing a small program that only reads and writes addresses. That program can be written in any language. It does not touch Sparkplug, Factory+ identity or configuration management.
The two halves talk over MQTT on topics under fpEdge1, through a broker that the Edge Agent provides. A driver has no Factory+ identity and never connects to the central MQTT broker.
graph LR
Dev[Southbound device] -- "device protocol" --> Drv[Driver]
Drv -- "fpEdge1 over local MQTT" --> EA[Edge Agent]
EA -- "Sparkplug B" --> MQ[Factory+ MQTT broker]
The key words MUST, SHOULD and MAY follow RFC 2119, as described on the service specification page. Paragraphs marked Non-normative describe what the reference Edge Agent, acs-edge, does. They are there because drivers are tested against acs-edge. Another Edge Agent MAY behave differently in those respects.
Summary for driver authors
| Part | A driver MUST | Notes |
|---|---|---|
status | Publish READY, then UP or an error status, with a will of DOWN. | |
active | Publish its current status on ONLINE. | Acting on OFFLINE is optional. |
conf | Accept the driver configuration as JSON. | |
addr | Keep the map from data topic names to addresses. | groups MAY be ignored. |
poll | Read the listed addresses and publish their data. | A push-only driver MAY ignore it. |
data | Publish one packet per address on data/<data topic>. | See data packet formats. |
cmd | Optional. Write the raw payload bytes to the address. | Subscribe to cmd or write, never both. |
write and result | Optional. Write a typed value and answer the write. | See typed writes. |
err | Optional. Report a failed write or an address problem. | |
req and rsp | Optional. Ask the agent to fetch something. | Only the kinds the agent serves. |
scout and found | Optional. List the device’s addresses and read live values. | Only after the agent advertises the feature. See device discovery. |
Terms
Connection name. The name that identifies a driver to its Edge Agent. It MUST be a short string of letters, digits and underscores. The Edge Agent configuration sets it from the connection’s driverId, or from its name when there is no driverId. The driver receives it when it is deployed.
Address. A string in a driver-specific format that names one data source within the driver’s device, such as an OPC UA node id or a Modbus register range. Reading an address gives a data packet. Address strings come from the Edge Agent configuration and reach the driver unchanged. Only the driver interprets them.
Data packet. The binary result of reading an address, or of the address pushing data to the driver. The Edge Agent MAY parse several metrics out of one packet.
Data topic name. A short name that the Edge Agent assigns to each address it is using. Addresses can be long and can contain characters that cannot go in an MQTT topic level. A data topic name MUST be a string of letters, digits and underscores. A given address MUST NOT have more than one data topic name in one address configuration. Data topic names are not stable across agent restarts, so a driver MUST NOT store them.
Address group. A named set of data topic names with a requested poll interval. One address MAY appear in more than one group.
Address configuration. The JSON document that tells a driver which addresses are in use and gives their data topic names. It arrives on addr.
Driver configuration. The driver-specific JSON configuration, such as host names, ports and credentials. The Edge Agent configuration holds it as the connection’s DriverDetails, and the agent passes it to the driver on conf.
Asynchronous address. An address whose data arrives without the driver asking for it. Some addresses are only asynchronous. The driver cannot read them on request and must wait for their data. Drivers are not expected to cache data or poll on a timer.
Connection and authentication
The Edge Agent provides an MQTT 3.1.1 broker with username and password authentication. The driver is an MQTT client. It MUST connect with its connection name as both the MQTT username and the client id. Its password is supplied by its deployment. If a driver runs outside the Edge Agent’s host, the broker port must be reachable from where the driver runs.
A driver that runs as a standalone program SHOULD take its settings from these environment variables:
| Variable | Meaning |
|---|---|
EDGE_MQTT | URL of the Edge Agent’s broker |
EDGE_USERNAME | The driver’s connection name |
EDGE_PASSWORD | The driver’s MQTT password |
A driver MUST accept mqtt:// URLs, with the port defaulting to 1883. A driver MAY accept mqtts://, ws:// and wss://.
The driver MUST include a will in its CONNECT packet that publishes DOWN to its status topic. The will tells the agent when the driver disappears.
Quality of service and retained messages
QoS 0 is enough for this protocol. Nothing in it relies on a higher QoS. A driver MAY publish and subscribe entirely at QoS 0. A driver that wants a higher QoS SHOULD:
- set up its subscriptions and wait for the SUBACKs before it publishes anything,
- subscribe at QoS 2, so the agent can choose the QoS, and
- use the QoS granted for
conf, or the QoS of the most recent packet received onconf, for all its own publishes.
The Edge Agent MAY downgrade a subscription in its SUBACK. It MAY also publish at a lower QoS.
Packets MUST NOT be published with the RETAIN flag. The broker MUST NOT allow retained messages.
Topics
Every topic is under fpEdge1/<Conn>/, where <Conn> is the driver’s connection name. In the examples below the connection name is Conn and a data topic name is Data.
| Topic | Published by | Purpose |
|---|---|---|
fpEdge1/Conn/status | driver | The state of the driver’s southbound connection |
fpEdge1/Conn/active | agent | Whether the agent wants the driver to be active |
fpEdge1/Conn/conf | agent | The driver configuration |
fpEdge1/Conn/addr | agent | The address configuration |
fpEdge1/Conn/poll | agent | A request to read some addresses |
fpEdge1/Conn/data/Data | driver | A data packet for one address |
fpEdge1/Conn/cmd/<address> | agent | A write, as raw bytes |
fpEdge1/Conn/write/<address> | agent | A write, as typed JSON |
fpEdge1/Conn/result/<id> | driver | The answer to a typed write |
fpEdge1/Conn/err/Data | driver | An error for one address |
fpEdge1/Conn/req/<kind> | driver | A request for the agent to fetch something |
fpEdge1/Conn/rsp/<kind> | agent | The answer to a request |
fpEdge1/Conn/scout | agent | Discovery requests (see device discovery) |
fpEdge1/Conn/found/<id> | driver | Discovery answers |
The Edge Agent SHOULD refuse publishes and subscriptions outside a driver’s own topics. A driver’s allowed topics are listed below, where \w means a letter, digit or underscore.
| Direction | Topics under fpEdge1/<Conn>/ |
|---|---|
| Driver publishes | status, data/\w+, err/\w+, req/\w+, result/\w+, found/\w+ |
| Driver subscribes | active, conf, addr, cmd/#, write/#, poll, rsp/\w+, scout |
An agent that enforces this list may drop the whole connection of a driver that publishes or subscribes to anything else. A driver therefore MUST NOT use a topic its agent may not allow. This is why new topics are only ever added behind a feature.
Status lifecycle
A driver reports the state of its southbound connection on status. Each message MUST be one of these strings:
| Status | Meaning |
|---|---|
DOWN | The driver is not connected or not running |
READY | The driver is waiting for configuration |
UP | The southbound connection is up and working |
CONF | There is a problem with the driver configuration |
CONN | The driver cannot connect, for example because a host name does not resolve or the device refuses the connection |
AUTH | The driver has connected but cannot authenticate with the credentials in its configuration |
ERR | Some other error, such as a protocol error on the southbound connection |
The driver MUST publish READY as soon as it has connected to the broker and set up its subscriptions. The exception is a driver that has resumed an MQTT session and already has its configuration. A driver MUST NOT publish data while its most recent status is anything other than UP.
The Edge Agent ties each device’s Sparkplug state to this status. A device’s birth and death therefore show whether its data is flowing.
- On
READY, the agent MUST publishconfand thenaddr. - On
UP, the agent publishes a DBIRTH for each of the connection’s devices. - On a move from
UPtoDOWN,CONF,CONN,AUTHorERR, the agent publishes a DDEATH for each of them.
sequenceDiagram
participant D as Driver
participant A as Edge Agent
participant S as Sparkplug
D->>A: CONNECT (will: status DOWN)
D->>A: SUBSCRIBE to its agent topics
A->>D: active ONLINE
D->>A: status READY
A->>D: conf (driver configuration)
A->>D: addr (address configuration)
D->>A: status UP
A->>S: DBIRTH for each device
loop every polling interval
A->>D: poll
D->>A: data/Data
A->>S: DDATA (changed values)
end
D->>A: status CONN
A->>S: DDEATH for each device
Messages from the Edge Agent
active
Every message is the string ONLINE or OFFLINE. It says whether the Edge Agent expects this driver to be active. On ONLINE, the driver MUST publish its current status. On OFFLINE, the driver SHOULD discard its configuration, go back to READY and disconnect from its data sources if it can.
conf
The driver configuration, as JSON. The Edge Agent MUST publish it whenever the driver publishes READY. The Edge Agent MAY publish a new one at any time. A new configuration replaces the driver’s old one.
addr
The address configuration, as a JSON object:
| Key | Type | Meaning |
|---|---|---|
version | integer | 1. |
addrs | object | Keys are data topic names and values are addresses. |
groups | object | Optional. Keys are group names and values are objects with addrs (an array of data topic names from addrs) and poll (the requested poll interval in milliseconds). |
features | object | Optional. The optional parts of the protocol this Edge Agent serves, each with an integer version. See features. |
{
"version": 1,
"addrs": { "48211": "ns=2;s=Line1.Speed", "48212": "ns=2;s=Line1.Temp" },
"groups": { "Line1_Spindle": { "addrs": ["48211", "48212"], "poll": 1000 } },
"features": { "scout": 1 }
}
The Edge Agent MUST republish the address configuration every time it publishes a driver configuration. It MAY publish a new one at any time. It MUST NOT assume that a driver reacts to a new address configuration at once. It MUST manage data topic names so that a late reaction causes no confusion. It MUST NOT add keys except under an updated version of this specification.
A driver MUST record the address configuration. It MAY use the configuration to set up its southbound connection. If a driver receives a version it does not recognise, it MUST set its status to CONF. A driver MUST ignore keys it does not recognise.
A driver SHOULD honour a group’s poll interval only if its device offers a way to poll a set of addresses. If a driver is polling, it SHOULD provide new values for all the addresses in a group in quick succession. If data does not arrive in time, the Edge Agent MUST poll explicitly. The Edge Agent MUST assume that a reported value stands until a new one is reported.
The schema urn:edge-scout:addr in the schema package checks this message.
poll
A request to read addresses. The payload is a list of data topic names from the current address configuration, separated by single newline characters.
The driver MUST try to read each listed address and publish a data packet as soon as it can. If reading an address fails, the driver MUST report an address error or a status error. If an address cannot be read on request because its data source is entirely asynchronous, the driver MUST ignore that address.
A driver SHOULD NOT poll on a timer of its own. The Edge Agent owns the poll timer.
Data
data
The driver MUST publish to fpEdge1/Conn/data/<Data> whenever it has a new data packet for an address in the current address configuration. Each message carries one packet. The driver need not avoid sending duplicate packets, because the Edge Agent applies report by exception. The driver MAY publish asynchronously when its data source pushes data.
Data packet formats
The driver and the connection’s payload format in the Edge Agent configuration agree the format of a data packet. The Edge Agent decodes a packet with the connection’s payloadFormat and each metric’s path, as described in the Edge Agent configuration. There are two kinds of driver.
Pass-through drivers. Some drivers receive southbound data that is already a byte payload, such as an MQTT message or an HTTP response body. A pass-through driver publishes those bytes unchanged. The connection’s payload format and the metric paths then pick values out of it. The payload format might be JSON, XML, Delimited String, Buffer or another format.
Decoded-value drivers. Some drivers use a southbound library that hands them typed values, such as an OPC UA client. A decoded-value driver publishes one JSON object per address:
{"value": 21.5, "timestamp": 1763380800123}
| Key | Meaning |
|---|---|
value | The value. A null value is ignored, so the metric keeps its last value. Numbers MAY be sent as strings, which are parsed for the metric’s type. |
timestamp | Optional. The source timestamp in milliseconds since the epoch. A value in seconds is converted to milliseconds. |
timestampNs | Optional. The source timestamp in nanoseconds since the epoch, as a string of digits. It takes precedence over timestamp. |
The connection uses payload format JSON with an empty path on each metric. The agent then takes value and the timestamp from the packet. A value with no timestamp is stamped with the time the agent received its packet.
Each Sparkplug type is carried in value as follows:
| Sparkplug type | value | Notes |
|---|---|---|
| Int8, Int16, Int32, UInt8, UInt16, UInt32 | number | Exact |
| Int64, UInt64 | number | Exact up to 2^53 |
| Float | number | Rounded to 32 bits by Sparkplug |
| Double | number | NaN and infinities cannot be sent, because JSON has no form for them |
| Boolean | true or false | Exact |
| String, Text | string | An empty string is published as null |
| DateTime | milliseconds since the epoch, or an ISO 8601 string | Exact to the millisecond |
Values held in 16-bit registers
Some devices hold Modbus-style registers in an array of 16-bit integers. They store a 32-bit or 64-bit value across several registers. A decoded-value driver MAY send such an address’s value as a JSON array of registers. An Edge Agent that supports this reads a numeric metric from the array as follows:
| Metric type | Registers | Order |
|---|---|---|
| Int16, UInt16 | 1 | none |
| Int32, UInt32, Float | 2 | With the BE suffix the first register is the most significant. With LE, or no suffix, the first is the least significant. |
| Int64, UInt64, Double | 4 | As above |
A register MAY be sent signed or unsigned, so -1 and 65535 are the same register. If an array has the wrong length, or holds something that is not a 16-bit integer, the metric gets no value. A String metric given an array or object gets no value either.
Gathering data
Each data packet carries one address. A device often reports many addresses together, for example in one OPC UA notification or in the results of one poll. An Edge Agent MAY gather data packets that arrive close together and publish the values that belong to each device as one DDATA. This keeps Sparkplug traffic low. Gathering MUST NOT change a value’s timestamp. Gathering MUST keep values for the same address in the order the driver sent them.
To help, a driver SHOULD publish values it receives together back to back. A driver SHOULD set TCP_NODELAY on its connection to the agent, so that later packets of a burst are not held back.
Writes
The Edge Agent writes to a device in answer to a DCMD. It publishes every write in two forms: on cmd as raw bytes and on write as typed JSON. The agent therefore does not need to know which form a driver uses. A driver subscribes to fpEdge1/Conn/cmd/# or to fpEdge1/Conn/write/#. A driver MUST NOT subscribe to both, because it would then write each value twice. A driver MAY refuse to write to its device at all.
In both forms the address is everything in the topic after cmd/ or write/. An address MAY contain /, so a driver MUST NOT take only the next topic level. For example, a write to the address plant/line1/speed arrives on fpEdge1/Conn/cmd/plant/line1/speed.
An MQTT topic cannot contain +, # or NUL. The Edge Agent MUST NOT write to an address that contains any of them. The Edge Agent MUST only write to addresses in the current address configuration. It publishes one message per metric written, so two metrics on the same address give two messages.
cmd
The payload is the new value as raw bytes for the metric’s Sparkplug type:
- integers and floats at their natural width, in the metric’s byte order,
- Boolean as one byte, 0 or 1,
- String, Text and UUID as UTF-8.
The byte order is big-endian unless the metric’s type has the LE suffix. Int64 and UInt64 are 8 bytes. Other types, including DateTime, have no cmd form. The agent sends no cmd for them, or for a value that does not fit its type.
The driver SHOULD write the data to its device at the given address. If it cannot or will not, it SHOULD report an RO address error. A driver that only takes cmd cannot tell the agent whether a write succeeded. The agent therefore reports the new value as soon as it has published the write.
Typed writes
A cmd payload does not say whether its bytes are an Int16, a Float or a String. Some southbound protocols need to know. A driver that needs the type subscribes to write/# instead of cmd/#. The payload is a JSON object:
{"type": "Int16", "value": -2, "id": "9f3a1c02_7"}
type is the metric’s Sparkplug type, with no byte order. value is written as follows:
| Sparkplug type | value |
|---|---|
| Boolean | true or false |
| Int8, Int16, Int32, UInt8, UInt16, UInt32 | a number, an integer in range for the type |
| Int64, UInt64 | a string of decimal digits, such as "-9223372036854775808", so no digits are lost |
| Float, Double | a number, or the string "NaN", "Infinity" or "-Infinity" |
| String, Text, UUID | a string |
| DateTime | a number of milliseconds since the epoch |
Other types are not sent. These are Bytes, File, DataSet, Template and the property sets. A driver MUST ignore keys it does not recognise.
id is optional. It is a string of letters, digits and underscores. If a write has an id, the Edge Agent is waiting for an answer, and the driver MUST answer as described below. If a write has no id, the driver does not answer, and SHOULD report a failure on err.
result
A driver that subscribes to write/# MUST answer every write that has an id exactly once. It answers by publishing to fpEdge1/Conn/result/<id> either:
- an empty payload once the value has been written, or
- an error code (
RO,CMDorERR, as forerr), optionally followed by a newline and a message, if it was not.
If a driver cannot use a write, it answers CMD straight away and does not also report it on err. A write the driver cannot use has an address that is not in its address configuration, or a bad payload.
The Edge Agent MUST report the written value in DDATA only when the answer says it was written. The value then carries the time of the answer. A refusal, or no answer in time, MUST leave the old value in place. Several writes MAY be in flight at once, each with its own id. The Edge Agent ignores an answer to an id it is not waiting for. It SHOULD make its ids unique across its own restarts, so that a late answer cannot match a new write.
Errors
err
The driver publishes to fpEdge1/Conn/err/<Data> to report a problem with one address. The payload is an error code, optionally followed by a newline and a message, such as RO or CMD\nBadTypeMismatch.
| Code | Meaning |
|---|---|
CONN | Connection problem |
AUTH | Authentication or authorisation problem |
RO | The Edge Agent tried to write a read-only address |
WO | The Edge Agent tried to poll a write-only address |
CMD | The driver can write to the address, but the value it was sent is not suitable |
ERR | Some other error |
Failed writes. If a driver fails a cmd, or a typed write without an id, it SHOULD publish RO, CMD or ERR on the error topic of that address’s data topic. A write error reports that one write only. The driver does not clear it. It does not stop data for the address.
Failed reads. If a driver has a problem reading an address in the current address configuration, it SHOULD publish an error code on that address’s error topic. It SHOULD NOT publish data for the address while the error stands. When it can read the address again, it SHOULD clear the error by publishing an empty message. Publishing UP on status clears all address errors. A problem that probably affects the whole device SHOULD be reported on status instead.
Requests
A driver has no Factory+ identity. When it needs something from Factory+, it asks its Edge Agent to fetch it. The driver publishes a request to fpEdge1/Conn/req/<kind>. The agent answers on fpEdge1/Conn/rsp/<kind> with a JSON object. The driver MUST subscribe to rsp/<kind> itself before it sends the request.
The Edge Agent implementation defines the kinds of request and their payloads. An agent MUST answer a kind it does not serve with:
{"error": "Unknown request: <kind>"}
Because a request is served with the agent’s own identity, an agent SHOULD only serve kinds that fetch specific, named things, such as one object by UUID, rather than act as a general-purpose proxy.
Features and extending the protocol
Optional parts of the protocol are switched on by features. The Edge Agent lists the features it serves in the features key of each address configuration, each with an integer version. The only feature defined today is scout, version 1. It is device discovery.
A new topic is only ever added to the protocol together with a feature. A driver uses that topic only after the agent has advertised the feature on the current MQTT session. A driver MUST forget the features it has seen whenever it connects to the broker. As a result, a new driver never subscribes to or publishes on a topic that an older agent’s topic list would refuse. This holds after the agent is rolled back to an older release too.
A driver MUST use a feature only at a version it recognises.
Compatibility
| Edge Agent | Driver | Result |
|---|---|---|
| Serves typed writes | Subscribes to cmd/# | The driver gets raw writes and the agent reports each value at once. |
| Serves typed writes | Subscribes to write/# | The driver gets typed writes and answers each one that has an id. |
Does not allow write/# | Subscribes to write/# | The agent refuses the subscription and may drop the driver. Such a driver needs an agent that serves typed writes. |
Does not advertise scout | Supports discovery | The driver never subscribes to scout, and nothing changes. |
Advertises scout | Does not support discovery | The driver never subscribes, and discovery requests fail with LIBRARY. |
Schemas
The lib/edge-scout-schemas package in the reference implementation holds JSON Schemas for the address configuration and for every device discovery message. The schemas use draft 2020-12. Their $id values have the form urn:edge-scout:<name>. The package also holds test fixtures that every implementation checks against.
Reference libraries
Three open-source libraries implement the driver side of this protocol. A driver built on one only has to read and write its device.
| Language | Library | Writes | Discovery |
|---|---|---|---|
| JavaScript | @amrc-factoryplus/edge-driver (lib/js-edge-driver) | cmd and typed writes | Yes |
| Python | amrc.factoryplus.edge_driver (lib/py-edge-driver) | cmd only | Yes |
| Rust | rs-edge-driver (lib/rs-edge-driver) | cmd and typed writes | Yes |
Each library handles the connection, the status lifecycle, the address map, polling, write answers and the discovery protocol. It calls the driver’s code to parse addresses, read them, write them and list them.
ACS implementationJavaScript driver librarySee how the AMRC Connectivity Stack implements this.View on GitHub ACS implementationPython driver librarySee how the AMRC Connectivity Stack implements this.View on GitHub ACS implementationRust driver librarySee how the AMRC Connectivity Stack implements this.View on GitHub