The content of this page has been automatically translated by AI. If you encounter any problems while reading, you can view the corresponding content in Chinese.
The rule engine provides multiple functions. You can use these functions in the fields and conditions of the rule engine as well as the corresponding values of the database fields to achieve diversified data processing.
Supported Functions
Function Name
Usage Description
productId()
Return the product ID of the message source.
deviceName()
Return the device name of the message source.
timestamp()
Return the current Unix system timestamp in seconds.
topic()
Return the original Topic of the message source.
topic(n)
The nth segment of the original Topic of the message source, separated by /.
payloadLen()
Return the byte length of the payload.
bin_to_dec()
Convert the binary number data to a decimal integer.
to_hex ()
Convert the input raw message to a hexadecimal string.
randint(min,max)
Return a random integer between min and max.
upper(string)
Return an uppercase string (the input message format needs to be in JSON format, and the function object is the corresponding key value. For example, if the input message is "tencent":"iot", then upper(tencent)=IOT).
lower(string)
Return a lowercase string (the input message format needs to be in JSON format, and the function object is the corresponding key value).
crypto(field,String)
Encrypt the value of the field, and the second parameter String is the algorithm string. Optional: MD5, SHA1, SHA256, SHA384, SHA512. (The input message format needs to be in JSON format, and the function object is the corresponding key value).
concat(string1, string2)
String concatenation, for example concat(deviceid, 'a') or concat(field1, field2).
requestId()
Return the message ID generated by the Internet of Things (IoT) Hub.
newuuid()
Return a random UUID string.
replace(source, substring, replacement)
Replace the substring in the source.
substring(source, start, end)
String extraction, return the string from start (including) to end (excluding).
Usage Example
The content of messages sent by a home temperature and humidity device dev00 to the cloud:
{"room1":{"temperature":31,"humidity":"63%"},
"room2":{"temperature":26,"humidity":"63%"}}
The temperature and humidity products have three devices, dev00, dev01, and dev02, which monitor the temperature and humidity of six rooms, room1, room2, room3,..., room6. Data from room1 need to be transferred to the MySQL database for processing only when the temperature in room1 exceeds 30 Celsius. The rule engine settings are as follows: