Skip to content
On this page

Data model

Data schemas

Factory+ schemas describe the metrics a device publishes, in JSON Schema 2020-12 identified by UUID.

14 min read Edit this page
ACS implementationACS ConfigDBSee how the AMRC Connectivity Stack implements this.View on GitHub

A Factory+ schema describes the shape of the data a device publishes. It says which metrics the device has, how they are grouped, what Sparkplug type each one carries and what each one means. Schemas exist because two devices that do the same job rarely name or structure their data the same way, and without a shared schema a consumer would need hand-written mapping for every device. When both devices publish against the same schema, a consumer can find every temperature sensor on a site by one UUID and read them all the same way.

Schemas give a common way to represent models. They do not replace the modelling work in existing specifications such as OPC UA companion specifications or MTConnect, and a schema may be written to follow one of those models.

Factory+ schemas are written in JSON Schema draft 2020-12. Each schema is identified by a UUID and stored in the Configuration Store. The Sparkplug birth certificate of every device that uses a schema refers to it. The requirement keywords on this page follow RFC 2119, as described in the service specification.

What a schema describes

A schema describes a tree. Its leaves are metrics, and each one becomes one Sparkplug metric. Its branches are either objects or folders. An object carries its own Schema_UUID and usually an Instance_UUID. A folder only groups metrics under a common name.

A document that conforms to a schema is an instance. It holds one metric definition for each metric the device publishes. A metric definition uses the fields of the Metric schema to give the metric’s Sparkplug type, where its value comes from and what it means. An Edge Agent turns the instance into a birth certificate, in which each property name becomes one level of the Sparkplug metric name. The example at the end of this page shows a schema, an instance of it and the metrics it produces.

Rules for a schema

A Factory+ schema:

  1. MUST declare "$schema": "https://json-schema.org/draft/2020-12/schema".
  2. MUST have a Schema_UUID. This is a UUID that identifies the schema and nothing else. A new schema SHOULD be given a random version 4 UUID.
  3. MUST have "$id": "urn:uuid:<Schema_UUID>", with the same UUID in lower case.
  4. MUST declare a Schema_UUID property whose value is fixed with const to the Schema_UUID. It SHOULD list Schema_UUID in required.
  5. SHOULD declare an Instance_UUID property of "type": "string", "format": "uuid" and list it in required. The Instance_UUID tells each instance of the object apart from every other instance, wherever the device moves.
  6. MUST refer to other schemas with "$ref": "urn:uuid:<Schema_UUID>" and never by URL.
  7. MUST be built by composition, so that every object in a device keeps its own Schema_UUID.
  8. MUST describe each metric as an allOf of a reference to the Metric schema and a refinement block, as set out in Defining a metric.
  9. MUST NOT use "type": "array". A collection of similar objects is an object whose keys are matched by patternProperties, as set out in Collections.
  10. SHOULD have a title that names the kind of thing it describes, such as Object Link or Electrical Grid.

Any Factory+ implementation can load a schema that follows these rules, and every $ref in such a schema can be resolved from the Configuration Store alone.

Property names

Each property name becomes one segment of a Sparkplug metric name. Factory+ joins the segments with /. The Unified Namespace also republishes metric names as MQTT topic levels. Property names in a schema therefore follow these rules.

  • A property name MUST NOT contain /, +, # or the NUL character.
  • A name MUST NOT be used for a metric and a folder at the same level. If a metric Foo exists, a folder Foo with metrics under it, such as Foo/Bar, MUST NOT exist beside it. A consumer could not tell whether Foo is a value or a branch.
  • A property name SHOULD contain only letters, digits and the underscore (_).

The library follows the SHOULD everywhere except Hierarchy-v1. Its Work Center and Work Unit metrics contain spaces because they carry the ISA-95 level names. These metrics cannot be renamed, because consumers of ISA-95 data and the UNS depend on those exact names.

Identity and versions

A schema’s identity is its Schema_UUID. Each schema also has a human-readable name and an integer version. These are recorded beside the schema in the Configuration Store, not in the schema body. In the published library the name and version also appear in the file name, for example Sensors/Proximity-v1.

