Skip to content
On this page

Services

Command Escalation

Command Escalation sends Sparkplug commands to nodes and devices on behalf of clients that hold a grant for that command.

10 min read Edit this page
Central services
ACS implementationACS Command Escalation serviceSee how the AMRC Connectivity Stack implements this.View on GitHub

Command Escalation sends Sparkplug commands to nodes and devices on behalf of other clients.

Sparkplug commands are NCMD and DCMD messages, and Sparkplug B expects only the Primary Application to send them. In a factory many clients have a good reason to ask for one, for example a historian that needs a device to rebirth or a monitor that needs an Edge Agent to reload its configuration. If each of those clients had MQTT permission to publish commands, any of them could send any command to any device.

Command Escalation acts as the single Primary Application instead. A client asks it for a command over HTTP, and the service publishes the command only after it has checked that the client holds a grant for that command on that target. Two commands are well known, Rebirth and Reload Edge Agent Config.

How a request flows

sequenceDiagram
    participant C as Client
    participant CE as Command Escalation
    participant A as Auth
    participant CS as Configuration Store
    participant B as MQTT broker
    participant N as Edge Agent
    C->>CE: POST /v1/address/Plant-A/Cell-3/Press-1
    CE->>A: Read the client's ACL
    CE->>CS: Read command definitions and Sparkplug addresses
    CE->>CE: Match the request against the ACL
    CE->>B: Publish spBv1.0/Plant-A/DCMD/Cell-3/Press-1
    CE-->>C: 200
    B->>N: DCMD
  1. The client sends the Sparkplug address of the target and the metric it wants to set.
  2. The service reads the client’s grants from the Auth service. It reads from the Configuration Store which metrics each command permission allows and which Sparkplug address each grant target has.
  3. If a grant allows that metric on that address, the service publishes the command to the target’s NCMD or DCMD topic and answers 200. Otherwise it answers with an error status and publishes nothing.

HTTP interface

The service follows the service specification. Clients find it in the Directory under the service UUID 78ea7071-24ac-4916-8351-aa3e549d8ccd. Every request MUST be authenticated with one of the authentication methods. All routes apart from /ping and /token are under /v1.

Request a command

POST /v1/address/{group}/{node}
POST /v1/address/{group}/{node}/{device}

The first form sends an NCMD to an Edge Node and the second sends a DCMD to a device under that node. The path segments are the target’s Sparkplug Group ID, Edge Node ID and Device ID as they appear in its Sparkplug topics, not UUIDs.

The request body MUST have the content type application/json. It is an object with these fields:

FieldTypeRequiredMeaning
namestringyesThe full name of the metric to set in the command, for example Node Control/Rebirth.
typestringnoThe Sparkplug B data type name of the metric, for example Boolean, Int32, Double or String. Types says what happens when it is left out.
valueany JSON valueyesThe value to send. It MUST be convertible to the metric’s Sparkplug type.

For example, to ask device Press-1 under node Cell-3 in group Plant-A to rebirth:

POST /v1/address/Plant-A/Cell-3/Press-1 HTTP/1.1
Host: cmdesc.example.com
Authorization: Negotiate YIIC...
Content-Type: application/json

{ "name": "Device Control/Rebirth", "type": "Boolean", "value": true }

The response has no body. The status gives the outcome:

StatusMeaning
200The request was allowed and the command was handed to the MQTT broker.
401The request was not authenticated, or the credentials were wrong.
403No grant the caller holds allows this metric, with this type, on this address. The service also answers 403 when it does not know the caller.
409The request gave a type, but the command definition that matched it has no type to check it against.
415The body is not application/json.
503The service could not decide or could not send. The cause is one of these: it could not read the caller’s ACL from Auth, it could not check the caller’s credentials, or it has no connection to the MQTT broker. The client MAY retry later.

A 200 means only that the command reached the broker. Command Escalation does not check whether the target is online or has declared the metric in its birth certificate, and the Sparkplug command carries no reply. If a client needs to know the effect, it SHOULD watch the target’s DATA or BIRTH messages.

