Raw Data Conversion
Raw data conversion performs calculations on data obtained from a device and adapts it to the values needed for input into the platform. This allows the use of devices from virtually any brand and model, simply by creating expressions that convert the values delivered by the device.
How can I inject raw data into the platform?
Raw data is sent, both via HTTP and MQTT, using APIs ending in "Raw". For example, to feed the platform with information from a temperature sensor using "raw" data, the "UpdateTemperatureSensorStatusRaw" API must be used. It is recommended to consult the following table to learn about the available methods for injecting raw data for each endpoint type.
Using expressions and the "RawData" variable
All APIs ending in "Raw" have a "rawData" parameter where the device must report the measured value. This value is internally converted into a variable called "RawData", which can be used in the expression evaluator.
As an example conversion, we will use a temperature sensor with the following characteristics:
- Units: the device reports temperature in degrees Fahrenheit.
- Measurement range: from -30 degrees Fahrenheit to +140 degrees Fahrenheit.
- Temperature is reported in tenths of a degree Fahrenheit (meaning it has no decimals, but is multiplied by 10).
The Gear platform, however, requires temperatures to be reported in degrees Celsius, which therefore requires a conversion. To achieve this conversion, the following steps are necessary:
- Divide the obtained value by 10.
- Convert the received temperature from degrees Fahrenheit to Celsius.
To accomplish this, the following expression should be used:
FahrenheitToCelsius(ToNumber(RawData) / 10)This expression does the following:
- Uses the RawData variable, which is an implicit variable that exists in all raw data conversion operations, and represents the raw data content as a string.
- Uses the ToNumber function to convert the RawData variable to an equivalent numeric value.
- Divides the obtained value by 10.
- Finally, uses the FahrenheitToCelsius function to convert this value to degrees Celsius.
More information
For more information about using expressions, see the Expressions section, which contains a more detailed description of the expression engine, data types, operators, functions, and examples of each.