Message Variables New
A variable is a name in braces, such as {groupName}, that OAS replaces with text from the tag, its groups, the message or the system when it publishes. One setting can then give a different result for each tag: plant/{groupPathSlash} publishes each group's tags on a topic of its own, and {site}/{area}/{tagShortName} fills a field with Dallas/Plant/Speed.
This page lists every variable, where each driver reads them, and how the drivers differ.
Where variables can be written
| Driver | Where a variable can be written |
|---|---|
| MQTT driver | Publish Topic Id, with Publish All Tags As One Topic on - see Topic patterns. In a schema, with Output Format ISA-95 Lite or Custom AVRO Schema: a Custom Format mapping and a tag map's key. |
| Kafka driver | The same as the MQTT driver. A topic must also be a legal Kafka topic name - see Kafka driver. |
| MQTT broker | In a library schema used by a schema topic or a $schema/ group topic: a Custom Format mapping and a tag map's key. The topic is the one the client subscribes to, so the broker has no topic setting. |
| Snowflake driver | A column's value, with the Custom Format source. Not a column name. See Snowflake driver. |
| Every other driver | None. |
Settings that may look as if they take a variable, but do not:
| Setting | What happens to braces |
|---|---|
| Snowflake column name | Not allowed. The Column Mapper and the driver both show an error. |
| Kafka Subject Name | Not allowed. The name is used exactly as typed, braces included, and the web app warns when it holds braces. |
| Kafka Subject Name left blank | The subject is the Publish Topic Id followed by -value. This is a fixed rule, not a variable. |
| Publish Topic Id with Publish All Tags As One Topic off | Not used: each tag is published on the topic named by its own Id. |
| A Constant mapping, in a schema or a Snowflake column | Sent exactly as typed, braces included. |
A broker group topic under $group/ | It carries the broker's standard payload, which has no variables. |
Writing a variable
| Rule | Detail |
|---|---|
| Text | Any number of variables, with any text between them: company/{siteId}/{area}. |
| Case | Names are matched without regard to case: {siteId} and {siteid} are the same. |
| A literal brace | In a Custom Format, write {{ or }}. In Publish Topic Id, doubled braces around a variable a topic may use give its name in single braces (data/{{site}} gives data/{site}); doubled braces around anything else are kept as written (data/{{line}} stays data/{{line}}). A Kafka topic may not hold braces, so on Kafka such a tag is not published. |
| Field type | Custom Format works only on text fields and on a tag map's key. The schema editor flags it on any other field, and the library will not save it there. |
| A variable with no value | Never sent as empty text. In a field of one tag - an entry of a tag array, a tag map's key or value, or a message of one tag - that tag is left out of the message. In a field built once for the whole message, the message is not sent. Either is logged once in System Errors, naming the variable and the tag, and Data Test shows it as a note. A topic works the same way: the tag is not published. |
{value} with no value | The one exception: with bad quality, or an empty text value, it is sent as empty text. |
| An unknown variable in a schema | An error in the schema editor. A driver or the broker publishes nothing with that schema and logs one system error naming the variable. |
| Braces in Publish Topic Id that are not a variable a topic may use | Left as written, and the web app warns about them. A topic with no usable variable is one topic, published exactly as written. |
What counts as no value:
- an Id part past the last
|, or with nothing between two bars -A||Bhas no{tagIdPart2}, - a level no group above the tag has,
- a group variable, such as
{groupPath},{groupName}or{hierarchyPath}, on a tag that is in no group, - an unset
{workCenterType}or{workUnitType}, - an empty property,
{schemaName}with Output FormatDefault,- on the broker and in Data Test opened from the library,
{driverName}, - on the broker,
{tagSeq0}and{tagSeq1}, - on Snowflake,
{topic},{schemaName},{seq0}and{seq1}.
The variables
The examples are for the tag Acme.Dallas.Plant.Line1.Speed.Value, where:
- the groups
Acme,Dallas,PlantandLine1have the ISA-95 levels Enterprise, Site, Area and Work Center, - the site's ID is
DAL, - the tag's Units property is
rpm, - the tag is listed in a driver's Tags To Publish with the Id
SPD-01|Hall_A.
Topic says whether Publish Topic Id accepts the variable; the ones it does not accept change with every value or every message. MQTT only means Kafka accepts the variable too, but it always gives a /, which a Kafka topic may not hold, so on Kafka the tag is never published.
The tag
| Variable | Gives | Example | Topic |
|---|---|---|---|
{tagName} | The tag name with its variable | Speed.Value | Yes |
{tagShortName} | The tag name alone | Speed | Yes |
{variable} | The tag variable | Value | Yes |
{tagPath} | The full path, dotted | Acme.Dallas.Plant.Line1.Speed.Value | Yes |
{tagPathSlash} | The full path, with each group a level | Acme/Dallas/Plant/Line1/Speed.Value | MQTT only |
{tagId} | The Id the tag is published under, from the driver's Tags To Publish | SPD-01|Hall_A | Yes |
{tagIdPart1}, {tagIdPart2}, … | The parts of that Id between |, counted from 1, without the spaces around them | SPD-01, Hall_A | Yes |
{property:Name} | A tag property by name, as the Custom Property... mapping reads it. The name keeps its case and its spaces | {property:Units} gives rpm | Yes |
{dataType} | The data type of the value: BOOLEAN, INT, LONG, FLOAT, DOUBLE or STRING | DOUBLE | No |
{value} | The value as text. Empty when the quality is bad, and still sent | 1450 | No |
{quality} | true or false | true | No |
{timestampUnixMs} | The value's timestamp, in Unix milliseconds | No | |
{timestampUnixSec} | The value's timestamp, in Unix seconds | No | |
{timestampIso} | The value's timestamp, in ISO 8601 | No |
One entry of a tag array or tag map
These work only inside a tag array or tag map. Anywhere else they are an error.
| Variable | Gives | Topic |
|---|---|---|
{seq0}, {seq1} | The entry's position in this message, from 0 or from 1. It starts again in every message, so the same number can be a different tag in the next message | No |
{tagSeq0}, {tagSeq1} | The tag's fixed position in the driver's Tags To Publish, from 0 or from 1. The same tag has the same number in every message. A tag listed more than once has the number of its first listing | No |
For a number that must always mean the same point, such as pointID_{tagSeq1}, use {tagSeq1}.
The tag's group
| Variable | Gives | Example | Topic |
|---|---|---|---|
{groupPath} | The group path, dotted | Acme.Dallas.Plant.Line1 | Yes |
{groupPathSlash} | The group path, with each group a level | Acme/Dallas/Plant/Line1 | MQTT only |
{groupName} | The tag's own group | Line1 | Yes |
{groupLevel1}, {groupLevel2}, … | The group at that depth, counted from the top. No value below the tag's own group | Acme, Dallas | Yes |
{enterprise}, {site}, {area}, {workCenter}, {workUnit}, {equipmentModule}, {controlModule} | The nearest group above the tag with that ISA-95 level: its export name override, or its name | {area} gives Plant | Yes |
{siteId}, {workUnitId}, {equipmentModuleId}, {controlModuleId} | That group's ID, or its name when the ID is empty | {siteId} gives DAL | Yes |
{workCenterType}, {workUnitType} | That group's type | Yes | |
{hierarchyPath} | The groups above the tag that have a level, top down, dotted, with overrides applied | Acme.Dallas.Plant.Line1 | Yes |
{hierarchyPathSlash} | The same, with each group a level | Acme/Dallas/Plant/Line1 | MQTT only |
The group path variables use the groups' real names. The level and hierarchy variables use a group's export name override when it has one, and give the same text as the Hierarchy mapping.
The message and the system
| Variable | Gives | Topic |
|---|---|---|
{driverName} | The driver interface's name | Yes |
{hostName} | The name of the machine OAS runs on | Yes |
{schemaName} | The schema's record name, in lower case with spaces as hyphens: isa-95-lite on a driver set to ISA-95 Lite. A driver keeps its own copy of a schema, not the name it was loaded under in the library. Only with Output Format ISA-95 Lite or Custom AVRO Schema; with Default it has no value, so a topic that uses it publishes nothing | Yes |
{topic} | The topic the message is published on | No |
{tagCount} | The number of tags in the message | No |
{uuid} | A new identifier for each message, the same wherever it is used in that message | No |
{publishTimeUnixMs}, {publishTimeUnixSec}, {publishTimeIso} | The time of the publish, the same in every message of one publish | No |
Where a variable may be used inside a schema
When a message holds many tags, a field outside the tag array or tag map is built once for the whole message:
- it may use the group, message and system variables,
- a tag or entry variable there is an error, just as mapping that field to a tag's value is,
- a group variable there means one message per group.
MQTT driver
- Topic. A Publish Topic Id that holds a variable a topic may use is a topic pattern. Each tag goes to the topic the pattern gives it, and tags of one publish that share a topic share a message. This works with every Output Format, including
Default. The topic a tag gets may not contain+or#. The slash variables give one topic level per group. Topics are worked out again once a minute, so a renamed group or a changed property is followed within a minute, without a restart. - Message. Variables are read in a schema only with Output Format
ISA-95 LiteorCustom AVRO Schema. TheDefaultpayload has no variables. - Many tags in one message. With Publish All Tags As One Topic on, Batched Messages on and a schema with a tag array or tag map,
{seq0},{seq1}and{tagCount}count the tags in the message. A message is split by Max Tags Per Publish, and by group when a field outside the tag array reads a group variable. - Several Ids. A tag listed in Tags To Publish under several Ids gives one entry per Id, each with its own
{tagId}and parts, when the mapping or the topic reads the Id. A tag map whose key does not read the Id keeps the last Id, and that is logged once for the tag. A pattern that reads the Id gives each Id its own topic.
Kafka driver
- Topic. A topic pattern works as it does on MQTT, including the refresh once a minute, and the Kafka topic is created under the filled-in name. The topic a tag gets must also be a legal Kafka topic name: 1 to 249 characters of
A-Z,a-z,0-9,.,_and-, and not.or... A tag whose topic breaks the rule is not published, and System Errors gets one entry for it. The line under Publish Topic Id in the web app warns about it before you apply. In practice:- use
{groupPath},{tagPath}or{hierarchyPath}- their slash forms always fail, - a group, tag or override name with a space, or any character outside that set, fails,
{property:Name}fails when the property's value holds such a character.
- use
- Message. As on MQTT, variables are read only with
ISA-95 LiteorCustom AVRO Schema. TheDefaultmessage, with or without a Schema Registry, has no variables. - Many tags in one message. Only with
Custom AVRO Schema, a tag array or tag map, Batched Messages on and Publish All Tags As One Topic on. Otherwise every message holds one tag, so{seq0}is0,{seq1}is1and{tagCount}is1. - Subject Name. Variables are not allowed. The schema is registered once, when the driver connects, under that one name, and every topic's messages carry its ID. With a topic pattern and Enable Schema Registry on, the name is required: left blank, the driver does not connect, raises a schema alarm, and the web app shows an error on the setting. A subject for each topic is not supported.
- Several Ids. As on MQTT.
MQTT broker
The broker reads variables in the library schema a client names, on a schema topic such as Sine.Value/plant-a-v2 or a $schema/ group topic such as $schema/plant-a-v2/Plant/Line1/+. It has no Tags To Publish list and no driver name, so a few variables give something else - see What differs.
A $schema/ group topic that sends one message per tag gives what a schema topic gives, except {topic}, which is the tag's group topic.
One message per group, under $schema/default/ or with a schema that has a tag array or tag map ($schema/line-batch/Plant/Line1), gives:
| Variable | One message per group |
|---|---|
{topic} | The group's topic, $schema/line-batch/Plant/Line1, not the filter subscribed to |
{schemaName} | The schema's name in the library, in lower case with spaces as hyphens (line-batch for Line Batch), not its record name |
{tagCount} | The tags in that message. When Group Max Tags Per Message splits the group, the tags in that part |
{seq0}, {seq1} | The tag's position in the message |
{tagSeq0}, {tagSeq1} | No value: the broker has no list, so the tag is left out |
{tagId}, {tagIdPart1} | The tag's path, Plant.Line1.Speed.Value |
{driverName} | No value, so the message is not sent |
{publishTimeUnixMs} and the other two | The time the message is built |
Snowflake driver
A column's value can be a Custom Format: in the Column Mapper, set the column's source to Custom Format and write text and variables, such as {site}-{tagName}. Each row is filled for its own tag, and the result goes into the column as text, so the Column Mapper sets the column's type to STRING. See Custom Format in the Snowflake Config Reference.
A column name cannot hold a variable. It is the table's column, used exactly as written, and a column name with braces is an error in the Column Mapper and in the driver's settings.
A row is one tag with no message around it, so a few variables give something else:
| Variable | Snowflake driver |
|---|---|
{tagId}, {tagIdPart1} | The Id in Tags To Publish |
{tagSeq0}, {tagSeq1} | The position in Tags To Publish |
{driverName} | The driver interface's name |
{uuid} | A new identifier for each row, the same in every column of that row |
{publishTimeUnixMs} and the other two | The time of the publish, the same for every row it sends |
{seq0}, {seq1}, {topic}, {schemaName} | No value, so the row is not sent. The Column Mapper does not offer them, and shows an error if one is typed |
{tagCount} | Always 1. The Column Mapper does not offer it |
A row left out because a variable has no value is logged once in System Errors, naming the variable and the tag. A Constant is still sent exactly as typed, braces included.
What differs between the drivers and the broker
Every variable not listed here gives the same text wherever it is read.
| Variable | MQTT driver | Kafka driver | MQTT broker, schema topic |
|---|---|---|---|
{tagId}, {tagIdPart1} | The Id in Tags To Publish | The Id in Tags To Publish | The tag's path (Sine.Value): the broker has no Id list |
{tagSeq0}, {tagSeq1} | The position in Tags To Publish | The position in Tags To Publish | No value: the broker has no list, so the tag is left out |
{seq0}, {seq1} | The position in the message | The position in the message when it holds many tags; otherwise 0, 1 | 0, 1: one tag per message |
{tagCount} | The tags in the message | The tags in the message when it holds many tags; otherwise 1 | 1 |
{driverName} | The driver interface's name | The driver interface's name | No value, so the message is not sent |
{schemaName} | The schema's record name | The schema's record name | The schema's record name |
{topic} | The topic published on: Publish Topic Id, the topic its pattern gives, or the tag's own topic | With a topic per tag, that topic, each Id of a tag listed more than once getting its own. With all tags in one topic, Publish Topic Id as written, or the topic its pattern gives | The topic as subscribed to and published (Sine.Value/plant-a-v2). On a group topic, the tag's group topic ($schema/plant-a-v2/Plant/Line1/Speed.Value), not the filter subscribed to |
{publishTimeUnixMs} and the other two | The time of the publish | The time of the publish | The time the message is built |
| The topic itself | Publish Topic Id, with + and # refused | Publish Topic Id, with the Kafka name rules | The client's subscription |
Where next
- Message Schemas - the schema library, the schema editor, and tag arrays and tag maps.
- MQTT Config Reference - topic patterns and Batched Messages on the MQTT driver.
- Kafka Config Reference - topic patterns and the Schema Registry on the Kafka driver.
- MQTT Broker - schema topics, group topics and one message per group.
- Snowflake Config Reference - the Column Mapper.
