# Expression Filter¶

The *foglamp-filter-expression* allows an arbitrary mathematical expression to be applied to data values. The expression filter allows user to augment the data at the edge to include values calculate from one or more asset to be added and acted upon both within the FogLAMP system itself, but also forwarded on to the up stream systems. Calculations can range from very simply manipulates of a single value to convert ranges, e.g. a linear scale to a logarithmic scale, or can combine multiple values to create composite value. E.g. create a power reading from voltage and current or work out a value that is normalized for speed.

Expression filters are added in the same way as any other filters.

Click on the Applications add icon for your service or task.

Select the

expressionplugin from the list of available plugins.Name your expression filter.

Click

Nextand you will be presented with the following configuration page

Configure the expression filter

Datapoint Name: The name of the new data point into which the new value will be stored.

Expression to apply: This is the expression that will be evaluated for each asset reading. The expression will use the data points within the reading as symbols within the asset. See Expressions below.Enable the plugin and click

Doneto activate your filter

## Expressions¶

The *foglamp-filter-expression* plugin makes use of the ExprTk library to do run time expression evaluation. This library provides a rich mathematical operator set, the most useful of these in the context of this plugin are;

Logical operators (and, nand, nor, not, or, xor, xnor, mand, mor)

Mathematical operators (+, -, *, /, %, ^)

Functions (min, max, avg, sum, abs, ceil, floor, round, roundn, exp, log, log10, logn, pow, root, sqrt, clamp, inrange, swap)

Trigonometry (sin, cos, tan, acos, asin, atan, atan2, cosh, cot, csc, sec, sinh, tanh, d2r, r2d, d2g, g2d, hyp)

Within the expression the data points of the asset become symbols that may be used; therefore if an asset contains values “voltage” and “current” the expression will contain those as symbols and an expression of the form

```
voltage * current
```

can be used to determine the power in Watts.

When the filter is used in an environment in which more than one asset is passing through the filter then symbols are created of the form <asset name>.<data point>. As an example if you have one asset called “electrical” that has data points of “voltage” and “current” and another asset called “speed” that has a data point called “rpm” then you can write an expression to obtain the power per 1000 RPM’s of the motor as follows;

```
(electrical.voltage * electrical.current) / (speed.rpm / 1000)
```

## Known Restrictions¶

If your asset name or datapoint name contains any characters that are mathematical symbols, i.e. +, -, *, /, %, ^, (, ), [ or ], then these can not be used in the expressions supported by this filter.

Likewise if your asset name or datapoint name is one of the reserved names of operators or functioned they can also not be used.

To resolve this problem it is recommended to use the asset filter to rename the offending assets or datapoint prior to passing the data through the expression filter.

## See Also¶

foglamp-filter-fft - A FogLAMP processing filter plugin that calculates a Fast Fourier Transform across sensor data

foglamp-filter-metadata - A FogLAMP processing filter plugin that adds metadata to the readings in the data stream

foglamp-filter-omfhint - A filter plugin that allows data to be added to assets that will provide extra information to the OMF north plugin.

foglamp-filter-python35 - A FogLAMP processing filter that allows Python 3 code to be run on each sensor value.

foglamp-filter-rms - A FogLAMP processing filter plugin that calculates RMS value for sensor data

foglamp-filter-scale-set - A FogLAMP processing filter plugin that applies a set of sale factors to the data

foglamp-filter-statistics - Generic statistics filter for FogLAMP data that supports the generation of mean, mode, median, minimum, maximum, standard deviation and variance.

foglamp-north-mqtt-scripted - A bi-directional MQTT publisher with scriptable payloads. This provides a way to forward data from FogLAMP to an MQTT broker using a Python script to control the format of the payload. Control messages can also be send back via MQTT into FogLAMP.

foglamp-south-Expression - A FogLAMP south plugin that uses a user define expression to generate data

foglamp-south-mqtt-scripted - An MQTT south plugin that allows a Python script to be added to decode the MQTT payload

foglamp-south-simple-rest - A generic REST south plugin with support for a variety of common REST payloads and Python scripting to manipulate call results.