Data model
Engineering units
How a metric's engineering unit travels as a string and resolves to a UNECE unit code through a shared vocabulary.
A metric’s engineering unit says what its numbers measure, such as millimetres, degrees Celsius or kilowatt hours.
Factory+ carries the unit as a free-text string because that is how devices and the people configuring them write units, but free text is ambiguous across a site. If one device writes kWh, another kW·h and a third kWhr, a consumer comparing them cannot tell that all three mean the same unit.
The engineering unit vocabulary removes this ambiguity. It is a shared list of units in the Configuration Store that says which UNECE unit each string means. Metrics keep their strings, and a consumer that needs a standard code resolves the string through the vocabulary.
The requirement keywords here follow RFC 2119, as described in the service specification.
The unit on the wire
A metric’s unit is the Eng_Unit field of its definition in the Metric schema. It is a string, and it is empty or absent when no unit applies. Because Factory+ never rewrites it, the same string appears everywhere the metric’s data goes:
| Where | Field | Value |
|---|---|---|
| Sparkplug birth certificate | the metric’s engUnit property, of type String | the Eng_Unit string |
| Unified Namespace message | the Unit MQTT user property | the birth metric’s engUnit, or an empty string when there is none |
| Data Access results | unit | the unit string recorded with the values |
| i3X object metadata | engUnit | the UNECE code the string resolves to, left out when it resolves to none |
i3X is the one place that reports a code rather than the string, because the i3X specification describes units by UNECE code.
A metric’s Eng_Unit SHOULD be a string that resolves to a unit through the vocabulary. This is not a MUST because a device can publish a unit that nobody has added to the vocabulary yet, and its data is still valid. Such a metric works everywhere except where a code is needed, and there it has none.
UNECE codes
The vocabulary identifies each unit by its common code from UNECE Recommendation 20. Recommendation 20 lists codes for units of measure used in international trade. OPC UA uses the same codes for its engineering units. The OPC Foundation publishes a table, UNECE_to_OPCUA.csv, that gives each code a display name. Some examples:
| Code | Unit | OPC UA display name |
|---|---|---|
MMT | millimetre | mm |
CEL | degree Celsius | °C |
KWH | kilowatt hour | kW·h |
MTS | metre per second | m/s |
P1 | percent | % or pct |
A code is a stable identifier that other systems understand, and a free-text symbol is not. The OPC UA display name is the usual way to write each unit. The most direct way to meet the SHOULD above is for a metric to write its Eng_Unit as the display name of the right UNECE unit, with % for percent.
The vocabulary
The vocabulary is held in the Configuration Store. Each unit is an object of the Engineering unit class, and its definition is a configuration entry in the Engineering unit application.
255cb8bf-23dc-47f1-b8c9-48c2685b2f6e8cd3bb74-c07f-46ed-8422-3d714c945cceA unit’s entry in the Engineering unit application looks like this:
{
"code": "KWH",
"symbol": "kWh",
"aliases": ["kW·h"]
}
| Field | Required | Meaning |
|---|---|---|
code | yes | The unit’s UNECE Recommendation 20 common code. It is two or three upper-case letters or digits, matching the pattern ^[A-Z0-9]{2,3}$. It is the unit’s identity. |
symbol | yes | How metrics write the unit. Tools that let a user pick a unit for a metric SHOULD write this string into the metric’s Eng_Unit. |
aliases | no | An array of other strings that also mean the unit, each one different. An existing metric written kW·h means kilowatt hour once kW·h is an alias of that unit. |
The symbol and each alias MUST be non-empty and MUST NOT start or end with whitespace. The entry MUST NOT have other fields. The unit’s object also has a name in the General Information application, such as kilowatt hour.
The vocabulary MUST keep these invariants:
codeis a code in the UNECE Recommendation 20 table.- The unit’s object UUID is the UUID derived from its code. There is therefore at most one unit for each code.
- No string is the symbol or an alias of more than one unit. A string therefore means at most one unit.
A Configuration Store that holds the vocabulary SHOULD refuse any write that would break an invariant.
The vocabulary is meant to be read by every consumer that reports or displays units, so read access to the Engineering unit application SHOULD be granted widely. Changing the vocabulary is an administrative task.
Unit UUIDs
A unit’s object UUID is a name-based UUID computed from its code, and it is a version 5 UUID as defined in RFC 4122. The same unit has the same UUID on every Factory+ installation, which means a consumer can find a unit by code without searching the vocabulary.
- The namespace is the Factory+ UUID,
11ad7b32-1d32-4c4a-b0c9-fa049208939a. - The name is the UTF-8 string made of the prefix
83c8b3c2-f106-45da-bec7-b24c4b8c45d3, a colon and the code, for example83c8b3c2-f106-45da-bec7-b24c4b8c45d3:KWH.
In Python:
import uuid
FACTORY_PLUS = uuid.UUID("11ad7b32-1d32-4c4a-b0c9-fa049208939a")
PREFIX = "83c8b3c2-f106-45da-bec7-b24c4b8c45d3"
def eng_unit_uuid(code):
return uuid.uuid5(FACTORY_PLUS, f"{PREFIX}:{code}")
print(eng_unit_uuid("KWH")) # 0333cc9b-695e-564e-b100-a95253b14c30
| Code | Unit UUID |
|---|---|
KWH | 0333cc9b-695e-564e-b100-a95253b14c30 |
CEL | 4627b92d-6986-561f-88c5-d5cde778fe07 |
MMT | 4f76b1fc-2a8d-55d8-8626-7261f3330fe7 |
MTS | 6f69e6a5-f6aa-566e-935a-6dfea9da267c |
P1 | 5eed15cc-7a8d-5ddb-a44a-144cd2fb835a |
To look up a unit by code, compute its UUID and read GET /v2/app/8cd3bb74-c07f-46ed-8422-3d714c945cce/object/<unit UUID> from the Configuration Store. A 404 means the vocabulary does not contain that unit.
Resolving a unit string
A consumer resolves a metric’s Eng_Unit string to a unit in these steps:
- If the string is absent, is not a string, or is empty after trimming whitespace from both ends, the metric has no unit.
- Otherwise, trim whitespace from both ends of the string.
- Compare the trimmed string with the
symboland every entry inaliasesof every unit in the vocabulary. The comparison is exact and case-sensitive. Case matters in units:mWis a milliwatt andMWa megawatt. - If it matches, the metric’s unit is that unit and its UNECE code is the unit’s
code. Invariant 3 means there is at most one match. - If nothing matches, the string is unresolved. A consumer SHOULD keep showing the string as it is, and SHOULD NOT guess a code for it.
A consumer builds its lookup table from every entry of the Engineering unit application. One way is to list GET /v2/app/8cd3bb74-c07f-46ed-8422-3d714c945cce/object and read each entry. Because the vocabulary changes rarely, a consumer SHOULD cache it and follow changes through the Configuration Store’s change notifications instead of reading it for every metric.
Resolution happens beside the data and never changes it. Adding a unit or an alias to the vocabulary makes more strings resolve. That changes the codes consumers report but not the data devices publish.
Changing a metric’s unit
A metric’s Eng_Unit travels with every value. Historians store the unit with each series of values, and in the reference implementation the unit is part of what identifies the series. Changing a metric’s Eng_Unit string therefore starts a new series for that metric and splits its history in two at the moment of the change.
A metric’s Eng_Unit SHOULD only be changed when the unit itself is wrong. If the string is a valid but different spelling of a unit, such as kWhr for a kilowatt hour, add it to the vocabulary as an alias of that unit instead. The metric then resolves to the right code and its history stays in one series.