Skip to content
On this page

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.

16 min read Edit this page
Edge
Edge Agent
Devices
ACS implementationEdge Scout schemasSee how the AMRC Connectivity Stack implements this.View on GitHub

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 features before anything else in an address configuration, before it checks version, 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>/scout when it sees features.scout with 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 scout when it connects.
  • MUST NOT publish on found/<id> unless it has subscribed to scout on 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

TopicPublished byMessages
fpEdge1/<Conn>/scoutEdge Agenthello, start, ack, cancel, read
fpEdge1/<Conn>/found/<id>driverhello, 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.

KeyMeaning
idThe scan id. It is 1 to 64 letters, digits and underscores, and is never hello.
version1.
rootWhere to start, in the driver’s own terms, or null for the device’s natural top. At most 1024 characters.
folder_idFor a branch scan, the id of the folder this scan replaces. Otherwise null. At most 1024 characters. It is set only together with root.
optionsDriver-specific options, at most 8 KiB as JSON. The driver validates them.
limitsThe caps the driver MUST keep to. All five are always present.
windowOptional. The most items messages the driver may send ahead of the agent’s acks, from 1 to 64.

The limits are:

LimitMeaningMaximum
itemsThe most items in the scan50,000
depthThe most levels below the root32
secondsThe longest the scan may run600
pace_msThe pause between two southbound requests, in millisecondsnone (minimum 0)
samplesWhether 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.

KeyMeaning
versionsThe versions of this protocol the driver speaks. At least one.
supportedWhether 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.
readsWhether the driver answers read. It also comes from the driver’s code. A hello without reads means false.
libraryOptional. 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.

KeyMeaning
exhaustiveTrue 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.
truncatedTrue when a cap stopped the scan. A truncated scan is not an error.
reasonWhen truncated is true, one of items, depth, seconds, size or partial_access. Otherwise null.
excludedOptional. 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”.
errorAn 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"}}
KeyRequiredMeaning
idyesIdentifies 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.
parentyesThe id of the item’s parent, or null at the top.
nameyesThe name a person sees, at most 256 characters.
kindyesfolder 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.
addressfor a valueThe 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.
pathnoThe metric path within the address’s data packet, or null. At most 1024 characters.
typenoA 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.
accessnor, w, rw or null.
unitnoThe engineering unit, at most 64 characters.
descriptionnoAt most 1024 characters.
samplenoThe current value written as text, at most 256 characters. Only sent when limits.samples is true.
morenoTrue on a folder that has children the scan did not list, for example because of the depth cap.
rootnoWhat to send as root to scan this folder on its own. It defaults to the item’s id.
detailnoAn 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 start arrives while a scan is running, the driver answers with an end carrying ERR on the new id.
  • A cancel, or a new driver configuration on conf, stops the running scan. The scan MUST end with CANCELLED within 5 seconds.
  • The driver MUST keep to every limit. At the item cap it stops, and the scan ends with truncated and reason items. A folder at the depth cap gets more: true, and the scan ends with reason depth. At limits.seconds the driver ends the scan with reason seconds, even if its device has stopped answering.
  • The driver waits pace_ms between southbound requests. It keeps collecting data while it scans.
  • Data comes first. A driver MUST NOT hold up data messages to send found messages.
  • If the start has a window and the driver’s accept repeats it, the driver MUST NOT publish an items message while window of its items messages are not yet covered by an ack. The driver waits, and stops waiting on a cancel, a new conf or the time limit. progress and end messages are not counted. The wait counts towards limits.seconds.
  • For a branch scan, the first item MUST have id equal to folder_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:

KeyMeaning
addressOne of the addresses asked for. There is one entry for each, in any order.
valueThe 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.
typeA Sparkplug B type name with no byte order, or null.
tsThe value’s source timestamp in milliseconds since the epoch, or null.
errorNull, 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 read while 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.

CodeMeaning
UNSUPPORTEDThe driver does not implement scanning, or does not read values
OPTIONSBad root, folder_id or options. The message says which
CONNThe driver cannot reach its device, as for the CONN status
AUTHThe device refused the driver, as for the AUTH status
CANCELLEDStopped by a cancel or a new conf
ERRAny 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.

CodeMeaning
REQUESTThe scan request was malformed
UNDEPLOYEDThe connection is not in this agent’s configuration, or is not served by a driver
NODRIVERThe 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
LIBRARYThe driver has been UP for a while and has not subscribed to scout. It was built before discovery existed
BUSYA scan is already queued or running on this connection
LIMITThe agent is running as many scans as it allows and its queue is full
NOREADSLive values were asked for from a driver whose hello says reads: false
NOTRUNNINGA cancel named a connection with no scan
TIMEOUTThe scan ran past its time limit, or nothing arrived for too long. For a read, no answer arrived in time
LOSTA gap in seq showed that a message was lost
INTERRUPTEDThe agent restarted, or the driver disconnected, left UP or sent a new hello during the scan
STOREThe agent could not save the result
AGENTAny 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 AgentDriverResult
Without discoveryWithout discoveryUnchanged
Without discoveryWith discoveryThe address configuration has no features key. The driver never subscribes to scout, and nothing changes, including after a rollback from a newer agent.
With discoveryWithout discoveryThe driver never subscribes. Scans fail with LIBRARY.
With discoveryWith discovery, status not UPScans fail with NODRIVER.
With discoveryWith discovery, but no scanning in the driverThe hello says supported: false, and scans fail with UNSUPPORTED.
With discoveryWith discovery and scanningScans run.
Asks for live valuesDoes not read valuesThe 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>.

SchemaChecks
urn:edge-scout:commonShared definitions: ids, limits, excluded scopes, codes and Sparkplug type names. It checks nothing on its own.
urn:edge-scout:addrThe address configuration, with its optional features key
urn:edge-scout:requestThe agent’s hello, start, cancel, ack and read
urn:edge-scout:foundThe driver’s hello, accept, items, progress, end and values
urn:edge-scout:itemOne 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 items message
  • the 2 KiB cap on detail
  • that seq goes 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.

ACS implementationACS Edge AgentSee how the AMRC Connectivity Stack implements this.View on GitHub
Esc