---
# ----------------------------------------------------------------------------#
# Commissioning File
# ----------------------------------------------------------------------------#
# Copyright: Cybus GmbH (2020)
# Contact: support@cybus.io
# ----------------------------------------------------------------------------#
# Source Interface Definition - HTTP/REST endpoint
# ----------------------------------------------------------------------------#

description: >
  Sample commissioning file for communicating with HTTP/REST endpoint

metadata:
  name: Http Connectivity
  icon: https://www.cybus.io/wp-content/uploads/2017/10/for-whom1.svg
  provider: cybus
  homepage: https://www.cybus.io
  version: 0.0.1

parameters:

  httpHost:
    description: IP address of the HTTP Server
    type: string
    default: 192.168.0.1

  httpPort:
    description: HTTP port of the Server
    type: number
    default: 80

  initialReconnectDelay:
    type: integer
    default: 1000

  maxReconnectDelay:
    type: integer
    default: 30000

  factorReconnectDelay:
    type: integer
    default: 2

resources:

  httpConnection:
    type: Cybus::Connection
    properties:
      protocol: Http
      connection:
        scheme: https
        host: !ref httpHost
        port: !ref httpPort
        connectionStrategy:
          initialDelay: !ref initialReconnectDelay
          maxDelay: !ref maxReconnectDelay
          incrementFactor: !ref factorReconnectDelay

  base:
    type: Cybus::Endpoint
    properties:
      protocol: Http
      connection: !ref httpConnection
      subscribe:
        path: /

  counter:
    type: Cybus::Endpoint
    properties:
      protocol: Http
      connection: !ref httpConnection
      subscribe:
        path: /counter

  getPost:
    type: Cybus::Endpoint
    properties:
      protocol: Http
      connection: !ref httpConnection
      subscribe:
        path: /post

  writePost:
    type: Cybus::Endpoint
    properties:
      protocol: Http
      connection: !ref httpConnection
      write:
        path: /post

  httpMapping:
    type: Cybus::Mapping
    properties:
      mappings:
        - subscribe:
            endpoint: !ref base
          publish:
            topic: !sub '${Cybus::MqttRoot}/server/base'
        - subscribe:
            endpoint: !ref counter
          publish:
            topic: !sub '${Cybus::MqttRoot}/server/counter'
        - subscribe:
            endpoint: !ref getPost
          publish:
            topic: !sub '${Cybus::MqttRoot}/server/post'
        - subscribe:
            endpoint: !ref counter
          publish:
            endpoint: !ref writePost
