GAT Example: Water Tank: Automation Program, Remote Controlling and Notification

 In this example we will deal with a water tank,
which is a typical case of remote installation with needs for remote control
and immediate notification of the persons in charge if something goes wrong.

To implement the needed functionality we will use both the ready-made functions
and the "GAT Automation Language" provided by the GAT device.

 

  GAT-1 example #3 preview

The scenario of this application is as follows:

 The tank is equipped with a level sensor
with voltage output in the range of 0,0 to 10,0V for water level in the range of 0,0 to 2,5m.
The sensor output is connected to Input #1 of the GAT device.

There is also a water pump used to fill the tank
and a drain valve, used for watering.
These two are controlled by the relay outputs of the GAT device.

The functionality provided is as follows:

  • The GAT device is used to measure the water level in the tank
    and control the drain valve and filling pump,
    according to some water level presets 
    which can be set by the administrator. 

    There are 3 water level presets:
    GAT-1 example #3 Tank Levels
      * The level "Upper" is the maximum level
      at which the filling pump stops working.

      * The level "Fill" is lower than the level "Upper",
      and is where the filling pump starts working.

      * The level "Lower" is the minimum allowed water level
      at which the GAT device will close the drain valve if it's open
      and send to the administrator a warning message, like below:
        2022/09/16,18:13:26
        WATER-TANK #1 LEVEL:0.12m
        WATER LEVEL LOW ! 

  • The adminstrator can setup / query the above mentioned water levels via messages.
    The administrator can send a message to setup all three water levels, like below:
        LEVEL
        UPPER 240
        FILL 160
        LOWER 15

    The above message sets the  "Upper", "Fill" & "Lower"  levels
    to  2.40, 1.60 & 0.15  meters respectivelly.

    The administrator can query the water level parameters, 
    by sending the following message:
        LEVEL

    The administrator can change only some of the water level parameters, like:
        LEVEL FILL 160

    In all cases, when the message is starting with the word  "LEVEL",
    the device answers with a message like below:
        2022/09/06,18:14:21
        WATER-TANK #1 LEVEL:1.25m
        LEVEL SETUP:
        UPPER=2.40m
        FILL=1.60m
        LOWER=0.15m


  • The administrator can control or query the pump automation state with messages.
    He can activate the pump automation by sending the message:
        PUMP AUTO ON

    He can stop the pump automation by sending the message:
        PUMP AUTO OFF

    He can query the pump automation state by sending the message:
        PUMP AUTO

    In all cases, when the message is starting with the words "PUMP AUTO",
    the device answers with a message like below:
        2022/09/06,18:27:43
        WATER-TANK #1 LEVEL:1.50m
        PUMP AUTOMATION IS ON


  • The administrator can control or query the drain valve state with messages.
    He can start watering, by sending the message:
        DRAIN ON 15

    With the above message the drain valve will open and stay so for 15 minutes.
    This duration will be stored by the device as parameter.
    After this, the administrator can send a message like:
        DRAIN ON

    and the device will open the drain valve again for 15 minutes.
    The administrator can close the drain valve immediatelly, by sending the message:
        DRAIN OFF

    The administrator can query the current state of the drain valve, by sending the message:
        DRAIN

    In all cases, when the message is starting with the word "DRAIN",
    when the valve is active the device answers with a message like:
        2022/09/06,18:29:23
        WATER-TANK #1 LEVEL:1.50m
        DRAIN VALVE ON, duration: 5 minutes

    and when the valve is off the device answers with a message like:
        2022/09/06,18:30:34
        WATER-TANK #1 LEVEL:1.50m
        DRAIN VALVE OFF


  • The administrator is able to check the GAT device with an unanswered telephone call. 
    If the device is functioning properly, it will answer with a telephone call to the administrator.


The above descripted functionality is implemented with the following "GAT Application Program":

; Water-Tank example with Automation Program
; Device: GAT-1 or GAT-2
;

;~ FPwizard 09/05/22,22:22:49
;~ device: GAT-2

;~ Telephone Numbers list with 1 clients
TN
1111111111
;~ #1 Administrator

;~ Inputs
;~ I1: WATER LEVEL

IT 1 20 ;~ I1 'WATER LEVEL' reaction Time: 2.00 sec
AIC 1 0 250 ;~ Input #1 'WATER LEVEL' Analog Calibration: Offset=0, Factor=250
AIT 1 30 150 ;~ I1 'WATER LEVEL' Analog Thresholds, Low=30, High=150

;~ Outputs
;~ O1: FILL PUMP
;~ O2: DRAIN VALVE

;~ Extras
HD "%D,%T%nWATER-TANK #1 LEVEL:%fA1m" ;~ Message Header
TCA 1 ;~ Telephone Call Answer mode

;~ FPwizard end

;--------------------------------
;Automation Program definitions
;
def LEVEL A1 ;Water Level Analog input
;
def PUMP_OUT O1 ;Water Fill Pump control output
def DRAIN_OUT O2 ;Water Drain Valve control output
;
def PUMP_AUTOMATION B1 ;Water Level Automation "switch"
;
;Parameters
def LEVEL_UPPER N1
def LEVEL_FILL N2
def LEVEL_LOWER N3
def DRAIN_DURATION N4
;Drain Valve active duration in minutes
;
def DRAIN_ACTIVE TE1 ;TIMER #1 ENABLE is used as "Drain Valve Active" flag
def DRAIN_ACTIVE_TC TC1 ;TIMER #1 COUNT is the "Drain Valve Active" time count

;GAT Automation Program code start

P( ;Prolog module, executed once
  ;declare the Non Volatile variables

  NVV( PUMP_AUTOMATION, 1, 8, 1 )
;the Pump Automation flag (B1)
  NVV( LEVEL_UPPER, 4, 8, 1 ) ;the 4 Parameters (N1..N4)
)