A published schema MUST NOT change in a way that could make an instance that was valid before invalid, or change the meaning of data that devices already publish against it. Such a change is a breaking change. A breaking change MUST be published as a new schema with a new Schema_UUID and the version increased by one. The new schema’s information SHOULD set replaces to the Schema_UUID of the schema it supersedes.

The old schema stays exactly as it was, and a device that still uses it sees no change. A device moves to the new schema only when its own configuration is changed to use it. For example, Power/Power_Monitoring-v1 (481dbce2-cabc-4fb1-b402-ee51f49f62b0) and Power/Power_Monitoring-v2 (b6253da7-8d95-455c-bc42-23693ca95d46) are separate schemas with separate UUIDs.

A change that keeps every existing instance valid MAY be made in place, with the same Schema_UUID and version. The table classifies common changes.

ChangeClass
Add an optional metric, object, collection or foldernot breaking
Change Documentation, Tooltip, a unit, a range or the historian defaultnot breaking
Add an allowed Sparkplug type to a metricnot breaking
Remove an entry from requirednot breaking
Reorder propertiesnot a change
Remove or rename a propertybreaking
Remove an allowed Sparkplug type from a metricbreaking
Point a $ref at a different schemabreaking
Change the patternProperties pattern of a collectionbreaking
Add an entry to requiredbreaking
Change a property from one kind to another (for example a metric to an object)breaking

Composition

Factory+ schemas describe Sparkplug birth certificates, not general JSON documents. Every object in a birth certificate publishes its own Schema_UUID metric. One device can therefore carry several Schema_UUIDs at different levels, with one for the device, one for each axis, one for its device information and so on. A consumer can then search for every axis on a site by the axis Schema_UUID, whatever machine the axis belongs to.

JSON Schema inheritance with allOf merges two schemas into one object, and that cannot work here. If a 3D printer axis schema used allOf to extend the common axis schema, the merged object would need two different Schema_UUID constants at the same level, and no instance could satisfy both. Even if one could, consumers searching by the common axis Schema_UUID would no longer find that axis.

Schemas therefore extend each other by composition. The extending schema puts the base schema in a named child property and adds its own properties beside it. The library names these properties Base_<Name>. This excerpt from CNC/Axis-v1 extends the common axis schema, Common/Axis-v1 (777dd941-f426-4355-8130-e144530b1376).

{
  "$id": "urn:uuid:e39007e9-1427-4867-9d72-1c00c663db15",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "CNC Axis",
  "type": "object",
  "properties": {
    "Schema_UUID": {
      "const": "e39007e9-1427-4867-9d72-1c00c663db15"
    },
    "Instance_UUID": {
      "description": "The unique identifier for this object. (A UUID specified by RFC4122).",
      "type": "string",
      "format": "uuid"
    },
    "Base_Axis": {
      "$ref": "urn:uuid:777dd941-f426-4355-8130-e144530b1376"
    },
    "Is_Virtual": {
      "allOf": [
        {
          "$ref": "urn:uuid:b16275f1-e443-4c41-a482-fcbdfbd20769"
        },
        {
          "properties": {
            "Sparkplug_Type": {
              "enum": [
                "Boolean"
              ]
            },
            "Documentation": {
              "default": "Virtual axis (no hardware present; true in case of virtual axis, else false)."
            }
          }
        }
      ]
    }
  },
  "required": [
    "Schema_UUID",
    "Instance_UUID",
    "Base_Axis"
  ]
}

A device using this schema publishes Schema_UUID for the CNC axis at the axis level and Base_Axis/Schema_UUID for the common axis one level down. A search for either Schema_UUID finds the axis.

Metric definitions are the one place allOf is used, and there it combines the Metric schema with a refinement block. This does not break the rule, because metrics do not publish a Schema_UUID and the refinement block adds no Schema_UUID of its own.

Defining a metric

Each metric in a schema is an allOf with exactly two entries:

  1. A $ref to the Metric schema, urn:uuid:b16275f1-e443-4c41-a482-fcbdfbd20769. It supplies every field a metric can have.
  2. A refinement block whose properties narrow those fields for this metric.

