Edge
Device discovery
The optional part of the driver protocol that lets a driver list the addresses its device offers and read their current values.
Device discovery lets a driver list the addresses its device offers and read their current values.
Mapping a device into Factory+ pairs each metric in the device’s schema with an address on the device, such as an OPC UA node id or an MQTT topic. Typing those addresses by hand is slow and error-prone, and the device usually knows what it offers. With discovery, an Edge Agent asks a running driver to scan its device and list the addresses it finds, and a person or a tool picks addresses from that list instead. The agent can also read the current values of chosen addresses, and a person can use them to check that they picked the right one.
Discovery is an optional part of the driver protocol, switched on by the scout feature. The Edge Agent can tell three kinds of driver apart: one that supports discovery, one that says it cannot scan, and one built before discovery existed. Whoever asked for a scan can therefore always be told why one is not available. A scan only reads from the device and never changes it, and a driver keeps collecting data while it scans.
The key words MUST, SHOULD and MAY follow RFC 2119, as described on the service specification page. Paragraphs marked Non-normative describe the reference Edge Agent, acs-edge.
Scope
Discovery is specified as the messages between an Edge Agent and a driver. How a person or service asks an Edge Agent to run a scan is up to the implementation. So is what the agent does with the results, such as storing them, showing them or comparing them with earlier scans. The In ACS note at the end describes how the reference implementation does it.
A scan belongs to a connection, not to a device, because the driver discovers what is on its southbound side. Every device on a connection sees the same results.
The feature gate
The Edge Agent advertises discovery by putting "features": {"scout": 1} in every address configuration it publishes on addr. The address configuration’s version stays 1, because drivers already ignore keys they do not recognise.
A driver that takes part in discovery:
- MUST read
featuresbefore anything else in an address configuration, before it checksversion, its handler or its addresses. A driver with a bad configuration or a bad address can then still answer that it cannot scan, and it does not look like a driver built before discovery existed. - MUST subscribe to
fpEdge1/<Conn>/scoutwhen it seesfeatures.scoutwith a version it recognises, and only then. It subscribes at most once per MQTT session. - MUST forget that it saw the feature whenever it connects to the broker.
- MUST NOT subscribe to
scoutwhen it connects. - MUST NOT publish on
found/<id>unless it has subscribed toscouton the current session.
These rules matter because an Edge Agent may drop the whole connection of a driver that uses a topic it does not allow. If an Edge Agent is rolled back to a release without discovery, its address configuration has no features key. A newer driver then never asks for the scout topic and keeps working.
The only version of the scout feature is 1. A breaking change would raise it to 2, and a driver takes part only when it recognises the version.
Topics and messages
| Topic | Published by | Messages |
|---|---|---|
fpEdge1/<Conn>/scout | Edge Agent | hello, start, ack, cancel, read |
fpEdge1/<Conn>/found/<id> | driver | hello, accept, items, progress, end, values |
<id> in a found topic is hello for the answer to a hello. Otherwise it is the id of the scan or read the message belongs to.
Every message is UTF-8 JSON, published at QoS 0 and never retained. A reader MUST ignore keys it does not recognise. Messages from the Edge Agent have an op key. Messages from the driver have seq and type keys.
seq is 0 for the first message on a found/<id> topic and goes up by 1 for each message after it. A gap in seq tells the Edge Agent that a message has been lost. A hello answer and a values answer always have seq 0.
sequenceDiagram
participant A as Edge Agent
participant D as Driver
A->>D: addr with features.scout = 1
D->>A: SUBSCRIBE scout
A->>D: scout: hello
D->>A: found/hello: hello (supported, reads)
Note over A: later, when a scan is requested
A->>D: scout: start (id, root, options, limits, window)
D->>A: found/id: accept
D->>A: found/id: items
A->>D: scout: ack
D->>A: found/id: progress
D->>A: found/id: items
A->>D: scout: ack
D->>A: found/id: end
Messages from the Edge Agent
hello
{"op": "hello", "version": 1}
Asks whether the driver can scan. The Edge Agent sends it when it sees the driver subscribe to scout.
start
{"op": "start", "id": "3f9c1a2b44e04d0c9a7e5b1f2c3d4e5f", "version": 1,
"root": null, "folder_id": null, "options": {},
"limits": {"items": 20000, "depth": 8, "seconds": 120, "pace_ms": 20, "samples": false},
"window": 4}
Starts a scan.
| Key | Meaning |
|---|---|
id | The scan id. It is 1 to 64 letters, digits and underscores, and is never hello. |
version | 1. |
root | Where to start, in the driver’s own terms, or null for the device’s natural top. At most 1024 characters. |
folder_id | For a branch scan, the id of the folder this scan replaces. Otherwise null. At most 1024 characters. It is set only together with root. |
options | Driver-specific options, at most 8 KiB as JSON. The driver validates them. |
limits | The caps the driver MUST keep to. All five are always present. |
window | Optional. The most items messages the driver may send ahead of the agent’s acks, from 1 to 64. |
The limits are:
| Limit | Meaning | Maximum |
|---|---|---|
items | The most items in the scan | 50,000 |
depth | The most levels below the root | 32 |
seconds | The longest the scan may run | 600 |
pace_ms | The pause between two southbound requests, in milliseconds | none (minimum 0) |
samples | Whether to read each value’s current value into its sample |
The Edge Agent MUST clamp the limits to these maximums before it sends them.
ack
{"op": "ack", "id": "3f9c1a2b44e04d0c9a7e5b1f2c3d4e5f", "seq": 12}
Says the Edge Agent has handled every message of the scan up to and including seq. The agent sends acks only to a driver whose accept repeated the window. A driver ignores an ack for a scan it is not running.
cancel
{"op": "cancel", "id": "3f9c1a2b44e04d0c9a7e5b1f2c3d4e5f"}
Stops the scan with that id.
read
{"op": "read", "id": "9d1e7c0a5b3f4e2d8c6a1b0f9e8d7c6b", "version": 1,
"addresses": ["ns=2;s=Line1.Speed", "plant/line1/temp"]}
Asks for the current values of some addresses, as described under reading values. id follows the rule for a scan id. The agent makes a new one for each read. addresses holds 1 to 40 unique addresses in the driver’s canonical form. Each address is at most 1024 characters.
Messages from the driver
hello
{"seq": 0, "type": "hello", "versions": [1], "supported": true, "reads": true,
"library": "rs-edge-driver 0.1.0"}
Published on found/hello in answer to a hello.
| Key | Meaning |
|---|---|
versions | The versions of this protocol the driver speaks. At least one. |
supported | Whether the driver can scan. It MUST come from the driver’s code, not its current state. A driver whose configuration failed then still answers correctly. |
reads | Whether the driver answers read. It also comes from the driver’s code. A hello without reads means false. |
library | Optional. The name and version of the driver library, at most 128 characters. |
accept
{"seq": 0, "type": "accept", "window": 4}
The first answer to a start. The driver sends it before it touches its device. A driver that keeps to the start’s window repeats it here. A driver that leaves window out gets no acks and is not flow-controlled.
items
{"seq": 1, "type": "items", "items": [ITEM, ...]}
Carries 1 to 500 items. The message is at most 256 KiB in all.
progress
{"seq": 2, "type": "progress", "visited": 3400, "found": 1200, "note": "ns=2;s=Line1"}
Reports counts while the scan runs. A driver MUST send one at least every 5 seconds. note is optional. It says in a few words where the scan has got to.
end
{"seq": 9, "type": "end", "exhaustive": true, "truncated": false, "reason": null,
"excluded": [{"id": "i=2253", "reason": "skipped", "prefixes": ["i="]}]}
{"seq": 0, "type": "end", "error": {"code": "OPTIONS", "message": "Root ns=2;s=Nope does not exist"}}
The last message of every scan, sent exactly once. It has either the result keys or error, never both.
| Key | Meaning |
|---|---|
exhaustive | True when the driver’s discovery is complete by nature within its caps. An OPC UA browse is exhaustive. Listening to an MQTT broker never is, because a quiet topic is missing from the results but may still exist. |
truncated | True when a cap stopped the scan. A truncated scan is not an error. |
reason | When truncated is true, one of items, depth, seconds, size or partial_access. Otherwise null. |
excluded | Optional. Up to 8 parts of the device that the scan did not visit on purpose, such as an OPC UA server’s own Server object. Each has an id of at most 256 characters, a reason such as skipped of at most 32 characters, and up to 4 prefixes. The prefixes are canonical address prefixes that fall inside the part. A consumer uses them to avoid calling an address under an excluded part “missing”. |
error | An object with a code from the driver codes and an optional message. It replaces the keys above. |
A scan that ends at once, such as one refused with OPTIONS, MAY send end with seq 0 and no accept. Cancellation is never a truncation. A cancelled scan ends with the error CANCELLED.
values
{"seq": 0, "type": "values", "values": [
{"address": "ns=2;s=Line1.Speed", "value": "1450.5", "type": "Double", "ts": 1795600000000, "error": null},
{"address": "ns=2;s=Gone", "value": null, "type": null, "ts": null, "error": "BadNodeIdUnknown"}]}
The answer to a read, described under reading values.
Items
Each item is one entry the driver found:
{"id": "ns=2;s=Line1/Speed", "parent": "ns=2;s=Line1", "name": "Speed",
"kind": "value", "address": "ns=2;s=Line1/Speed", "path": null,
"type": "Double", "access": "rw", "unit": "rpm", "description": "Spindle speed",
"sample": null, "more": false, "root": null,
"detail": {"namespace_uri": "urn:plc:line1"}}
| Key | Required | Meaning |
|---|---|---|
id | yes | Identifies the item. It is unique within the scan and 1 to 512 characters long. The driver MUST derive it from the device alone, never from the scan’s root. An item then has the same id in a full scan and in every branch scan. |
parent | yes | The id of the item’s parent, or null at the top. |
name | yes | The name a person sees, at most 256 characters. |
kind | yes | folder for structure, or value for something a metric can read. A value MAY also have children, as an MQTT topic has the leaves of its JSON payload. |
address | for a value | The address to put in a metric. It MUST parse with the driver’s own address parser. It MUST be in the driver’s canonical form. The canonical form is the form the driver prints from a parsed address, and it can be compared with the address of an existing metric. At most 1024 characters. |
path | no | The metric path within the address’s data packet, or null. At most 1024 characters. |
type | no | A Sparkplug B type name with no byte order (Int8, Int16, Int32, Int64, UInt8, UInt16, UInt32, UInt64, Float, Double, Boolean, String, Text, DateTime, UUID, Bytes, File, DataSet or Template), or null when the driver cannot say. |
access | no | r, w, rw or null. |
unit | no | The engineering unit, at most 64 characters. |
description | no | At most 1024 characters. |
sample | no | The current value written as text, at most 256 characters. Only sent when limits.samples is true. |
more | no | True on a folder that has children the scan did not list, for example because of the depth cap. |
root | no | What to send as root to scan this folder on its own. It defaults to the item’s id. |
detail | no | An object of driver-specific facts, at most 2 KiB as JSON. |
A key that is left out means null, or false for more. The pair of address and path matches the Address and Path of a metric. A consumer binds an item to a schema metric by that pair.
The Edge Agent SHOULD truncate strings that are too long. It SHOULD drop an item with no id, an id over 512 characters, a repeated id or any other fault, and count what it dropped. One bad item then does not lose the rest of its message.
Rules for a scan
- A driver runs one scan at a time. If a
startarrives while a scan is running, the driver answers with anendcarryingERRon the new id. - A
cancel, or a new driver configuration onconf, stops the running scan. The scan MUST end withCANCELLEDwithin 5 seconds. - The driver MUST keep to every limit. At the item cap it stops, and the scan ends with
truncatedand reasonitems. A folder at the depth cap getsmore: true, and the scan ends with reasondepth. Atlimits.secondsthe driver ends the scan with reasonseconds, even if its device has stopped answering. - The driver waits
pace_msbetween southbound requests. It keeps collecting data while it scans. - Data comes first. A driver MUST NOT hold up
datamessages to sendfoundmessages. - If the
starthas awindowand the driver’sacceptrepeats it, the driver MUST NOT publish anitemsmessage whilewindowof itsitemsmessages are not yet covered by anack. The driver waits, and stops waiting on a cancel, a newconfor the time limit.progressandendmessages are not counted. The wait counts towardslimits.seconds. - For a branch scan, the first item MUST have
idequal tofolder_id. - A scan never changes the device.
Reading values
An Edge Agent MAY ask a driver for the current values of up to 40 addresses with a read. Live values help a person who is choosing addresses. If a driver’s hello said reads: false, or left reads out, the driver never gets a read. Values read this way are never published to Sparkplug.
The driver answers once on found/<id> with seq 0. The answer is either a values message or an end carrying an error.
Each entry of values has:
| Key | Meaning |
|---|---|
address | One of the addresses asked for. There is one entry for each, in any order. |
value | The value written as text, or null. At most 1024 characters. A string is sent as it is. A number or Boolean is sent as JSON writes it, and anything else as JSON. A number JSON cannot write is sent as NaN, Infinity or -Infinity. |
type | A Sparkplug B type name with no byte order, or null. |
ts | The value’s source timestamp in milliseconds since the epoch, or null. |
error | Null, or a short reason the address could not be read, at most 256 characters. |
A driver that cannot answer sends end with an error code. The code is UNSUPPORTED when the driver does not read values, CONN when it is not connected to its device, and ERR for any other failure.
Rules for a read:
- A read runs beside a scan, never inside it, and does not count as a scan.
- A driver answers a
readwhile a scan is running. - The driver reads on its existing connection to its device. It never opens a session, subscription or client for a read.
- If a driver has not answered within 4 seconds, it gives up and sends nothing.
- The Edge Agent sends at most one read at a time to a driver.
- A read never changes the device.
Codes
Every outcome of a scan has exactly one code.
The driver codes are the only codes a driver sends. They go in the error.code of an end.
| Code | Meaning |
|---|---|
UNSUPPORTED | The driver does not implement scanning, or does not read values |
OPTIONS | Bad root, folder_id or options. The message says which |
CONN | The driver cannot reach its device, as for the CONN status |
AUTH | The device refused the driver, as for the AUTH status |
CANCELLED | Stopped by a cancel or a new conf |
ERR | Any other failure, with a message |
An Edge Agent SHOULD report outcomes it detects itself with these agent codes. Results are then reported the same way whichever agent ran the scan.
| Code | Meaning |
|---|---|
REQUEST | The scan request was malformed |
UNDEPLOYED | The connection is not in this agent’s configuration, or is not served by a driver |
NODRIVER | The driver is not connected, its status is not UP, it came up a moment ago and has not subscribed to scout yet, or the agent is stopping |
LIBRARY | The driver has been UP for a while and has not subscribed to scout. It was built before discovery existed |
BUSY | A scan is already queued or running on this connection |
LIMIT | The agent is running as many scans as it allows and its queue is full |
NOREADS | Live values were asked for from a driver whose hello says reads: false |
NOTRUNNING | A cancel named a connection with no scan |
TIMEOUT | The scan ran past its time limit, or nothing arrived for too long. For a read, no answer arrived in time |
LOST | A gap in seq showed that a message was lost |
INTERRUPTED | The agent restarted, or the driver disconnected, left UP or sent a new hello during the scan |
STORE | The agent could not save the result |
AGENT | Any other agent failure, including a found message that is not JSON or does not match its schema |
The agent MAY also set OPTIONS or CANCELLED itself for a scan that never reached the driver. Examples are a branch scan whose folder_id is not in the agent’s current results, and a scan cancelled while still queued. If the agent ends a scan itself because of TIMEOUT, LOST, AGENT or one of its own caps, it SHOULD send cancel to the driver.
Compatibility
| Edge Agent | Driver | Result |
|---|---|---|
| Without discovery | Without discovery | Unchanged |
| Without discovery | With discovery | The address configuration has no features key. The driver never subscribes to scout, and nothing changes, including after a rollback from a newer agent. |
| With discovery | Without discovery | The driver never subscribes. Scans fail with LIBRARY. |
| With discovery | With discovery, status not UP | Scans fail with NODRIVER. |
| With discovery | With discovery, but no scanning in the driver | The hello says supported: false, and scans fail with UNSUPPORTED. |
| With discovery | With discovery and scanning | Scans run. |
| Asks for live values | Does not read values | The hello has no reads. Live values are refused with NOREADS, and the driver never gets a read. |
Schemas and test fixtures
JSON Schemas for every discovery message are published in the lib/edge-scout-schemas package of the reference implementation. They use draft 2020-12. Each schema’s $id is urn:edge-scout:<name>.
| Schema | Checks |
|---|---|
urn:edge-scout:common | Shared definitions: ids, limits, excluded scopes, codes and Sparkplug type names. It checks nothing on its own. |
urn:edge-scout:addr | The address configuration, with its optional features key |
urn:edge-scout:request | The agent’s hello, start, cancel, ack and read |
urn:edge-scout:found | The driver’s hello, accept, items, progress, end and values |
urn:edge-scout:item | One discovered item |
The package also holds valid and invalid fixtures for each schema. An implementation in any language can test against them. Some rules cannot be written as JSON Schema. An implementation checks these in code:
- the 8 KiB cap on
options - the 256 KiB cap on an
itemsmessage - the 2 KiB cap on
detail - that
seqgoes up by 1 for each message of a scan
The three reference driver libraries implement the driver side of discovery in full. That covers the gate, the hello, seq, batching, the window, the limits, cancellation and errors. A driver built on one only has to produce items and, if it can, read values.