Expressions
Expressions allow performing calculations, primarily for raw data conversion in devices.
What are expressions?
Expressions are texts that allow evaluating data, performing calculations, and ultimately returning a single value. Expressions can include variables, so that the values of those variables are used in the calculations.
Data types
The expression engine built into Gear Studio supports three data types: number, string, and boolean, as shown below:
| Data type | Comments |
|---|---|
| Number | Number data types represent numbers, either integers or floating-point (with decimals). |
| String | Represent texts, and when written as constants, they must be enclosed using single quotes ('). When a text must contain a single quote, it can be represented as a constant using two consecutive single quotes (''). |
| Boolean | Represents a boolean (logical) condition, which can only be true or false. |
Variables
When expressions are used for raw data conversion in devices, there is an implicit variable RawData, which contains the raw value sent by the device. This variable can be used directly in any data conversion expression, but it is important to note that the variable is of type string. It is usually necessary to convert the variable to a number (using the ToNumber function), and apply other conversion functions as needed.
Some expression examples
| Expression | Comments |
|---|---|
| 25 | Constant, with value 25 (number) |
| 'Hola, mundo' | Constant, with value "Hola, mundo" (string) |
| False | Constant, with value false (boolean) |
| 'I''m happy with expressions' | Constant with value "I'm happy with expressions" (string). Note the use of double single quotes for the single quote after "I". |
| 5 * 6 | Expression with value 30 (number), corresponding to the multiplication of 5 by 6. |
| (2 + 3) * 6 | Expression with value 30 (number), corresponding to an addition and a multiplication. |
| 'Tengo ' + ToString(6 * 5) + ' anos' | Expression with value "Tengo 30 anos" (string), using a multiplication and a number-to-string conversion using the ToString function. |
| 25 < 8 | Expression with value false (boolean), corresponding to a less-than comparison. |
| not (25 < 8) | Expression with value true (boolean), corresponding to the negation of a less-than comparison. |
| Sqrt(81) | Expression with value 9 (number), calculated as the square root of 81 using the Sqrt function. |
| ToNumber(RawData) / 10 | Numeric expression whose value depends on the special RawData variable. The expression takes the value of RawData, converts it to a number, and then divides it by 10. |
What effect do uppercase and lowercase have on expressions?
In the Cloud Studio platform expression engine, variable names, functions, etc., are not case-sensitive, meaning it does not matter whether they are written in uppercase, lowercase, or a mix of both. For example, all of the following expressions are equivalent:
ToString(NOT (valor < 25))
tostring(not (valor < 25))
TOSTRING(not (VALOR< 25))Where can expressions be used?
Currently, expressions can be used for raw data conversion in devices. This allows obtaining raw information from certain devices (typically sensors), and using expressions to convert that data to values that can be injected into the platform.
Can I program using expressions?
No, expressions are not a programming tool, but a calculation tool. Expressions do not have control structures such as for, while, etc., and are not designed for that purpose.
How can I test my expressions?
In general, any functionality that allows the use of expressions has the ability to test each expression right there with test values. As an example, you can consult the raw data conversion reference for devices.
How can I represent hexadecimal numbers?
The expression engine allows representing hexadecimal numbers by prepending the prefix "0x", or alternatively, the prefix "$" (both methods are equivalent). For example, the value 0x100 (or alternatively, $100), represents the hexadecimal number 100, equivalent to decimal 256.
More information
For more information about expressions, consult the operators and functions reference.