For the complete documentation index, see llms.txt. This page is also available as Markdown.

Cybus::Endpoint

Defining and managing data endpoints.

A Cybus::Endpoint resource represents the address of a single data endpoint in the context of a specific protocol. Each endpoint is always mapped to exactly one internal MQTT topic.

The MQTT topic can either be:

  • Explicitly defined using the topic property, or

  • Automatically generated (see note at topic).

In most services, endpoint topics are further mapped via a Cybus::Mapping resource to application-specific topics, which can then be consumed by dashboards, applications, or other services.

The actual protocol-specific data address is configured under the subscribe, read, or write properties. These properties are one level deeper in the YAML structure (beneath endpoint subscribe/read/write) and must not be confused with properties defined directly on the endpoint resource itself.

Operation Results

Endpoints of type read and write publish the results of their operations on an additional MQTT topic with the suffix /res:

  • A read endpoint named myEndpoint listens for requests on the MQTT topic myEndpoint/req and publishes the result on myEndpoint/res.

  • A write endpoint named myEndpoint listens for messages on the MQTT topic myEndpoint/set and publishes the result on myEndpoint/res.

To match a result to your request, add an id to the request. Whether the result contains this id depends on the protocol, and SQL reads accept an id only in one case, see Result Format per Protocol.

{ "id": "29194" }

If the endpoint has rules, Connectware applies them to the result before publishing it.

Result Format per Protocol

Each protocol defines the format of its results. The following table lists the properties of a successful result. A result contains id only where its cell lists it, and then only if your request contains one.

Protocol

read result

write result

timestamp, value, id

timestamp, value (true), id

value, timestamp, id

Empty message

id, value, timestamp

id, timestamp

id, timestamp, value

Not supported

timestamp, result, id (null if your request has none)

Same as read

timestamp, id, value

timestamp, id, value

The query result as an array of rows

value (true), timestamp

Not supported

id (null if your request has none), timestamp, result

timestamp, value. Without dataType, the raw bytes.

The Modbus response

Not supported

Empty message

timestamp, value

id, timestamp, value (true)

timestamp, value

Empty message

The OPC UA data value. For a batch, values, id.

id, timestamp, result

Not supported

id, timestamp, result (true)

timestamp, value, id

timestamp, result (true)

Not supported

Not supported

id, timestamp, result

Empty message

The SOPAS telegram

Empty message

timestamp, value, and id if the query has an $id placeholder

id, timestamp, value (true)

state, resourceId, timestamp

Not supported

Not supported

Not supported

An SQL read request can contain only the values for the placeholders of the query. Add an id only if the query uses an $id placeholder, otherwise the read fails.

Failed Operations

What Connectware publishes when an operation fails depends on the protocol:

  • An empty message, that is, an MQTT message without payload. Protocols that answer a successful write with an empty message answer a failed write the same way.

  • A result with an error property. error is a message string or an object with message and code. For HTTP/REST endpoints, ADS reads, and OPC UA writes and method calls, the publishError property controls the format. OPC UA batch endpoints always include the error object.

  • For OPC UA, a result with a Bad status code. See OPC UA.

Connectware processes requests on /req and /set while the connection of the endpoint is up. A write endpoint with buffering also accepts messages while the connection is down and publishes the results once it writes the buffered messages. Use a timeout in your application when it waits for a result.

Polling Interval and Subscribe

When an endpoint should subscribe to some data point on the device, it should be defined with the subscribe operation. Some protocols support such a subscription directly (e.g., OPC UA), whereas others only support regular polling the data point from the Connectware side. Depending on the available choices, the actual behavior can be chosen by the properties in the subscribe / read / write section.

