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) -> stringCategory: Method
Parameter:
key: string type,Configuration namedefault: string type,Default value
Return:
stringGet configuration content, returns default value if emptyExample:
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.2 Device ID
Definition:
idCategory: Property
Type:
intDescription: Returns device ID
Example:
8.1.2.3 Device Name
Definition:
nameCategory: Property
Type:
stringDescription: Returns device name
Example:
8.1.2.4 Device Code
Definition:
codeCategory: Property
Type:
stringDescription: Returns device Code
Example:
8.1.2.5 Current Collection Data
Definition:
currentCategory: Property
Type: table
Description: Returns current collection data from device
Example:
8.1.2.6 Last Collection Data
Definition:
lastCategory: Property
Type: table
Description: Returns last collection data from device
Example:
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:
8.1.3.2 Variable Name
Definition:
nameCategory: Property
Type:
stringDescription: Variable name
Example:
8.1.3.3 Current Collection Data
Definition:
currentCategory: Property
Type:
tableDescription: Current collection data from variable
Example:
8.1.3.4 Last Collection Data
Definition:
lastCategory: Property
Type:
tableDescription: Last collection data from variable
Example:
8.1.3.5 Variable Device
Definition:
deviceCategory: Property
Type: Device
Description: Device that variable belongs to
Example:
8.1.4 Publisher Type
Push platform type
8.1.4.1 Get Original Collection Data
Definition:
GetOriginMessage() -> tableCategory: Method
Return:
tableReturns original collection dataData Format:
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:
intReturns 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:stringstring type,Message to pushtopic:stringstring type,Target topic to pushqos:intint type,Push qos, 0 or 1 or 2retained:intint type,Whether to retain message, 0 or 1
- Return:
intReturns 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:
intReturns 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:stringstring type,Topic to subscribeqos:intint type,0 or 1 or 2
- Return:
intReturns 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.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:stringstring type,Topic of received subscription messagemessage:stringstring type,Content of received subscription message
- Description: Triggered when mqtt receives subscription message, receives two parameters