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

description: >
  Service commissioning file migrated from the UMH Core protocol
  converter press1-modbus (Example)

metadata:
  name: United Manufacturing Hub Migration Example
  provider: cybus
  homepage: https://www.cybus.io
  version: 1.0.0

parameters:
  # UMH variable IP
  plcHost:
    description: Host of the protocol converter press1-modbus
    type: string
    default: 192.168.1.100

  # UMH variable PORT
  plcPort:
    description: Port of the protocol converter press1-modbus
    type: integer
    default: 502

definitions:
  # agent.location + converter location: acme.cologne.packaging.press1
  MQTT_TOPIC_PREFIX: acme/cologne/packaging/press1

resources:
  # Protocol converter "press1-modbus" (modbus input)
  press1ModbusConnection:
    type: Cybus::Connection
    properties:
      protocol: Modbus
      targetState: connected
      connection:
        host: !ref plcHost
        port: !ref plcPort

  # Address "temperature.holding.100.INT16", timeBetweenReads 1 s
  # Verify the register base convention against live values.
  temperature:
    type: Cybus::Endpoint
    properties:
      protocol: Modbus
      connection: !ref press1ModbusConnection
      subscribe:
        fc: 3
        address: 100
        length: 1
        dataType: int16BE
        interval: 1000

  # Address "running.coil.5.BOOL", timeBetweenReads 1 s
  running:
    type: Cybus::Endpoint
    properties:
      protocol: Modbus
      connection: !ref press1ModbusConnection
      subscribe:
        fc: 1
        address: 5
        length: 1
        dataType: boolean
        interval: 1000

  mapping:
    type: Cybus::Mapping
    properties:
      mappings:
        - subscribe:
            endpoint: !ref temperature
          publish:
            topic: !sub '${MQTT_TOPIC_PREFIX}/temperature'
        - subscribe:
            endpoint: !ref running
          publish:
            topic: !sub '${MQTT_TOPIC_PREFIX}/running'
