Triggers are snippets of code executed after an event happens like a thingWrite. You can use a trigger to send an alarm or generate an event to be aggregated later. Also you can call external web services.

Each trigger must contain a function trigger(params, callback)


params is an object with the keys:

  • action: one of 'write' | 'read'
  • thingToken: the thing that triggered the trigger
  • values: only if action == 'write'. Is an array of values where each value is an object with:
    • key: the key
    • value: the data sent
    • datetime: (can be null)

callback is a function to be called when the trigger ends can contain a parameter string error if the trigger needs to report an error.

The execution of a trigger is limited to 2 seconds. If the execution takes longer, the server will end the sandbox.

Setup Alarm

This code sends an email when the temperature is higher than 50 degrees to ''.

Generate events

You can generate events from inside the code. The following code generates a simple event which stores the value to an event called 'temperature'. To be later retrieved from a job:

Playing with geolocation

This example shows how you can combine geolib and the geolocation of your things to send an email when your thing is not inside a predefined circle.
In the example the description key/resource is used to store the predefined coordinates and the user's email.

Learn more