Skip to main content

iRidi Server API

Unique functions, methods, and properties available in an iRidi server project (*.sirpz)

Methods​

IR is a global object containing all iRidi API functions and constants. Its server methods access server properties in an iRidi Server project.

IR.GetServer​

Available only in server projects (*.sirpz), this method works with the server's internal variable space. It accesses iRidi Server as a driver and any variable by its full name. Returns an object supporting the methods available for IR.GetDevice.

Syntax

IR.GetServer()

InputValueDescription
-
Output
Object[object DevicePrototype]type: Object
driver reference

Example

var server = IR.GetServer();  // [object DevicePrototype]
server.Set("Virtual 1", 1); // set 1 to Virtual Channel
server.Set("KNX.Address 1", 1); // set 1 to the Address of KNX driver
IR.AddListener(IR.EVENT_TAG_CHANGE , IR.GetServer(), function(name,value)
{
if (name == "KNX.Address 1") IR.Log("KNX Address Changed");
if (name == "Virtual 1") IR.Log("Virtual Tag Changed");
});
Tip
  • Works only in a server project
  • The returned object supports the same methods as other drivers (see methods available for IR.GetDevice)

Events​

An event is a process exposed to scripts with an identifier for monitoring.

A listener is a function that executes when its specified event occurs

Add a listener using the method IR.AddListener

IR.AddListener(event, input, action);

  • event is the identifier of the event monitored by the listener
  • input is an input parameter required to create the listener. If there is no parameter, specify 0
  • action is an anonymous function or a reference to a declared function in which actions are performed
  • pointer - optional reference to the listener's invocation context. Access it with this. The context can change while the program runs

Example:

// functions inside of listener
IR.AddListener(IR.EVENT_TAG_CHANGE, IR.GetDevice("Driver"), function (name, value)
{
IR.Log("changes: "+name+" > "+value); // changes: Feedback 1 > 100
});

IR.EVENT_ACCEPT​

Identifier of the event triggered on any server connection attempt. Returns network parameters of the device attempting to connect. Device authorization starts after connection. When authorization finishes, IR.EVENT_AUTHORIZE is triggered, indicating successful authorization. Combining panel data from ACCEPT and AUTHORIZE provides complete panel information. Associate the two events using ID, the connection identifier.

Syntax

IR.AddListener(IR.EVENT_ACCEPT, IR.GetServer(), function (ID, LocalIP, LocalPort, HostIP, HostPort) {});

InputValueDescription
driverIR.GetServer()type: object
iRidi Server driver reference
Output
ID1type: string
control panel's sequential number in the server's connected-panel list
LocalIP192.168.0.100type: string
control panel's local IP address
LocalPort30464type: string
port on the control panel open for receiving server data
HostIP192.168.0.100type: string
IP address of the remote system from which the panel connected to the server
HostPort30464type: string
port on the remote system open for receiving server data

Example

IR.AddListener(IR.EVENT_ACCEPT, IR.GetServer(), function (ID, LocalIP, LocalPort, HostIP, HostPort)
{
var time = IR.GetVariable("System.Time.24");
IR.Log("Accept Client: "+time+", "+ID+", "+LocalIP+", "+LocalPort+", "+HostIP+", "+HostPort);
});

IR.EVENT_AUTHORIZE​

Important

This function is deprecated and does not perform its stated purpose; it is retained for compatibility. The server currently allows any panel to connect, regardless of whether a password is present

Identifier of the event triggered when a control panel connects successfully to the server. Triggered after IR.EVENT_ACCEPT and returns detailed information about the connected device: connection identifier, panel HWID, user login, automation-site identifier, and name of the visualization project running on the panel. Combining panel data from ACCEPT and AUTHORIZE provides complete panel information. Associate the two events using ID, the connection identifier.

Syntax

IR.AddListener(IR.EVENT_AUTHORIZE, IR.GetServer(), function (ID, ObjectId, Login, ProjectName, HWID) {});

