8.1 Built-in Data Types

8.1.1 ConfigBase Type

Basic configuration type

class ConfigBase{
    string GetConfigString(string key, string default);
    int GetConfigInt(string key, string default);
}

8.1.1.1 Get String Configuration Parameter

  • Definition: GetConfigString(key, default) -> string

  • Category: Method

  • Parameter:

    • key: string type,Configuration name
    • default: string type,Default value
  • Return: string Get configuration content, returns default value if empty

  • Example:

    -- Current configuration item is c
    -- Read current configuration address
    local address = c:GetConfigString("address","")

8.1.1.2 Get Integer Configuration Parameter

  • Definition: GetConfigInt(key, default) -> int

  • Category: Method

  • Parameter:

    • key: string type,Configuration name
    • default: int type,Default value
  • Return: int Get configuration content, returns default value if empty

  • Example:

    -- Current configuration item is c
    -- Read current configuration port
    local port = c:GetConfigString("port","")

8.1.2 Device Type

Data collection device type, inherits from ConfigBase, can use ConfigBase methods

class Device : ConfigBase{
    string name;
    string code;
    string type;
    json current;
    json last;
    int state;
    int id;
}

8.1.2.1 Get Device Configuration Parameter

8.1.2.2 Device ID

  • Definition: id

  • Category: Property

  • Type: int

  • Description: Returns device ID

  • Example:

    -- If this script is in device edge calculation, device is the current device
    -- Return current device id
    local device_id = device.id

8.1.2.3 Device Name

  • Definition: name

  • Category: Property

  • Type: string

  • Description: Returns device name

  • Example:

    -- If this script is in device edge calculation, device is the current device
    -- Return current device name
    local device_name = device.name

8.1.2.4 Device Code

  • Definition: code

  • Category: Property

  • Type: string

  • Description: Returns device Code

  • Example:

    -- If this script is in device edge calculation, device is the current device
    -- Return current device code
    local device_code = device.code

8.1.2.5 Current Collection Data

  • Definition: current

  • Category: Property

  • Type: table

  • Description: Returns current collection data from device

  • Example:

    -- If this script is in device edge calculation, device is the current device
    -- Return current device current collection data
    local current_data = device.current

8.1.2.6 Last Collection Data

  • Definition: last

  • Category: Property

  • Type: table

  • Description: Returns last collection data from device

  • Example:

    -- If this script is in device edge calculation, device is the current device
    -- Return current device last collection data
    local last_data = device.last

8.1.2.7 Device Collection Status

  • Definition: state

  • Category: Property

  • Type: int

  • Description: Returns current collection status, 0 for normal, non-zero otherwise

  • Example:

    -- If this script is in device edge calculation, device is the current device
    -- Return device current collection status
    local state = device.state

8.1.3 Variable Type

Data collection variable type, inherits from ConfigBase, can use ConfigBase methods

class Variable{
    int Write(json value);
    Device device;
    string name;
    bool writable;
    bool readable;
    json current;
    json last;
}

8.1.3.1 Write Value to Variable

  • Definition: Write(value)

  • Category: Method

  • Parameter:

    • value: any type,Value to write, type depends on variable data type setting
  • Example:

    -- If this script is in variable edge calculation, variable is the current variable
    -- Write to current variable configuration
    variable:Write(1)
    -- variable:Write("1") --If string type
    -- variable:Write(true) --If bool type

8.1.3.2 Variable Name

  • Definition: name

  • Category: Property

  • Type: string

  • Description: Variable name

  • Example:

    -- If this script is in variable edge calculation, variable is the current variable
    -- Return current variable last collection data
    local name = variable.name

8.1.3.3 Current Collection Data

  • Definition: current

  • Category: Property

  • Type: table

  • Description: Current collection data from variable

  • Example:

    -- If this script is in variable edge calculation, variable is the current variable
    -- Return current variable current collection data
    local current_data = variable.current

8.1.3.4 Last Collection Data

  • Definition: last

  • Category: Property

  • Type: table

  • Description: Last collection data from variable

  • Example:

    -- If this script is in variable edge calculation, variable is the current variable
    -- Return current variable last collection data
    local last_data = variable.last

8.1.3.5 Variable Device

  • Definition: device

  • Category: Property

  • Type: Device

  • Description: Device that variable belongs to

  • Example:

    -- If this script is in variable edge calculation, variable is the current variable
    -- Read current variable device name
    local device = variable.device
    local device_name = variable.device.name

8.1.4 Publisher Type

Push platform type

class Publisher{
    json GetOriginMessage();
    int SetMessage(json message);
    json GetMessage();
}

