tencent cloud

Feedback

Rule Function

Last updated: 2021-08-20 16:11:59

    The rule engine provides a wide variety of functions, which you can use in the corresponding values of the rule engine fields, conditions, and database fields to process data in diverse ways.

    Supported Functions

    Function Description
    productId() Returns the ID of the product from which the message comes
    deviceName() Returns the name of the device from which the message comes
    timestamp() Returns the current Unix system timestamp in seconds
    topic() Returns the original topic from which the message comes
    topic(n) Returns the segment n separated by / in the original topic from which the message comes
    payloadLen() Returns the length of the payload in bytes
    bin_to_dec() Converts the binary data to a decimal integer
    to_hex () Converts the entered original message to a hexadecimal string
    randint(min,max) Returns a random integer between min and max
    upper(string) Returns an uppercase string (the entered message should be in JSON format, and the function object is the corresponding key value. For example, if the entered message is "tencent":"iot", then upper(tencent)=IOT)
    lower(string) Returns a lowercase string (the entered message should be in JSON format, and the function object is the corresponding key value)
    crypto(field,String) Encrypts the value of field, where the second parameter String is an algorithm string. Valid values: MD5, SHA1, SHA256, SHA384, SHA512. (The entered message should be in JSON format, and the function object is the corresponding key value)
    concat(string1, string2) Concatenates strings, such as concat(deviceid,'a') or concat(field1,field2)
    requestId() Returns the ID of the message generated by IoT Hub
    newuuid() Returns a random UUID string
    replace(source, substring, replacement) Replaces substring in source with replacement
    substring(source, start, end) Returns the string between start (inclusive) and end (not inclusive)

    Samples

    A home temperature and humidity monitor device dev00 sends the following messages to the cloud:

    {"room1":{"temperature":31,"humidity":"63%"},
    "room2":{"temperature":26,"humidity":"63%"}}
    

    Three temperature and humidity monitor devices dev00, dev01, and dev02 under the temperature and humidity monitor product monitor the temperature and humidity in six rooms room1, room2, room3...room6 respectively, and only when the temperature in room room1 is above 30°C, the data needs to be transferred to the MySQL database for processing. In this example, the settings of the rule engine are as follows:

    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support