In some cases, RAW data managed by the remote object may use a legacy representation for some types of information.
For instance:
- The environment temperature can be published as an integer of 4 digits (e.g. 2550 → 25.5 °C).
- A boolean can be published as integer (e.g. 1 → true, 0 → false).
- The number of hours can be published by using the number of milliseconds, and for this reason you need to convert back to hours (e.g. value / 3600000).
In order to store the right value, within a Simple metric you can select a Value Transformer, which is applied as the last step during the value extraction from the incoming IoT message.
Value transformer can be used within the definition of:
Predefined Value Transformers
By default, Servitly provides the following Value Transformers:
- Boolean to Integer: converts true or false to 1 or 0.
-
Int / 10: it means that the incoming value is a float with one decimal digit but represented as an integer (e.g. 123 → 12.3).
-
Int / 100: it means that the incoming value is a float with two decimal digits but represented as an integer (e.g. 123 → 1.23).
-
Two’s Complement: it means that the incoming value is an integer represented in two’s complement (e.g. 0101 → 5).
-
Two’s Complement / 10: the composition of the third and first case (e.g. 0101 → 0.5).
-
Two’s Complement / 100: the composition of the third and second case (e.g. 0101 → 0.05).
Integer to Boolean conversion is handled automatically by the system, so there is no need for an explicit value transformer.
Custom Value Transformers
You can use one of the predefined value transformers or, in addition, you can create your own one by clicking the Add Value Transformer button.
The Value Transformer creation requires providing:
- Name: the name that uniquely identifies the transformer.
- Description: the text that describes the transformer and helps find it when defining a metric.
- Expression: the mathematical expression to be used to convert the incoming value.
You can use the default "value" variable, but in addition you can use the context thing and thus the underlying properties. For instance, (value * thing.properties.factor) / 100.
Comments
0 comments
Please sign in to leave a comment.