---
# ----------------------------------------------------------------------------
# Service Commissioning File
# ----------------------------------------------------------------------------
# Copyright: Cybus GmbH
# Contact: support@cybus.io
# ----------------------------------------------------------------------------
# Migrating from OPC Router (Example)
# ----------------------------------------------------------------------------

description: >
  Service commissioning file migrated from the OPC Router flow
  "Press to UNS" (Example)

metadata:
  name: OPC Router Migration Example
  provider: cybus
  homepage: https://www.cybus.io
  version: 1.0.0

parameters:
  opcuaHost:
    description: Host of the OPC UA plug-in instance
    type: string
    default: 192.168.1.100

  opcuaPort:
    description: Port of the OPC UA plug-in instance
    type: integer
    default: 4840

definitions:
  MQTT_TOPIC_PREFIX: press-to-uns

resources:
  # OPC UA plug-in instance (SecurityPolicy None)
  opcuaConnection:
    type: Cybus::Connection
    properties:
      protocol: Opcua
      targetState: connected
      connection:
        host: !ref opcuaHost
        port: !ref opcuaPort
        options:
          securityPolicy: None
          messageSecurityMode: None

  # Transfer object item bp=4:Machines/5:Press/7:State/5:Speed;
  # Time trigger period 10000 ms becomes the sampling interval
  pressSpeed:
    type: Cybus::Endpoint
    properties:
      protocol: Opcua
      connection: !ref opcuaConnection
      subscribe:
        browsePath: 4:Machines/5:Press/7:State/5:Speed
        samplingInterval: 10000
        publishInterval: 10000

  # Transfer object item bp=4:Machines/5:Press/7:State/9:PiecesOut;
  pressPiecesOut:
    type: Cybus::Endpoint
    properties:
      protocol: Opcua
      connection: !ref opcuaConnection
      subscribe:
        browsePath: 4:Machines/5:Press/7:State/9:PiecesOut
        samplingInterval: 10000
        publishInterval: 10000

  mapping:
    type: Cybus::Mapping
    properties:
      mappings:
        - subscribe:
            endpoint: !ref pressSpeed
          publish:
            topic: !sub '${MQTT_TOPIC_PREFIX}/speed'
        - subscribe:
            endpoint: !ref pressPiecesOut
          publish:
            topic: !sub '${MQTT_TOPIC_PREFIX}/pieces-out'