If the endpoint is set to polling, there is the choice between specifying an interval or a time schedule expression for polling from the Connectware side.

  • An interval specifies the waiting time between subsequent polls. There is no guarantee on the exact time interval, only that on average the time interval should be matched. For example, if the protocol needed longer for one interval, the next one will be chosen shorter. Typical numbers for specified time intervals of 1000 milliseconds are actual intervals in the range of 950 to 1050 milliseconds, but this also strongly depends on the protocol and device behavior.

  • A time schedule expression is specified in the cronExpression syntax, see https://github.com/node-cron/node-cron, for example "0 * * * *" for “every hour at the 00 minute, such as 00:00h, 01:00h, 02:00h, and so on. In this case, there is no guarantee on the exact time when data is received, but one polling will be triggered for each time expression match. So it can be relied on receiving 24 polling results per day if “once per hour” has been specified in the cronExpression.

For any subscribe endpoint in the protocols where polling is available, you can either specify an interval, or a cronExpression (which takes precedence over the interval property), or neither, in which case interval will be used with its default value.

Endpoint Properties

Property
Type
Required

enum

Required

string

Required

object

Optional*

object

Optional*

object

Optional*

object[]

Optional

integer

Optional

boolean

Optional

enum

Optional

string

Optional

string

Obsolete

object

Optional

object

Optional

boolean

Optional

* One out of subscribe, read, and write is required.

protocol

Identifies the protocol for which a connection should be established.

  • Required

  • Type: enum

The value of this property must be equal to one of the following:

  • Ads

  • Bacnet

  • EthernetIp

  • Focas

  • Heidenhain

  • Http

  • Influxdb

  • Influxdb3

  • Kafka

  • Modbus

  • Mqtt

  • Mssql

  • Opcda

  • Opcua

  • Openprotocol

  • S7

  • S7plus

  • Shdr

  • Sinumerik

  • Sopas

  • Sql

  • Systemstate

  • Werma

connection

Reference to a Cybus::Connection resource.

  • Required

  • Type: string

subscribe / read / write

rules

You may specify rules to your payload here before sending it to the internal broker for the first time.

qos

MQTT Quality of Service (QoS) for the internal messaging from Endpoint to the internal MQTT broker.

If this endpoint runs on an agent, setting this to 1 instead of the default 0 will activate the simple buffering of MQTT client implementations.

A non-zero QoS also protects data flow during short outages of the internal broker itself, not only during agent-to-Connectware disruptions. When the broker connection is lost, the machine subscription remains active and incoming data is buffered locally until the broker is reachable again.

  • Optional

  • Type: integer, must be one of 0, 1, 2

  • Default: 0

retain

Whether the last message should be retained (last-value-cached) on the internal MQTT broker.

If this endpoint runs on an agent, setting this to true instead of the default false might be useful in certain applications to have some value on the topic if the agent disconnects. However, in other applications this might not make sense.

  • Optional

  • Type: boolean, must be one of true, false

  • Default: false

targetState

The state this resource should be in after startup.

  • Optional

  • Type: enum, must be one of enabled, disabled

  • Default: enabled

topic

Explicit topic name to which this endpoint address should be mapped.

services/<serviceId>/<topic>

See the explanation at Cybus::MqttRoot if alternative topic structures are needed.

Providing a custom topic and avoiding an additional mapping resource improves overall performance as the message has to travel one hop less. Endpoints with custom topics can still be mapped using a regular mapping (see Cybus::Mapping).

  • Optional

  • Type: string

agentName

Obsolete. This value is no longer being used. The agentName of the referenced connection is always used if this connection and endpoint are being used on an agent instance, separate from Connectware.

buffering

The buffering section can optionally switch on output data buffering on write endpoints. With this feature, it is possible to enable output buffering on write operations for when the connection to the device is lost, in order to avoid data loss.

The buffering mechanism kicks in when a device disconnection is detected and will start buffering any incoming values. It also engages when an individual write operation fails with a timeout or write error while the connection is still reported as connected, so that transient write failures do not cause data loss. After the connection is reestablished, buffered messages will be written to the machine ("flushed").

The flushing of the buffer is implemented to handle subsequent disconnections during flushing correctly. In such a case, newly incoming values will be buffered, too. Once the connection is reestablished, the flushing will continue where it left off.

The write buffer is owned by the endpoint. If the endpoint is destroyed as part of a service update, any messages still in its buffer at that moment are discarded and not flushed to the device.

