Menu

GroovyScripts

Jim

Create a Groovy Script

Groovy scripts can be created by clicking the "Create Script" button on the main menu of the admin GUI at http://localhost:8080/cs-ws

There are three types of scripts:

  • MomentProcessingScript: The script is called whenever new device data is received by the platform before it is written to the database, similar to a BEFORE INSERT trigger in a SQL database.
  • SocketConnectorScript: The script is called when a message is received on the optional raw socket interface of the platform.
  • HttpConnectorScript: The script is called when a message is received on the optional pure HTTP interface of the platform.

MomentProcessingScript

Purpose of this script is to provide application logic that can directly executed on the platform when new data is available. There is no limit on the number of moment processing scripts. The script has to implement the IMomentProcessingScript interface with the run(...) method, It has to be assigned to the device model in the "Scripts" section by clicking the "AddScript" button. If several scripts are assigned to the device model all of them are executed one after the other in arbitrary order. Typical tasks of moment processing scripts are:

  • check the validity of the data with respect to min and max values
  • calculate derived values such as averages and add them to sensor attributes
  • define thresholds and generate alarms or send email when a threshold is reached
  • change the configuration state of a device when certain device data are received

SocketConnectorScript

Task of the script is to process the socket data and return a list of sensor data for further processing by the platform. There is only one such script possible per tenant. The script has to implement the ISocketConnectorScript interface with two methods:

  • getDevice(...) has to return a string holding the device id based on the received socket data
  • getSensorData(...) has to return the received data as a list of sensor data

HttpConnectorScript

Task of the script is to process the HTTP data and return a list of sensor data for further processing by the platform. There is only one such script possible per tenant. The script has to implement the IHttpConnectorScript interface with two methods:

  • getDevice(...) has to return a string holding the device id based on the received HTTP data
  • getSensorData(...) has to return the received data as a list of sensor data

The ScriptUtil class provides a set of functions to read, modify and create device data and configuration data, process device data, send notifications and get access to EJBs for further opeartions to be performed. They are described in the API Doc.


Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.