Discover how Compas can monitor and control third party devices (Lua Scripting)

Here is a video describing how you can use our scripting tool to monitoring and control third party devices. You will understand why Compas is a site controller, and not only a dc system controller.

 

 

The Lua scripting system gives you a new efficient way to meet all your need. It can be used to: 

  • Create a new equipment with custom descriptions, alarms, data, records, parameters or controls.
  • Adding events
  • Setting all Compas data or setting function
  • sending emails - monitor other devices
  • (...) Other protocols (Modbus, one-wire...) and interfaces will follow with further version. Please, let us if you need something else in order to prioritize the development.

You have the possibility to execute different scripts in order to keep your system clean and functionality independent.

Here is a preview of the Compas User Guide, describing the Lua Scripting inside Compas:

Let's start to use your scripting system directly. It is accessible inside the files -> scripting path. We are going to create your first script: enter the command "new my_first_script" and press the Execute button. A new script will be created. With the screenshot below, you will see the main parts of Compas Scripting system.

  • A script manager
    • Scripts status and Command
    • Command window
    • A Script Manager: one line by script
  • A Script editor (press on the name of the script that you want to edit)
  • A Log that will log all errors or message printed by the system

Compas Lua Interface

Take a look to the script inside the script editor. Some comment explains you parts of the script. Let's decompose this script and understand what it does.

The Script

In the Lua language, comments are with two hyphens. Most of Lua embedded functions are available. If you need more specific information about Lua functions, just take a look to the Lua language.

The Initialization Part

As you can see, we will just print a text in the initialization. This is to show when the script is started. You can also see how functions are called in Lua and how you can concatenate strings and functions. Here we call the function print which will print text in the console box, the string is concatenated with the function compas.version_api(). This function is specific to compasLua, it will just return a string that contains the version number of the Lua API. (Functions added by Alpha to Lua Language)

The Loop Part

The loop part contains the function that will be called approximately every 10 seconds (configurable), in this case the initial content is just some basic text that will be shown inside the console. The loop function has to return the string "OK", so the system will assume that everything is OK. If there is a problem, you can return another string like "KO" that will record a problem inside the error system and alarms related to scripting system.

The Callbacks Part

The callback block is located at the end of the file. It contains the functions that have to be executed in case of a callback. A Callback is always composed of:

  • Path: The callback trace
  • Value: The data to be processed

It has to return a boolean. If the boolean is false, an error will be added on scripting error counter.

Starting a script

Now that you have a script, let's start the scripting system:

  1. push on the "Start Scripting System" button
  2. the status will pass to "Initializing..."
  3. Reload the page (or click on the scripting tab), you will see that the status is now "running".

Sine the script runner can work with multiple scripts, you have to enable it:

  1. Click on the enable link on the script line inside the script manager

CompasLua: Enable a script

Now the script has started, you can see a little more information about it : It is running every 10 seconds, the last time it has run it is 8 second ago and the script duration is 11 ms. ( On the screenshot below)

Script running

You can also see the console output that will show the text that you have entered in the script. As you can see, the initialization part has run only at the start of the script. After that, it is the loop that has been called by the Script runner.

CompasLua: debug output console

In order to have the script starting at the start-up, you have to enable CompasLua system (having the green flag indicating "running" on scripting page is a good indicator), enable the scripts that you want to start automatically and save your configuration. If there is an error on a script, the  corresponding line will also be in red.

Modifying Your Script In Order To Monitor a SNMP Device

Currently, Compas is supporting SNMP get command. We will just try to monitor another device using the SNMP communications. We are going to monitor a Micro-secure UPS, controller coming directly from the alpha group.

What are we going to do into this small script?

  1. Create an ac_ups_system
  2. with one description manually defined
  3. with one description read from SNMP
  4. with several alarms coming from SNMP
  5. and with several data coming from the ups

This exercise has a progressive difficulty.

.... ....

Contact us if you are interested !!