Skip to main content

Trigger examples

This section outlines two examples for the two main Trigger types (connection and data), and a sample payload for its HTTP Post URL action.

Connection Trigger​

This trigger will send a POST request to <url> every time any device connects to its transport.

This is the JSON representation of the trigger:

{
"name": "my_connection_trigger",
"action": {
"http_url": "<url>",
"http_method": "post"
},
"simple_triggers": [
{
"type": "device_trigger",
"device_id": "*",
"on": "device_connected"
}
]
}

If the Trigger is installed, when a device connects, <url> will receive the following JSON payload:

{
"timestamp": "<timestamp>",
"device_id": "<device_id>",
"event": {
"type": "device_connected",
"device_ip_address": "<device_ip_address>"
}
}

Data Trigger​

This trigger will send a POST request to http://www.example.com/hook every time a device sends data to the org.astarte-platform.genericsensors.Values major version 0 interface on the /streamTest/value path.

This is the JSON representation of the trigger

{
"name": "my_data_trigger",
"action": {
"http_url": "http://www.example.com/hook",
"http_method": "post"
},
"simple_triggers": [
{
"type": "data_trigger",
"on": "incoming_data",
"interface_name": "org.astarte-platform.genericsensors.Values",
"interface_major": 0,
"match_path": "/streamTest/value",
"value_match_operator": "*"
}
]
}

If the Trigger is installed, when a device sends data to the interface/path defined above, <url> will receive the following JSON payload:

{
"timestamp": "<timestamp>",
"device_id": "<device_id>",
"event": {
"type": "incoming_data",
"interface": "org.astarte-platform.genericsensors.Values",
"path": "/streamTest/value",
"value": <value>
}
}