The refinement block MUST restrict Sparkplug_Type with an enum of the types the metric may have, and it SHOULD give a default for Documentation. It MAY also give defaults for other fields, such as Eng_Unit, Eng_Low and Eng_High, and it MAY restrict Value to an enum of allowed values.

The Battery/Percentage metric from Device_Information-v1 allows four floating-point types and suggests a unit and range.

{
  "allOf": [
    {
      "$ref": "urn:uuid:b16275f1-e443-4c41-a482-fcbdfbd20769"
    },
    {
      "properties": {
        "Documentation": {
          "default": "The current battery percentage"
        },
        "Sparkplug_Type": {
          "enum": [
            "FloatLE",
            "FloatBE",
            "DoubleLE",
            "DoubleBE"
          ]
        },
        "Eng_Unit": {
          "default": "%"
        },
        "Eng_Low": {
          "default": 0
        },
        "Eng_High": {
          "default": 100
        }
      }
    }
  ]
}

A definition of this metric with "Sparkplug_Type": "Boolean" is invalid, because an enum constrains the instance. A default is only an annotation, and tools use it to fill in a new instance. A definition that writes different documentation or a different unit is still valid.

The Metric schema

The Metric schema (Common/Metric-v1) lists every field a metric definition can have. Its $id is urn:uuid:b16275f1-e443-4c41-a482-fcbdfbd20769, and its Schema_UUID const is b16275f1-e443-4c41-a482-fcbdfbd20769. It requires Sparkplug_Type and Record_To_Historian. The full source is schemas/Common/Metric-v1.yaml in the schema library.

FieldTypeMeaning
Sparkplug_Typestring, one of the values belowThe data type of the metric. Required.
Record_To_Historianboolean, default trueWhether historians record the metric’s values. Required. A definition with false produces a birth metric with is_transient set to true.
ValuestringThe fixed value of a static metric, or the initial value of a dynamic one. A refinement block may restrict it with an enum.
Methodstring, one of GET, PUT, POST, DELETE, GET,POST, default GETHow the value is obtained, written in REST style for every protocol. GET is for read-only values and PUT for values that are written.
AddressstringWhere the value is read from on the device, in a form that depends on the protocol. With Path, it identifies one value, for example ns=2;s=/Channel/Spindle/actSpeed for OPC UA or %QD1026 for a fieldbus.
PathstringHow to pick the value out of what Address returns, for example a JSONPath ($.status.errors.code) or an XPath expression. Empty when the protocol returns the value on its own.
Eng_UnitstringThe engineering unit of the value, such as mm or °C. Empty when no unit applies.
Eng_LownumberThe lowest value the metric can have, for example the hardware limit.
Eng_HighnumberThe highest value the metric can have, for example the hardware limit.
DeadbandstringThe smallest change the Edge Agent treats as worth reporting. It is either a positive number for an absolute change, such as 3.75, or a percentage of the range from Eng_Low to Eng_High, such as 1.5%. A percentage needs both limits. It applies to numeric metrics only.
TooltipstringA short description, for display when a user hovers over the metric.
DocumentationstringA fuller description, with enough context that someone who did not configure the device can understand what the metric holds.

Address, Path and Method tell an Edge Agent’s driver how to read the value, and their exact syntax belongs to the driver for that protocol. The other fields describe the data and travel with it as properties of the birth metric, following the Sparkplug conventions.

Sparkplug types

Sparkplug_Type MUST be one of these values:

GroupValues
Signed integersInt8, Int16LE, Int16BE, Int32LE, Int32BE, Int64LE, Int64BE
Unsigned integersUInt8, UInt16LE, UInt16BE, UInt32LE, UInt32BE, UInt64LE, UInt64BE
Floating pointFloatLE, FloatBE, DoubleLE, DoubleBE
Other scalarsBoolean, String, Text, DateTime, UUID
ComplexDataSet, Bytes, File, Template
PlaceholderUnknown

