This page is a
translated version of the page
JS Samples and the translation is 100% complete.
The section is under development.
Examples of using iRidium API
Examples of using iRidium API methods and functions
« Guide
« Handbook
Examples of using iRidium JavaScript API with descriptions
Updated: 06.2.2019
Source language: JavaScript
Language version: 1.5
Specification: ECMAScript Edition 3
The JS version that we use is not the latest
one and it does not support new constructions,
but its functions are enough for panel projects
in 99% of all cases. To satisfy the remaining
one per cent converters of the https://babeljs.io
type can be used and of course experience
and developer's skills help.
Report an error
Drivers (DDK, Drivers API)
Examples of creating and editing driver settings with the help of iRidium API
Custom TCP Server in iRidium Client
Custom Server on the basis of the AV & Custom Systems driver can take client connections on the basis of AV & Custom Systems and third-party applications. It can also process data sent by the client and send commands to it.
Remember, the server launched in the i3 pro application works only until the application is launched and the server cannot store the database as the iRidium Server specialized solution.
Use of "the server on a client" is very limited. It can be used only for synchronization of some data between control panels, when installation of iRidium Server is not possible for some reason.
// TCP server on port 5678
function start_tcp_server(server_name)
{
// name, port, max connections
var name = server_name;
var port = 5678;
var max_clients = 10;
var tcp_device = IR.CreateDevice(IR.DEVICE_CUSTOM_SERVER_TCP, name, "", port, max_clients);
// start server
tcp_device.Connect();
// inform when the server online
IR.AddListener(IR.EVENT_ONLINE, tcp_device, function(text)
{
IR.Log("Server is ONLINE");
});
// register connected client
IR.AddListener(IR.EVENT_ACCEPT, tcp_device, function(id)
{
IR.Log(tcp_device + " ACCEPT CLIENT "+id);
});
// process received data
IR.AddListener(IR.EVENT_RECEIVE_TEXT, tcp_device, function(text)
{
//IR.Log("INPUT DATA: "+text);
var strings = text.split('\r\n');
var string;
while(string = strings.shift())
{
var parts = string.split(":"); // parse the string with ":" devider
switch(parts[0])
{
case "LOG": // if the first substring of received data = "LOG"
IR.GetItem("Page 1").GetItem("Item 1").GetState(0).Text = IR.GetVariable("System.Time.24")+" "+parts[1];
IR.Log(IR.GetVariable("System.Time.24")+" "+parts[1]);
break;
case "ERROR": // if the first substring = "ERROR"
IR.GetItem("Page 1").GetItem("Item 2").GetState(0).Text = IR.GetVariable("System.Time.24")+" "+parts[1];
IR.Log(IR.GetVariable("System.Time.24")+" "+parts[1]);
break;
case "DATABASE": // if the first substring = "DATABASE"
IR.Log(parts[1]);
break;
}
}
});
}
// start the server when project starts
start_tcp_server("Custom Server TCP");
Interface (GUI API)
Examples of controlling properties of pages, popups and graphic items with the help of iRidium API
Animation of Items with the Help of IR.Tween
The tweener specifies the variable value in the indicated segment calculated by some formula. It allows you to create animation with object movements on a particular segment of the indicated curve.
The tweener can be used for the gradual appearance of a popup from the screen side. Use the linear tweener for the popup to move straightforward.
function ShowTop()
{
TopTween("Popup 1", 820, 34, 250); // popup, X, Y, moving range from Top
}
////////////////////////////////////////////////////////////////////////////////
// Creating Effects
////////////////////////////////////////////////////////////////////////////////
var timer = 0;
var speed = 20; // showing speed
function TopTween(popup, X, Y, range)
{
IR.ShowPopup(popup);
IR.GetItem(popup).X = X;
var Tm = IR.SetInterval(1, function()
{
timer++;
var Tween = IR.Tween("TWEEN_LINEAR", timer, 0, range, speed);
IR.GetItem(popup).Y = Y+Tween;
if (timer > speed) IR.ClearInterval(Tm); timer = 0;
});
}
Font Control
You can set the font or change the font size for the item via the .FontId
state property.
FontId - the font identifier. It stores the pointer to the font and the font size. You cannot change the font size separately.
Create a new font and assign it to the item state via FontId. For creation of new fonts it is important to use the identifiers which have not been used in the project (the editor creates its own system fonts using identifiers beginning with 1). For getting free id, your should use js method IR.FreeFontID
Indicate which font file must be used as a basis, what size must be set up. Assign a font identifier not used in the project before:
var Font=IR.FreeFontID; //Get free font ID
IR.CreateFont(Font, "tahoma.ttf", IR.GetItem("Страница 1").GetState(0).FontSize+10);//Create new font with new size and id
IR.GetItem("Страница 1").GetState(0).FontId=Font;//Set new font to the state
Notifications (Push API)
Sending of Push notifications to control panels. The notifications are sent by the server (there are no any other possibility to do it in v1.0.10).
1 "'Create groups of control panels"'
By default, none of control panels will receive Push notifications until you place it in the Group of panels that can get Push notifications.
The groups are set up on the web site, see the instructions.
Each group has an ID and name. That is the group ID you will use when indicating which panels have to get notifications.
2 "'Set up the script for sending notifications from the server"'
In the server project create a new script file. Add the condition for notification sending and the command for sending Push notifications in it. The condition for sending Push notifications can be change of any server variable - associated with the driver or a virtual one.
Example:
send a notification when channel "Address 1" of the "KNX" driver takes value 1. The notification will be received by the group panels with ID = 1.
function sendPush (text, group)
{
IR.SendPush(text, "", group);
// text - message that will be displayed in notification
// group - group of Panels seted up in Cloud Object properties on iRidium Mobile web site
}
IR.AddListener(IR.EVENT_TAG_CHANGE, IR.GetDevice("KNX"), function(name, value)
{
if (name == "Address 1" && value == 1)
{
sendPush("Leakage in the kitchen! The water supply is turned off", 1);
}
});
No additional settings and scripts are required on the control panel with i3 pro. The panel will get notifications if it is in the specified group.