8.1.4.1 Get Original Collection Data

  • Definition: GetOriginMessage() -> table

  • Category: Method

  • Return: table Returns original collection data

  • Data Format:

        [
            {
                "device_id":1,
                "device_name":"test_fanuc",
                "device_state":1,
                "device_type":"fanuc",
                "ts":1716886841474,
                "values":[
                    {
                        "name":"cnc_runstatus",
                        "id":100,
                        "ts":1716886841474,
                        "value":1
                    }
                ]
            }
        ]

8.1.4.2 Set Push Data

  • Definition: SetMessage(message)
  • Category: Method
  • Parameter:
    • message: table type
  • Return: table Returns formatted push data after format processing

8.1.4.3 Get Push Data

  • Definition: GetMessage() -> table
  • Category: Method
  • Return: table Returns formatted push data after format processing

8.1.5 Mqtt Type

Mqtt client for pushing

class MqttClient{
    int Connect();
    int PushMessage(string message, string topic, int qos, int retained);
    int CheckConnect();
    int Subscribe(string message, int qos);

    string address;
    string username;
    string password;
    string client_id;
    int keepalive;
    string will_msg;
    int will_qos;
    bool connected;
    function on_connect;
    function on_disconnect;
    function on_message;
    function on_connect;
    string ca;
    string cert;
    string key;
    string key_pass;
    string ssl_version;
}

8.1.5.1 Connect to Mqtt

  • Definition: Connect() -> int
  • Category: Method
  • Return: int Returns connection status, 0 for ok, non-zero for connection failure

8.1.5.2 Push to mqtt server

  • Definition: PushMessage(message,topic,qos,retained) -> int
  • Category: Method
  • Parameter:
    • message: string string type,Message to push
    • topic: string string type,Target topic to push
    • qos: int int type,Push qos, 0 or 1 or 2
    • retained: int int type,Whether to retain message, 0 or 1
  • Return: int Returns push status, 0 for ok, non-zero for connection failure

8.1.5.3 Check Current Server Connection Status

  • Definition: CheckConnect() -> int
  • Category: Method
  • Return: int Returns connection status, 0 for ok, non-zero for connection failure

8.1.5.4 Subscribe Topic

  • Definition: Subscribe(topic,qos) -> int
  • Category: Method
  • Parameter:
    • topic: string string type,Topic to subscribe
    • qos: int int type,0 or 1 or 2
  • Return: int Returns push status, 0 for ok, non-zero for connection failure

8.1.5.5 Mqtt Server Address

  • Definition: address
  • Category: Property
  • Type: string
  • Description: Format: tcp://127.0.0.1:1883

8.1.5.6 Mqtt Authentication Username

  • Definition: username
  • Category: Property
  • Type: string

8.1.5.7 Mqtt Authentication Username

  • Definition: username
  • Category: Property
  • Type: string

8.1.5.8 Mqtt Authentication Password

  • Definition: password
  • Category: Property
  • Type: string

8.1.5.9 Mqtt ClientID

  • Definition: client_id
  • Category: Property
  • Type: string

8.1.5.10 Mqtt KeepAlive

  • Definition: keepalive
  • Category: Property
  • Type: string

8.1.5.11 Mqtt Will Message

  • Definition: will_msg
  • Category: Property
  • Type: string

8.1.5.12 Mqtt Will Topic

  • Definition: will_topic
  • Category: Property
  • Type: string

8.1.5.13 Mqtt Will QOS

  • Definition: will_qos
  • Category: Property
  • Type: int
  • Description: 0 or 1 or 2

8.1.5.14 Mqtt Current Connection Status

  • Definition: connected
  • Category: Property
  • Type: Bool
  • Description: Current connection status, true / false

8.1.5.15 Mqtt Connected Event

  • Definition: on_connect
  • Category: Property
  • Type: function()
  • Description: Called when mqtt server connection succeeds, no parameters

8.1.5.16 Mqtt Disconnected Event

  • Definition: on_disconnect
  • Category: Property
  • Type: function()
  • Description: Called when mqtt server disconnects, no parameters

8.1.5.17 Mqtt Subscribe Message Event

  • Definition: on_message
  • Category: Property
  • Type: function(topic,message)
  • Parameter:
    • topic: string string type,Topic of received subscription message
    • message: string string type,Content of received subscription message
  • Description: Triggered when mqtt receives subscription message, receives two parameters

8.1.5.18 Mqtt SSL CA

  • Definition: ca
  • Category: Property
  • Type: string

8.1.5.19 Mqtt SSL CERT

  • Definition: cert
  • Category: Property
  • Type: string

8.1.5.20 Mqtt SSL KEY

  • Definition: key
  • Category: Property
  • Type: string

8.1.5.21 Mqtt SSL KEY PASSWORD

  • Definition: key_pass
  • Category: Property
  • Type: string

8.1.5.22 Mqtt SSL Version

  • Definition: ssl_version
  • Category: Property
  • Type: string