The LE and BE suffixes say whether a multi-byte value is little-endian or big-endian when a driver reads it as raw bytes from the device, for example from a block of registers. An Edge Agent removes the suffix in the birth certificate, because it is not part of the Sparkplug type. A metric defined as FloatBE is published with the Sparkplug type Float, and UInt16LE is published as UInt16. A schema that does not care about byte order lists both forms, as the Battery/Percentage example does.

Collections

Factory+ schemas do not use JSON arrays, because arrays do not map onto Sparkplug metric names. A collection of similar objects is an object whose keys are matched by patternProperties. The keys are names chosen by whoever configures the device. Each name becomes a level in the metric name. For example, a robot’s axes appear as Axes/A1/..., Axes/A2/... and so on.

This excerpt from Common/Alert-v1 allows any number of links, and each link is an instance of Common/Link-v1.

"Links": {
  "type": "object",
  "patternProperties": {
    "^[a-zA-Z0-9_]*$": {
      "$ref": "urn:uuid:b3c4b273-9528-45de-8842-9f77c9ef272a"
    }
  }
}

The pattern SHOULD allow only names that meet the property name rules. Most collections in the library use ^[a-zA-Z0-9_]*$, and a schema MAY use a narrower pattern. One library schema uses ^L[123]$ for the three lines of a three-phase supply.

Folders

A property declared as "type": "object" with its own properties and no Schema_UUID is a folder. A folder groups metrics under a common name without making them a separate object. It adds a level to the metric names but publishes no Schema_UUID or Instance_UUID. Device_Information-v1 uses a Battery folder to group Battery/Percentage and Battery/Time_Remaining. Use a folder when the grouping is only for readability, and use a separate schema when the group is a thing that consumers will want to find by itself.

Optional keywords

A schema MAY carry "topLevel": true or "topLevel": false. A value of true means a device can be built on the schema directly. A value of false means the schema describes a part used inside other schemas, such as an axis or a spindle. Tools use the keyword to decide which schemas to offer when someone chooses a schema for a device. If topLevel is absent, the schema says nothing either way, and a tool SHOULD NOT treat it as false.

Because JSON Schema validators ignore keywords they do not know, topLevel does not affect validation, and changing it is not a breaking change.

How schemas are stored

The Configuration Store holds the schemas of a Factory+ installation. Every consumer therefore resolves the same $ref to the same schema. Each schema is an object whose UUID is its Schema_UUID. The object is a member of the Metric schema class, and its body and information are held as configuration entries.

ClassMetric schema
83ee28d4-023e-4c2c-ab86-12c24e86372c
Every published metric schema is a member of this class. Consumers list schemas by its membership.
ApplicationJSON schema
b16e85fb-53c2-49f9-8d83-cdf6763304ba
The schema body as JSON, stored against the schema's object.
ApplicationSchema information
32093857-9d29-470e-a897-d2b56d5aa978
The schema's name, integer version and lineage.
ApplicationGeneral Information
64a8bfa9-7772-45c4-9d1a-9e6290690957
The general object information application. Its name field holds the schema's display name, such as Sensors/Proximity (v1).

The schema information entry holds these fields:

FieldMeaning
nameThe schema’s name, such as Common/Metric or Sensors/Proximity.
versionThe schema’s integer version. A consumer SHOULD also accept the integer written as a decimal string.
replacesThe Schema_UUID of the schema this one supersedes after a breaking change. Absent when it supersedes nothing.

An implementation MAY record more fields in this entry, such as where the schema came from or when it was created.

Consumers read stored schemas through the Configuration Store’s v2 API.

  • To resolve "$ref": "urn:uuid:<uuid>", read GET /v2/app/b16e85fb-53c2-49f9-8d83-cdf6763304ba/object/<uuid>.
  • To list every published schema, read GET /v2/class/83ee28d4-023e-4c2c-ab86-12c24e86372c/member.
  • To list the schemas that have a body, read GET /v2/app/b16e85fb-53c2-49f9-8d83-cdf6763304ba/class/83ee28d4-023e-4c2c-ab86-12c24e86372c.

If an implementation keeps unfinished or draft schemas, it MUST keep them out of the Metric schema class until they are published, because consumers find schemas by membership of that class. The Directory answers the separate question of which devices have actually published a schema in their birth certificates.