Service routes

As on every Factory+ service, GET /ping returns the service UUID and the version of this interface, 1.0.2, and POST /token issues a bearer token for this service.

Authorisation

Command permissions

The right to send a command is an ordinary Factory+ permission, granted through Auth like any other as described under Authorisation. A command permission:

  • MUST be a member of the Command Escalation permission group 9584ee09-a35a-4278-bc13-21a8be1f007c. The service only considers grants of permissions in that group.
  • MUST have an entry in the Command definition application 60e99f28-67fe-4344-a6ab-b1edb8b8e810, keyed by the permission’s UUID. The entry lists the metrics the permission allows a client to set.

A Command definition entry is a JSON array of objects, one per metric:

PropertyTypeRequiredMeaning
namestringyesThe full metric name, for example Node Control/Rebirth.
typestringnoThe Sparkplug B data type name of the metric. A definition SHOULD always give a type, for the reasons in Types.

For example, the Reload Edge Agent Config permission has this entry:

[
    { "name": "Node Control/Reload Edge Agent Config", "type": "Boolean" }
]

One permission MAY list several metrics, and the Rebirth permission lists two so that it covers both nodes and devices.

Targets

The target of a grant says which Sparkplug nodes or devices the client may send those commands to. The service looks the target up in the Sparkplug address application 8e32801b-f35a-4cbf-a5c3-2af64d3debd7. Its entries have this shape:

{ "group_id": "Plant-A", "node_id": "Cell-3", "device_id": "Press-1" }

The service compares the address from the request path with the target’s entry as follows:

  • An entry with no device_id matches only the Edge Node itself, not the devices under it.
  • An entry with a device_id matches only that device.
  • The value + in any field matches any non-empty value in that position. The entry { "group_id": "Plant-A", "node_id": "Cell-3", "device_id": "+" } matches every device under Cell-3 but not Cell-3 itself. A client that may command both a node and its devices therefore needs two grants.
  • A grant whose target is the Wildcard matches every address. The Wildcard is the Null UUID, 00000000-0000-0000-0000-000000000000.
  • A grant whose target has no Sparkplug address entry matches nothing.

Auth expands group targets and the Self special before the service sees the grants, as described under Authorisation. A grant to a class of devices therefore covers each member that has a Sparkplug address.

Types

The service decides the type of the metric it sends as follows:

  1. When the request gives no type, the service uses the type from the matching command definition, or Boolean if the definition has no type.
  2. When the request gives a type, only a definition with the same type matches it. A definition with a different type does not match, and the request fails with 403 unless another grant allows it.
  3. When the request gives a type and the definition that matches by name has no type, the service refuses the request with 409 because it cannot tell whether that type is allowed.

A definition without a type therefore allows only requests that leave the type out, and those requests are sent as Boolean. Giving every definition a type avoids this.

Matching

The service allows a request when the caller holds at least one grant where:

  • the permission has a Command definition entry that lists the requested metric name with a compatible type,
  • and the grant’s target matches the requested address.

Several grants that match the address may define the same metric name. The service then uses the first definition that matches the name and type, and takes the type from that one definition. Grants that define the same command SHOULD give it the same type, because otherwise the result depends on which grant the service reads first.

An implementation MAY let one configured administrative principal send any command without a grant. Such a request MUST give a type because without a definition the service has no other way to know which type to send.

The command it publishes

When a request is allowed, the service publishes a Sparkplug B payload. A command to a node goes to spBv1.0/<group>/NCMD/<node> and a command to a device goes to spBv1.0/<group>/DCMD/<node>/<device>. The payload has these fields:

FieldValue
timestampThe time the service sent the command, in milliseconds since the Unix epoch. The Factory+ timestamp rule allows milliseconds. A receiver converts it by that rule, as it would any other timestamp.
metricsOne metric with the requested name, the resolved type and the requested value.
uuidThe Factory+ payload UUID 11ad7b32-1d32-4c4a-b0c9-fa049208939a, as described in the Sparkplug conventions.
bodyThe identity of the client that asked for the command, as UTF-8 text.
seqNot set, because Sparkplug B sends commands without a sequence number.

