# Examples

# Configuration

Before starting integration process Public MQTT API should be configured. See User Interface Options chapter of Gateway Programming Guide.

To do this - enter configuration mode on gateway shell and set basic parameters.

# Setup MQTT Port and Authentication

set public-mqtt authentication username "public"
set public-mqtt authentication password "password"
set public-mqtt port 11883
commit
save

Resulting configuration tree will be:

{
    public-mqtt {
        port 11883
        authentication {
            username "public"
            passsword ********
        }
    }
}

# Enable public API for devices

set public-mqtt devices electrolyser-v21 ELID1 enabled true
set public-mqtt devices electrolyser-v21 ELID2 enabled true
set public-mqtt devices dryer DR1 enabled true
commit
save

Resulting configuration tree will be:

{
    public-mqtt {
        devices {
            electrolyser-v21 ELID1 {
                enabled true
            }
            electrolyser-v21 ELID2 {
                enabled true
            }
            dryer DR1 {
                enabled true
            }
        }
    }
}

# Define variables

set public-mqtt variable target-pid-pressure type float
commit
save

Resulting configuration tree will be:

{
    public-mqtt {
        variable target-pid-pressure {
            type float
        }
    }
}

# Receiving device telemetry

  1. Connect to mqtt on gateway ip address, specified port, with specified username & password,
  2. Subscribe to telemetry topic
mosquitto_sub -d -v -p 11883 -h 192.168.1.1 -u public -P password -t "telemetry/v1/ELID1"

# Set variable value

  1. Connect to mqtt on gateway ip address, specified port, with specified username & password,
  2. Publish message to set variable topic
mosquitto_pub -p 11883 -h 192.168.1.1 -u public -P password -t "telemetry/v1/ELID1" -m "{ \"value\": 30.5 }"

# Command variables

Variables can be used to execute commands.

For example electrolysers can be started once when variable set to true.

  1. Define variable
set public-mqtt variable start-els type bool
commit
save
  1. Activate ELs and dryers plugins
set rule-engine plugin electrolyser-v21 enabled true
commit
save
exit
  1. Configure devices in rule engine
set rule-engine devices electrolyser-v21 EL1ID enabled true
set rule-engine devices electrolyser-v21 EL1ID power 2400
set rule-engine devices electrolyser-v21 EL2ID enabled true
set rule-engine devices electrolyser-v21 EL2ID power 2400
  1. Add rule to activate ELs when variable set to true
set rule-engine rule 1-start-els condition 1 variable run-all-els compare-operator eq
set rule-engine rule 1-start-els condition 1 variable run-all-els value "true"
set rule-engine rule 1-start-els action 1 start-electrolyser device ELID1
set rule-engine rule 1-start-els action 2 start-electrolyser device ELID2
set rule-engine rule 1-start-els action 3 set-variable run-all-els value-lua "false"

Resulting configuration tree will be:

{
    public-mqtt {
        variable run-all-els {
            type bool
        }
    }
    rule-engine {
        rule 1-start-els {
            condition 1 {
                variable run-all-els {
                    compare-operator eq
                    value true
                }
            }
            action 1 {
                start-electrolyser {
                    device ELID1
                }
            }
            action 2 {
                start-electrolyser {
                    device ELID2
                }
            }
            action 3 {
                set-variable run-all-els {
                    value-lua "false"
                }
            }
        }
    }
}