---
# ----------------------------------------------------------------------------
# Service Commissioning File
# ----------------------------------------------------------------------------
# Copyright: Cybus GmbH
# Contact: support@cybus.io
# ----------------------------------------------------------------------------
# Ignition Integration (Example)
# ----------------------------------------------------------------------------

description: >
  Service commissioning file for the integration between Connectware and
  Inductive Automation Ignition (Example)

metadata:
  name: Ignition Integration
  provider: cybus
  homepage: https://www.cybus.io
  version: 1.0.0

parameters:
  ignitionHost:
    description: Hostname or IP address of the Ignition gateway
    type: string
    default: 192.168.1.100

  opcuaPort:
    description: Port of the Ignition OPC UA server
    type: integer
    default: 62541

  opcuaUsername:
    description: Username for the Ignition OPC UA server
    type: string
    default: opcuauser

  opcuaPassword:
    description: Password for the Ignition OPC UA server
    type: string

resources:
  # Connection to the OPC UA server built into the Ignition gateway
  ignitionOpcuaConnection:
    type: Cybus::Connection
    properties:
      protocol: Opcua
      connection:
        host: !ref ignitionHost
        port: !ref opcuaPort
        username: !ref opcuaUsername
        password: !ref opcuaPassword

  # Reads exposed Ignition tags and publishes them to MQTT topics
  temperatureEndpoint:
    type: Cybus::Endpoint
    properties:
      protocol: Opcua
      connection: !ref ignitionOpcuaConnection
      topic: ignition/opcua/line-1/temperature
      subscribe:
        nodeId: 'ns=2;s=[default]Line1/Temperature'

  machineStateEndpoint:
    type: Cybus::Endpoint
    properties:
      protocol: Opcua
      connection: !ref ignitionOpcuaConnection
      topic: ignition/opcua/line-1/machine-state
      subscribe:
        nodeId: 'ns=2;s=[default]Line1/MachineState'

  # Republishes the plain JSON messages of the MQTT Transmission
  # UNS Transmitter under the ignition/uns topic hierarchy
  unsTopicMapping:
    type: Cybus::Mapping
    properties:
      mappings:
        - subscribe:
            topic: 'unsAv1.0/#topic'
          publish:
            topic: 'ignition/uns/#topic'
