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

description: >
  Service commissioning file migrated from the HiveMQ Edge protocol
  adapter line1-modbus (Example)

metadata:
  name: HiveMQ Edge Migration Example
  provider: cybus
  homepage: https://www.cybus.io
  version: 1.0.0

parameters:
  modbusHost:
    description: Host of the adapter line1-modbus
    type: string
    default: 192.168.1.100

  modbusPort:
    description: Port of the adapter line1-modbus
    type: integer
    default: 502

resources:
  # HiveMQ Edge protocol adapter "line1-modbus"
  line1ModbusConnection:
    type: Cybus::Connection
    properties:
      protocol: Modbus
      targetState: connected
      connection:
        host: !ref modbusHost
        port: !ref modbusPort

  # Tag "line1-temperature": HOLDING_REGISTERS, startIdx 0, INT_16, unit 1
  line1Temperature:
    type: Cybus::Endpoint
    properties:
      protocol: Modbus
      connection: !ref line1ModbusConnection
      subscribe:
        fc: 3
        address: 0
        length: 1
        dataType: int16BE
        interval: 1000

  # Northbound mapping: topic reused verbatim
  # publishChangedDataOnly was enabled: only publish on change of value
  mapping:
    type: Cybus::Mapping
    properties:
      mappings:
        - subscribe:
            endpoint: !ref line1Temperature
          publish:
            topic: factory/line1/temperature
          rules:
            - cov:
                key: value