By default, this feature is switched off. To enable it, the property enabled must be set to true, and most likely additional properties should be set according to the expected behavior in the actual application scenario. The supported properties of buffering are:

  • enabled (default: false): Whether buffering should be enabled or not when the connection to the source device is lost.

  • keepOrder (default: true): Whether to keep the order of messages when going into redelivery mode after an endpoint comes back online.

  • burstInterval (default: 100): Time in milliseconds to wait between each re-publishing of buffered messages after connection is re-established.

  • burstSize (default: 1): The number of messages to send in one burst when flushing the buffer upon re-connection.

  • bufferMaxSize (default: 100000): The max number of messages to be buffered. Older messages are deleted when this limit is reached.

  • bufferMaxAge (default: 86400, one day): The number of seconds the buffered data will be kept. If messages have been buffered for longer than this number of seconds, they will be discarded.

The keepOrder property, which is switched on by default, will keep the order of arriving messages when a flush of the buffer is in progress. This will delay newly arriving messages until all the buffered messages have been sent.

For example, if we had the values 1, 2, 3, 4 in the buffer, the buffer starts the flushing of values after a reconnection, and the values 5, 6 are received in the meantime, then the machine will get the values in that exact order 1, 2, 3, 4, 5, 6. If this property was set to false and the same scenario is replicated, the order of arrival of the new values is unspecified and the end result would be an interleaved set of values, for example: 1, 5, 2, 3, 6, 4.

inputBuffering

The input data to each endpoint can optionally be managed through an individual input buffer (also called input queue) to establish fine-grained control for high data rate behavior. By default, this input buffering is disabled and instead all input data is handled on the global event queue, which works fine as long as there is no risk of out-of-memory exceptions due to unexpected slow data processing or forwarding.

When enabling the individual input buffer, the buffer properties determine the behavior in situations when the input buffer is filling up. The buffer is filling up when the message arrival rate is larger than the processing data rate or the forwarding (publishing) data rate. Or, in other words, the input buffer is filling up if the messages arrive faster than how they can be processed or be forwarded (published). If this situation happens for longer time durations, the input buffer will reach its configured capacity limits and arriving messages will be dropped, so that the system will not run into an uncontrollable out-of-memory exception. This is a fundamental and unavoidable property of distributed systems due to its finite resources. But the actual behavior of the input buffer can be adapted to the actual application scenario by setting the properties in the inputBuffering section (optional).

Supported properties are (all optional):

  • enabled (type: boolean, default: false): Enable or disable input buffering.

  • maxInputBufferSize (type: integer, default: 5000): Maximum number of input messages that are queued in the input buffer. Exceeding messages will be discarded. Adjust this to a higher value if you are handling bursty traffic.

  • maxConcurrentMessages (type: integer, default: 2): Maximum number of concurrently processed messages as long as the input buffer queue is non-empty.

  • waitingTimeOnEmptyQueue (type: integer, default: 10): Waiting time in milliseconds after the input buffer queue ran empty and before checking again for newly queued input messages. Regardless of this value, on non-empty input buffer queue all messages will be processed without waiting time in between until the queue is empty again.

publishError

Whether Connectware publishes a failed read or write operation on the /res topic as an error object with message and code. Set it to true when you use the endpoint in a FlowSync flow.

  • Optional

  • Type: boolean, must be one of true, false

  • Default: false

publishError has an effect on HTTP/REST endpoints, on ADS reads, and on OPC UA writes and method calls:

Operation

publishError: false

publishError: true

HTTP/REST read

The result is an empty message.

The result contains an error object.

HTTP/REST write

The result contains error as a string with the message.

The result contains an error object.

ADS read

The result is an empty message.

The result contains an error object.

OPC UA write and method calls

The result contains the status code in result and no error.

The result also contains an error object.

An OPC UA batch endpoint ignores publishError. It always includes the error object when it rejects a message or aborts a batch.

The following result of an HTTP/REST read endpoint contains an error object:

For the complete result formats, see HTTP/REST and OPC UA.

Examples

BACnet

OPC UA

MQTT with Write Buffering Enabled

Last updated

Was this helpful?