This topic outlines the functions available for scripting time series data storage rules on the IoT Platform, enabling diverse data processing. It covers data type conversion functions, time type conversion functions, and basic data type functions, along with their usage instructions.
Background information
Utilize the supported script syntax to invoke functions for storing custom topic data from devices into the IoT Platform's time series data storage.
Time series data storage related functions
Expression | Description |
convert2HotStorageData(fields, time) | Transforms the fields data into a standardized format suitable for storage.
The data is converted into the following standardized format: |
writeHotStorage(params) | Stores data in the standardized format params into the IoT Platform's time series data storage. The params must include Important The params parameter can include a maximum of 500 |
Convert data types
Function | Description |
toBoolean(Object) | Converts the Object parameter into a Boolean value. The parameter supports the following data types:
|
toNumber(Object) | Converts the value of the Object parameter into a number. The parameter supports the following data types:
|
toString(Object) | Converts the value of the Object parameter into a string. If the parameter is set to a value other than NULL, the function returns the value as a string. If the parameter is set to NULL, the function returns an empty string. If the parameter is of the binary type, the function returns a UTF-8 decoded value. |
toMap(Object) | Converts the value of the Object parameter into a map. The parameter supports the following data types:
|
toArray(Object) | Converts the value of the Object parameter into an array. The parameter supports the following data types:
|
toBinary(Object) | Converts the value of the Object parameter into a binary value. The parameter supports the following data types:
|
Convert time formats
Function | Description |
format_date(timestamp, patten, timeZone) | Converts a timestamp in milliseconds into a time value in a specified format. A string is returned.
|
to_timestamp(dateString, patten, timeZone) | Converts a time value in a specified format into a timestamp in milliseconds. A numeric value is returned.
|
Functions that are supported by each basic data type
Map
Function
Description
[Object]
Obtains the value of a specified key.
size()
Obtains the number of key-value pairs in a map.
containsKey(String)
Checks whether a map contains a specified key.
keySet()
Obtains keys in a map. An array is returned.
remove(Object)
Removes a key-value pair from a map based on a specified key.
put(Object, Object)
Adds key-value pairs to a map.
putAll(map)
Adds another map to an existing map.
Array
Function
Description
[int]
Obtains the value at a specified index. The index of the first element in an array is 0.
contains(Object)
Checks whether an array contains a specified element.
remove(Object)
Removes a specified element from an array.
removeAt(int)
Removes an element at a specified index in an array.
add(Object)
Adds an element to the end of an array.
add(index, Object)
Adds an element to a specified index.
addAll(array)
Adds another array to an array.
size()
Obtains the number of elements in an array.
String
Function
Description
substring(start, end)
Extracts a string from the
startposition to theend-1position.If you do not configure the parameter, the extraction process continues until the end of the string.length()
Queries the length of a string.
split(String)
Splits a string by using a specified separator.
startsWith(String)
Checks whether a string starts with a specified substring.
endsWith(String)
Checks whether a string ends with a specified substring.
indexOf(String, index)
Queries the position in which a substring first appears from a specified index of a string.
The default value of the index parameter is 0.
Other functions
Function | Description |
endWith(input, suffix) | Checks whether the input string ends with a specified suffix. A Boolean value is returned. |
productKey() | Returns the ProductKey of the current product. |
getDeviceTag(key) | Returns the device tag value of a tag key. If the tag that contains the specified key is not attached to a device, no tag value is returned. |
getOrNull(data, "items", ......) | Returns the value of a specified field in the JSON-formatted data parameter. You can configure one or more fields in the function. Multiple fields must be configured based on levels. The function returns the value of the last field. If the last field does not exist or the field is empty, the function returns null. Example of data: Examples:
|
payload(textEncoding) | Encodes the message payload that is sent by a device. The textEncoding parameter specifies an encoding scheme.
|
parseNumber(numberString, radix) | Converts a string specified by the numberString parameter into a number based on a number system specified by the radix parameter. The radix parameter is optional. Valid values:
Examples: |