InputValueDescription
driverIR.GetServer()type: object
iRidi Server driver reference
Output
ID1type: string
control panel's sequential number in the server's connected-panel list
ObjectId7071type: number
identifier of the automation site in iRidi Cloud from which the project was uploaded to the control panel
Loginuser@my.mailtype: string
login of the user signed in on the control panel
ProjectNameProject Hometype: string
name of the visualization project running on the control panel
HWID69538...a7acftype: string
unique control-panel identifier (it may change; do not use HWID as a permanent panel identifier!)
NameDESKTOP-1type: string
name of the device on which the panel connected to the server.
ModelWindows 6.2 build 9200 sp 0.0type: string
model of the device on which the panel connected to the server.
ProducerMicrosoft Windows 8 x64type: string
operating system of the device on which the panel connected to the server.
Version0.0.3type: string
operating-system version of the device on which the panel connected to the server.
Group2type: number
group of the client connecting to the server.
Channel1type: number
variables that can be controlled.
Tags1type: number
variables from which feedback can be received

Example

IR.AddListener(IR.EVENT_AUTHORIZE, IR.GetServer(), function (ID, ObjectId, Login, ProjectName, HWID, in_oFullInfo)
{
var time = IR.GetVariable("System.Time.24");
IR.Log("Client Authorized: " + time + ", " + ID + " " + ObjectId + " " + Login + " " + ProjectName + " " + HWID)
IR.Log(JSON.Stringify(in_oFullInfo))
});

IR.EVENT_RELEASE​

Identifier of the event triggered when an i3 pro panel disconnects from the server. Returns information about that panel.

Syntax

IR.AddListener(IR.EVENT_RELEASE, IR.GetServer(), function (ID, LocalIP, LocalPort, HostIP, HostPort) {});

InputValueDescription
driverIR.GetServer()type: object
iRidi Server driver reference.
Output
ID1type: string
control panel's sequential number in the server's connected-panel list.
LocalIP192.168.0.100type: string
control panel's local IP address.
LocalPort30464type: string
port on the control panel open for receiving server data.
HostIP192.168.0.100type: string
IP address of the remote system from which the panel was connected to the server.
HostPort30464type: string
port on the remote system open for receiving server data.

Example

IR.AddListener(IR.EVENT_RELEASE, IR.GetServer(), function (ID, LocalIP, LocalPort, HostIP, HostPort)
{
var time = IR.GetVariable("System.Time.24");
IR.Log("Release Client: "+time+", "+ID+", "+LocalIP+", "+LocalPort+", "+HostIP+", "+HostPort);
});

IR.EVENT_SCHEDULE_EVENT_CHANGE​

Event marking the start or finish of any scheduled event.

Important

Available only on the server.

Syntax

IR.AddListener(IR.EVENT_SCHEDULE_EVENT_CHANGE, 0, function(scheduleName, eventName, status){}, [pointer]);

InputValueDescription
function()function(){}type: function
anonymous function or function reference
pointer-type: object
pointer to the object serving as the function context (optional)
Output
scheduleName'Schedule 1'type: string
schedule name
eventName'Event N'type: string
event name
status1type: number
event state:
1 - IR.SCHEDULE_EVENT_STATE_START - started,
2 - IR.SCHEDULE_EVENT_STATE_RUN - running,
3 - IR.SCHEDULE_EVENT_STATE_FINISH - finished

Example

IR.AddListener(IR.EVENT_SCHEDULE_EVENT_CHANGE, 0, function(scheduleName, eventName, status)
{
if (eventName == "Light" && status == IR.SCHEDULE_EVENT_STATE_START)
{
IR.Log("Light on");
}
if (eventName == "Light" && status == IR.SCHEDULE_EVENT_STATE_FINISH)
{
IR.Log("Light off");
}
if (eventName == "Heating" && status == IR.SCHEDULE_EVENT_STATE_START)
{
IR.Log("Heater on");
}
if (eventName == "Heating" && status == IR.SCHEDULE_EVENT_STATE_FINISH)
{
IR.Log("Heater off");
}
});