We added access to device metadata directly from expressions in calculators.
You may configure in device metadata any specific per-device configuration, for example maximum speed limit or controlling geofence and use this data in calculator selectors or counters.
To access metadata you use new function metadata(“field-path”). For example, let's imagine that you store in the device's metadata two fields: maximum speed limit and coordinates of locked point. You can do this by executing the following REST API call after which device metadata will be the following:
"metadata": {
"speed_limit": 100,
"geofence": {
"lat": 50,
"lon": 20
}
}
Now you can create a calculator that will handle speed and generate overspeeding intervals according to the currently configured speed limit. To do this use the following configuration of calculator:
{
"selectors": [
{
"expression": "position.speed > metadata(\"speed_limit\")",
"type": "expression"
}
],
"name": "Overspeeding",
"validate_message": "not(isnull(metadata(\"speed_limit\")))",
"update_onchange": true
}
Validate message parameter used to disable calculator when no speed_limit parameter is defined in device’s metadata.
Same you can achieve with geofence. In order to generate interval when device moves 100 meters outside of specified center point you use the following expression in selector:
distance(metadata("/geofence/lat"), metadata("/geofence/lon"), position.latitude, position.longitude) > 100
Important note. Update_onchange option in calculator properties will determine the calculator action when you changed the metadata - should it recalculate everything (update_onchange=true) or just ignore change in metadata and initiate minor recalculation only when the device sends a new message.
P.S. Access to metadata is provided only for devices assigned to calculators and not available using calculation on-demand API call.