Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagelua
function LimitValue(minValue, maxValue, email)

	local currentValue = nxa.SourceValue()

	if (currentValue ~= nil and currentValue >= minValue and currentValue <= maxValue)
   	then
		nxa.WriteDestinationValue(currentValue)
    else
		if (email ~= nil)
		then
			xcon.SendEmailTo("wolfgang@granzer.org"email, "Value out of range", "The input value with ID " .. nxa.SourceItemID() .. " is out of range")
		end
	end
end

...

  • minValue: defines the minimum value of the range for the input item
  • maxValue: defines the maximum value of the range for the input item
  • email: defines the e mail address where item values outside the boundaries are reported.

First, current value which triggers the LUA function is stored within the local variable currentValue. To achieve this, the built-in function nxa.SourceValue() is used. Afterwards, the value is evaluated. First, it is verified whether it is not nil. nil means that there is no valid value – this is the case when the Item Quality is not GOOD (e.g. the device that provides the item is offline). Then, the value is compared to the minimum and maximum limits that are provided as function parameter. If the condition evaluates to true, the current value is forwarded to the destination item. This is done using the built-in function nxa.

...

 WriteDestinationValue(value) which writes the value that is provided as parameter 1 to the item which is defined within the task.

If the condition evaluates to false, an e mail shall be sent if an e mail address is specified. First, it is verify whether an e mail is specified i.e. whether it is not nil. To send an e mail, the LUA function xcon.SendEmailTo(email, subject, body, attachment(optional)) is used. The first parameter is the e mail address. In our example, it is provided by the third parameter of the LUA function LimitValue. The second parameter is the subject of the e mail, the third the body, and the forth is an optional file as attachment. The subject and body are strings. As body, LUA string concatenation using .. is used in order to include the Item ID that triggers the tasks using nxa.SourceItemID().

After having finished the LUA implementation, save LUA function and restart the LUA engine using the buttons within the toolbar of the LUA script editor.

Image Added

Configuring the e mail system

In order to send an e mail, the connection to an SMTP e mail server has to be configured. This is done within the System Parameter within the Server menu of the NETx BMS Studio. At the bottom of the configuration file, the SMTP host (IP address), SMTP port number and the authentication information (TLS, user name , password) have to entered. The following screenshot shows the configuration of the gmail SMTP server.

Image Added

Create a task definition to use the LUA function

...

Filter by label (Content by label)
max5
spacesTS
sorttitle
reversetrue
typepage
excerptTypesimple
cqllabel in ("command","xlogiclua","commandlogic")
labelsBMS Server database storage

...