Skip to content

tklHelper

tklHelper is a powerful tool designed for the ThinkLink platform to simplify the configuration process for Thing Models and RPC (Remote Procedure Calls). By using simple variables or JSON-formatted configurations, users can rapidly build Thing Models and RPC functions for uplink protocols, significantly improving development efficiency and configuration flexibility.

This manual provides a detailed introduction to the configuration parameters and usage methods of tklHelper to help users efficiently perform device data parsing and functional definition on the ThinkLink platform.

1. frameInfo Configuration: Data Packet Validation

The frameInfo configuration defines identification rules for data packets to ensure received data conforms to expected formats.

Field NameTypeDescriptionExample
portNumberLoRaWAN uplink port number used to identify specific application data.22
dataLenNumberExpected packet length. Set to -1 to ignore length checks (default is -1).24 or -1
rssiBooleanIndicates whether to display RSSI and SNR from the gateway (default is false).true or false
tagListArrayAn array of tag objects for validation at specific offsets. Includes index (offset) and tag (hex value).[{ index:0, tag:0x83}]

Example frameInfo Configuration:

json
let frameInfo = {
    port: 22,
    dataLen: 24,
    rssi: true,
    tagList: [
        { index: 0, tag: 0x83 },
        { index: 1, tag: 0x23 }
    ]
};

2. appInfo Configuration: Variable Identification

appInfo is an array of objects used to identify specific variables parsed from the data packet, including display names, data types, and units.

Field NameTypeDescriptionExample
nameStringVariable name displayed on the frontend interface."Weight 1"
field_nameStringVariable name used in Thing Model parsing code and other interface calls."weight1"
unitStringThe unit of the variable."kg"
indexNumberStarting position (offset) of the variable in the data frame.6
typeStringData type of the variable (see detailed list below)."int32be"
coefficientString/NumScaling factor (default is 1). Can be a number or another variable's field_name."0.001"
decimalNumberNumber of decimal places to retain (default is 0).2
optionsObjectMaps raw values to other values (e.g., {0:false, 1:true}). Prioritized over postProcess.{0: "Off"}
postProcessStringFunction for simple algorithmic calculations. Input is value; must have a return."return value + 1"

3. Data Type Details

3.1 Number Types

These represent various integers and floating-point numbers.

Type NameDescriptionExample Usage
int8, uint88-bit signed/unsigned integer."int8"
int16be, uint16le16-bit integer with Big-Endian (BE) or Little-Endian (LE) support."uint16be"
int32be, uint32le32-bit integer with BE/LE support."int32be"
floatbe, floatle32-bit floating point ."floatbe"
bcdbe, bcdleBinary Coded Decimal. Format: type + byte length."bcdbe4"
bitbe, bitleBit extraction. Format: type + start bit + - + end bit."bitbe2-2"

3.2 Boolean and String Types

Type NameDescriptionExample Usage
boolBoolean type. Format: bool + byte length."bool4"
stringASCII string. Format: string + byte length."string7"
hexbe, hexleHexadecimal string. Format: hexbe + byte length."hexbe5"

4. Thing Model Display Fields

This configuration defines how data is presented on the ThinkLink frontend.

Field NameTypeDescription
iconNullCurrently remains null.
nameStringDisplay name on the interface.
typeStringData type: number, string, boolean, or object.
orderNumberPresentation order on the interface.
field_nameStringMust match the field_name in appInfo.

5. Functions and Examples

Using PayloadParser, you can create a data parser to process uplink data. For EB-based parameters (usually on port 214), configurations are retrieved from APP parameters.

Example Implementation:

javascript
function payload_parser({device, msg, thingModelId, noticeAttrs}) {
  let port = msg?.userdata?.port || null;
  let frameInfo = {
    port: 11, dataLen: 15, rssi: true,
    tagList: [{ index: 0, tag: 0x21 }, { index: 1, tag: 0x07 }, { index: 2, tag: 0x03 }]
  };
  let appInfo = [
    { name: "status", field_name: "status", unit: "", index: 7, type: "bitLE0-0" },
    { name: "temperature", field_name: "temperature", unit: "℃", index: 8, type: "uint16LE" }
  ];
  
  let payParser = new PayloadParser({
    device: device,
    msg: msg,
    frameInfo: frameInfo,
    appInfo: appInfo
  });

  let tdata = (port === 214) ? null : payParser.telemetry();
  let pdata = (port === 214) ? payParser.paras() : null;

  return {
    telemetry_data: tdata,
    server_attrs: null,
    shared_attrs: pdata
  };
}

6. Conclusion

By configuring frameInfo and appInfo with tklHelper, users can efficiently manage Thing Models and RPC functions on ThinkLink, ensuring precise data parsing and visualization.