The Configuration Store also uses JSON Schema to check the shape of its own configuration entries. These config schemas are a different mechanism from the metric schemas on this page.

Worked example: from schema to birth certificate

Sensors/Proximity-v1 is a complete schema from the library. It has one metric of its own and the common device information object. It has no title.

{
  "$id": "urn:uuid:d4e32f15-3276-4e9f-b9ef-d9e1a1e4c535",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "topLevel": false,
  "type": "object",
  "properties": {
    "Schema_UUID": {
      "const": "d4e32f15-3276-4e9f-b9ef-d9e1a1e4c535"
    },
    "Instance_UUID": {
      "description": "The unique identifier for this object. (A UUID specified by RFC4122).",
      "type": "string",
      "format": "uuid"
    },
    "Active": {
      "allOf": [
        {
          "$ref": "urn:uuid:b16275f1-e443-4c41-a482-fcbdfbd20769"
        },
        {
          "properties": {
            "Documentation": {
              "default": "Whether the proximity sensor is active"
            },
            "Sparkplug_Type": {
              "enum": [
                "Boolean"
              ]
            }
          }
        }
      ]
    },
    "Device_Information": {
      "$ref": "urn:uuid:2dd093e9-1450-44c5-be8c-c0d78e48219b"
    }
  },
  "required": [
    "Schema_UUID",
    "Instance_UUID"
  ]
}

This instance of it defines a sensor that reads its state from an input. It gives the manufacturer as a static value and places the sensor in an ISA-95 enterprise. The Instance_UUIDs are example values.

{
  "Schema_UUID": "d4e32f15-3276-4e9f-b9ef-d9e1a1e4c535",
  "Instance_UUID": "ccbf2c9c-07c1-4361-8a55-7f2d8f3506e0",
  "Active": {
    "Sparkplug_Type": "Boolean",
    "Method": "GET",
    "Address": "input/0",
    "Documentation": "Whether the proximity sensor is active",
    "Record_To_Historian": true
  },
  "Device_Information": {
    "Schema_UUID": "2dd093e9-1450-44c5-be8c-c0d78e48219b",
    "Manufacturer": {
      "Sparkplug_Type": "String",
      "Value": "Example Sensors Ltd",
      "Record_To_Historian": false
    },
    "ISA95_Hierarchy": {
      "Schema_UUID": "84ac3397-f3a2-440a-99e5-5bb9f6a75091",
      "Instance_UUID": "50ace174-6129-4f4d-af81-79baa0c6eb1f",
      "Enterprise": {
        "Sparkplug_Type": "String",
        "Value": "Example Co",
        "Record_To_Historian": false
      }
    }
  }
}

The device’s birth certificate then contains these metrics.

Metric nameSparkplug typeValueTransient
Schema_UUIDUUIDd4e32f15-3276-4e9f-b9ef-d9e1a1e4c535no
Instance_UUIDUUIDccbf2c9c-07c1-4361-8a55-7f2d8f3506e0no
ActiveBooleanread from the deviceno
Device_Information/Schema_UUIDUUID2dd093e9-1450-44c5-be8c-c0d78e48219bno
Device_Information/ManufacturerStringExample Sensors Ltdyes
Device_Information/ISA95_Hierarchy/Schema_UUIDUUID84ac3397-f3a2-440a-99e5-5bb9f6a75091no
Device_Information/ISA95_Hierarchy/Instance_UUIDUUID50ace174-6129-4f4d-af81-79baa0c6eb1fno
Device_Information/ISA95_Hierarchy/EnterpriseStringExample Coyes

Each object’s UUIDs become metrics named after the object’s path, and each metric definition becomes one metric whose name is its path. A consumer reading the birth can tell from the top-level Schema_UUID that the device is a proximity sensor, and that it carries device information and an ISA-95 hierarchy, without fetching any schema. The Sparkplug conventions give the rules for these metrics and for the payload uuid that marks a birth certificate as Factory+. The ISA95_Hierarchy object at exactly Device_Information/ISA95_Hierarchy places the device in the Unified Namespace.

Esc