The body names the requesting principal so that a node or device can record who asked for a command. It takes one of these forms:

FormUsed when
kerberos:<principal name>The client authenticated with Kerberos, for example kerberos:operator@EXAMPLE.COM.
uuid:<principal UUID>The client authenticated with an OIDC bearer token carrying fp_principal_uuid.
sparkplug:<group>/<node>The request came through the deprecated MQTT interface.

Because the service has already authorised the request, a receiver SHOULD use the body only for logging and auditing.

The service publishes at QoS 0, as Sparkplug B requires for commands. A service SHOULD NOT queue commands while it has no connection to the broker, because a command delivered late can do harm, such as a rebirth or a setpoint applied minutes after it was asked for. The service answers 503 instead, and the client decides whether to try again.

The service’s own principal needs the MQTT permission Issue CMDs so that the broker lets it publish to every NCMD and DCMD topic. It also needs permission to read the caller’s ACL and the two Configuration Store applications above.

Rebirth

Rebirth asks a Sparkplug node or device to publish its birth certificate again. A node answers Node Control/Rebirth = true by publishing its NBIRTH and the DBIRTH of each of its devices again. A device answers Device Control/Rebirth = true by publishing its DBIRTH again. A consumer asks for a rebirth to rebuild its view when it joins late or has lost track of a node’s metrics and aliases. Factory+ consumers SHOULD ask through Command Escalation rather than publishing a command themselves.

PermissionRebirth
fbb9c25d-386d-4966-a325-f16471d9f7be
Allows a client to ask the target node or device to publish its birth certificate again.

Its Command definition entry is:

[
    { "name": "Node Control/Rebirth", "type": "Boolean" },
    { "name": "Device Control/Rebirth", "type": "Boolean" }
]

To rebirth a node, a client sends { "name": "Node Control/Rebirth", "type": "Boolean", "value": true } to /v1/address/<group>/<node>. To rebirth a device, it sends Device Control/Rebirth to /v1/address/<group>/<node>/<device>.

Reload Edge Agent Config

Reload Edge Agent Config asks an Edge Agent to reload its configuration. An Edge Agent answers Node Control/Reload Edge Agent Config = true by reading its configuration from the Configuration Store again and restarting with it. A central component uses the command to keep each agent’s configuration current. The component that notices a change asks through Command Escalation and needs no MQTT permission of its own.

PermissionReload Edge Agent Config
6335f100-e68e-4e4d-b46d-85b42f85a036
Allows a client to ask the target Edge Agent to read its configuration again and restart with it.

Its Command definition entry is:

[
    { "name": "Node Control/Reload Edge Agent Config", "type": "Boolean" }
]

To ask an Edge Agent to reload, a client sends { "name": "Node Control/Reload Edge Agent Config", "type": "Boolean", "value": true } to /v1/address/<group>/<node>. The address is the agent’s own Sparkplug address. The command applies to a node only and has no device form.

Well-known UUIDs

ServiceCommand Escalation
78ea7071-24ac-4916-8351-aa3e549d8ccd
The service UUID that Command Escalation is registered under in the Directory.
Permission groupCommand Escalation permissions
9584ee09-a35a-4278-bc13-21a8be1f007c
Every command permission is a member of this group.
ApplicationCommand definition
60e99f28-67fe-4344-a6ab-b1edb8b8e810
Lists, for each command permission, the metrics it allows a client to set.
ApplicationSparkplug address
8e32801b-f35a-4cbf-a5c3-2af64d3debd7
Gives the Sparkplug address of each grant target.
PermissionRebirth
fbb9c25d-386d-4966-a325-f16471d9f7be
Allows a client to request a rebirth of the target node or device.
PermissionReload Edge Agent Config
6335f100-e68e-4e4d-b46d-85b42f85a036
Allows a client to ask the target Edge Agent to reload its configuration.