M( ;Main module, executed every 10msec
  ;INCOMMING MESSAGES PROCESSING
  ;------------------------------
  ; SETUP/QUERY the LEVEL PARAMETERS

  IF RMC( "LEVEL" )==1 ( ;INCOMMING MESSAGE STARTS WITH "LEVEL"
    IF RMC( "UPPER" ) ( ;INCOMMING MESSAGE CONTAINS "UPPER"
      RMN( LEVEL_UPPER, 1 ) ;SET the UPPER LEVEL PARAMETER
    )
    IF RMC( "FILL" ) ( ;INCOMMING MESSAGE CONTAINS "FILL"
      RMN( LEVEL_FILL, 1 ) ;SET the FILL LEVEL PARAMETER
    )
    IF RMC( "LOWER" ) ( ;INCOMMING MESSAGE CONTAINS "LOWER"
      RMN( LEVEL_LOWER, 1 ) ;SET the LOWER LEVEL PARAMETER
    )
    ;REPLY TO MESSAGE SENDER
    SM( 0, "LEVEL SETUP:%nUPPER=%fN1m%nFILL=%fN2m%nLOWER=%fN3m" )
  )
  ; SETUP/QUERY the PUMP AUTOMATION switch
  IF RMC( "PUMP AUTO" )==1 ( ;INCOMMING MESSAGE STARTS WITH ""PUMP AUTO"
    IF RMC( "ON" ) ( ;INCOMMING MESSAGE CONTAINS "ON"
      PUMP_AUTOMATION = 1 ;SET the PUMP_AUTOMATION switch
    )
    ELIF RMC( "OFF" ) ( ;INCOMMING MESSAGE CONTAINS "OFF"
      PUMP_AUTOMATION = 0 ;RESET the PUMP_AUTOMATION switch
    )
    ;REPLY TO MESSAGE SENDER
    IF PUMP_AUTOMATION (
      SM( 0, "PUMP AUTOMATION IS ON" )
    )
    ELSE (
      SM( 0, "PUMP AUTOMATION IS OFF" )
    )
  )
  ; CONTROL THE DRAIN VALVE
  IF RMC( "DRAIN" )==1 ( ;INCOMMING MESSAGE STARTS WITH "DRAIN"
    RMN( DRAIN_DURATION, 1 ) ;SET the DRAIN DURATION
    IF RMC( "ON" ) ( ;INCOMMING MESSAGE CONTAINS "ON"
      DRAIN_ACTIVE = 1 ;SET the DRAIN ACTIVE flag (enable TIMER #1)
      DRAIN_ACTIVE_TC = 0 ;RESET the DRAIN ACTIVE TIME COUNT (TIMER #1 COUNT)
    )
    ELIF RMC( "OFF" ) ( ;INCOMMING MESSAGE CONTAINS "OFF"
      DRAIN_ACTIVE = 0 ;RESET the DRAIN ACTIVE flag
    )
    ;
    ;REPLY TO MESSAGE SENDER
    IF DRAIN_ACTIVE (
      SM( 0, "DRAIN VALVE ON, duration: %N4 minutes" )
    )
    ELSE (
      SM( 0, "DRAIN VALVE OFF" )
    )
  )

  ;
  ;PUMP AUTOMATION
  ;----------------
  IF PUMP_AUTOMATION (
    IF LEVEL >= LEVEL_UPPER (
      PUMP_OUT = 0
    )
    ELIF LEVEL <= LEVEL_FILL (
      PUMP_OUT = 1
    )
  )
  ELSE ( ;NOT PUMP_AUTOMATION
    PUMP_OUT = 0
  )
  ;
  ;LOW WATER LEVEL CHECK
  ;----------------------
  def LOW_LEVEL_WARN_SENT B2 ;flag for the LOW-LEVEL WARNING MESSAGE
  ;

  IF LEVEL <= LEVEL_LOWER ( ;LOW LEVEL
    ;
    DRAIN_ACTIVE = 0 ;RESET the DRAIN ACTIVE flag
    ;
    IF !LOW_LEVEL_WARN_SENT ( ;IF NOT LOW-LEVEL WARNING MESSAGE SENT
      SM( 1, "WATER LEVEL LOW !" ) ;SEND LOW-LEVEL WARNING MESSAGE
      LOW_LEVEL_WARN_SENT = 1 ;SET the LOW-LEVEL WARNING FLAG
    )
  )
  ELIF LEVEL > (LEVEL_LOWER+10) ( ;LEVEL HIGHER than LEVEL_LOWER+10cm
    LOW_LEVEL_WARN_SENT = 0 ;RESET the LOW-LEVEL WARNING FLAG
  )
  ;
  ;DRAIN AUTOMATION
  ;-----------------
  IF DRAIN_ACTIVE a ( DRAIN_ACTIVE_TC < (DRAIN_DURATION*60) ) (
    ;DRAIN VALVE is ACTIVE and DRAIN TIME not passed yet
    DRAIN_OUT = 1 ;SET the DRAIN VALVE OUTPUT
  )
  ELSE (

    ;DRAIN VALVE is NOT ACTIVE or DRAIN TIME passed
    DRAIN_OUT = 0 ;RESET the DRAIN VALVE OUTPUT
    DRAIN_ACTIVE = 0 ;RESET the DRAIN ACTIVE flag
  )
)

;
APR 1 ;START THE AUTOMATION PROGRAM

 

This application program is uploaded to the device with about 10 successive messages,
while it needs about 8 seconds to upload locally via USB and 2..3 minutes to upload via SMS to a remote device.

  * * *

This application program is a demostration of the features of the GAT Automation Program,
which you can use as template for your application.