API reference

OpenAPI specificationView the full OpenAPI specification for the Command Escalation serviceView specification
post/v1/address/{group}/{node}
Send an NCMD to an Edge Node

Publishes an NCMD to spBv1.0/{group}/NCMD/{node} if the caller holds a grant whose permission allows the metric and whose target matches the node's address.

Authentication: Any one of: HTTP Basic, Negotiate (Kerberos), Bearer token
Parameters
NameInRequiredTypeDescription
grouppathYesSparkplugId

Sparkplug Group ID of the target.

nodepathYesSparkplugId

Sparkplug Edge Node ID of the target.

Request body (required)
application/jsonCommandRequest
  • namerequiredstring

    The full name of the metric to set.

  • typeSparkplugType

    The Sparkplug type of the metric. When it is left out the service uses the type from the matching command definition, or Boolean if that has none. A root override request must give a type.

  • valuerequiredany

    The value to send, which must be convertible to the metric's Sparkplug type.

Responses
200

The request was allowed and the command was handed to the MQTT broker. This does not mean the target is online or acted on it.

401

The request was not authenticated, or the credentials were wrong.

403

No grant the caller holds allows this metric, with this type, on this address, or the service does not know the caller.

409

The request gave a type, but the command definition that matched it by name has no type, so the service cannot check it.

415

The request body is not application/json.

503

The service could not read the caller's ACL from Auth, could not check the caller's credentials, or could not publish to the MQTT broker. The client may retry later.

default

Any other error, for example a body that is not valid JSON.

post/v1/address/{group}/{node}/{device}
Send a DCMD to a device

Publishes a DCMD to spBv1.0/{group}/DCMD/{node}/{device} if the caller holds a grant whose permission allows the metric and whose target matches the device's address.

Authentication: Any one of: HTTP Basic, Negotiate (Kerberos), Bearer token
Parameters
NameInRequiredTypeDescription
grouppathYesSparkplugId

Sparkplug Group ID of the target.

nodepathYesSparkplugId

Sparkplug Edge Node ID of the target.

devicepathYesSparkplugId

Sparkplug Device ID of the target.

Request body (required)
application/jsonCommandRequest
  • namerequiredstring

    The full name of the metric to set.

  • typeSparkplugType

    The Sparkplug type of the metric. When it is left out the service uses the type from the matching command definition, or Boolean if that has none. A root override request must give a type.

  • valuerequiredany

    The value to send, which must be convertible to the metric's Sparkplug type.

Responses
200

The request was allowed and the command was handed to the MQTT broker. This does not mean the target is online or acted on it.

401

The request was not authenticated, or the credentials were wrong.

403

No grant the caller holds allows this metric, with this type, on this address, or the service does not know the caller.

409

The request gave a type, but the command definition that matched it by name has no type, so the service cannot check it.

415

The request body is not application/json.

503

The service could not read the caller's ACL from Auth, could not check the caller's credentials, or could not publish to the MQTT broker. The client may retry later.

default

Any other error, for example a body that is not valid JSON.

get/ping
Identify the service
Authentication: Any one of: HTTP Basic, Negotiate (Kerberos), Bearer token
Responses
200

The service identity.

application/jsonPing
  • versionrequiredstring

    The version of this interface specification.

  • servicerequired"78ea7071-24ac-4916-8351-aa3e549d8ccd"
  • softwareobject

    Optional details of the implementation.

    Fields
    • vendorstring
    • applicationstring
    • revisionstring
401

The request was not authenticated, or the credentials were wrong.

post/token
Issue a bearer token for this service

Returns an opaque bearer token that is valid only on this service, for the principal that authenticated the request.

Authentication: Any one of: HTTP Basic, Negotiate (Kerberos), Bearer token
Responses
200

A new token.

application/jsonToken
  • tokenrequiredstring

    The bearer token.

  • expiryrequiredinteger

    Expiry time in milliseconds since the Unix epoch.

401

The request was not authenticated, or the credentials were wrong.

Esc