Editing a schedule on the control panel
The schedule is stored in the server's memory. Its settings need to be changed from a smartphone or tablet screen. The iRidi platform provides a solution for this.
Demo project overview
The panel screen contains:
- the event list Event list,
- the event name field Name,
- the status indicator and switch Enabled,
- two fields displaying the event start and end date and time (Start and Finish),
- two fields for entering a new date and time, Enter new date-time,
- the button labeled UPDATE.
-f46dd822bab0bda915d51b44b675fd64.png)
The event list contains all events in the server's schedule. The user can select any event in the list, and its data appears in the fields to the right of the list.
The user enters new data in the Enter new date-time fields, uses the Enabled switch to select the event state (enabled/disabled), and then clicks UPDATE. The new data is then sent to the server and the schedule is updated. If the update succeeds, the updated schedule information is returned to the panel.
The demo project archive contains two ready-to-use projects:
- a server project (the file Schedule_edit.sirpz)
- a Panel Project (the file Schedule_edit.irpz).
Configuring the server project
- Add the virtual channel EventData_to_server and the virtual tag EventData_from_server.
- Add events to the schedule:
- Add the script:
var schedule = IR.GetScheduler("Schedule 1");
// creating a string with schedule data
var EventChanger = function() {
// writing schedule data in virtual tag
this.Write = function(in_events) {
var EventBuff = [];
for(var i in in_events) {
EventBuff.push({
"name": in_events[i].Name,
"end": in_events[i].End,
"start": in_events[i].Start,
"enable": in_events[i].enable
});
}
IR.SetVariable("Server.Tags.EventData_from_server", JSON.Stringify(EventBuff));
}
// reading schedule data in virtual tag
this.Read = function(in_schedule, in_NewData) {
var data = JSON.Parse(in_NewData);
var newData = JSON.Parse(data.join());
EventEdit = in_schedule.GetEvent(newData.name);
EventEdit.Start = newData.start;
EventEdit.End = newData.end;
EventEdit.Enabled = newData.enable;
EventEdit.Done(); // event update */
}
}
var EventsObj = new EventChanger();
// getting schedule data at server start
IR.AddListener(IR.EVENT_START,0,function() {
schedule = IR.GetScheduler("Schedule 1");
EventsObj.Write(schedule.GetEvents());
});
// getting new data from panel
IR.SetGlobalListener(IR.EVENT_GLOBAL_TAG_CHANGE, function(in_sName, in_sValue) {
var newData = in_sValue.split(',');
EventsObj.Read(schedule, newData);
EventsObj.Write(schedule.GetEvents());
});
// subscribing for tag changes
IR.SubscribeTagChange("Server.Channels.EventData_to_server");
- For a detailed description of the JS methods for server routines and schedules, follow this link.
- Save the project.
Configuring the Panel Project
- Add the iRidium Server driver. In Source Project, specify the saved server project file; in Host, specify the server's IP address.

- Click the server-project synchronization button.
- Add graphical items to the screen:
-e383ba26ed6c21d4710e9d133fafe145.png)
- Add the script:
var Server = IR.GetDevice("iRidium Server");
var ListBox = IR.GetItem("Page 1").GetItem("ListBox");
var EventNameField = IR.GetItem("Page 1").GetItem("EventName");
var EventStartField = IR.GetItem("Page 1").GetItem("EventStart");
var EventFinishField = IR.GetItem("Page 1").GetItem("EventFinish");
var EventStartFieldEdit = IR.GetItem("Page 1").GetItem("EventStartEdit");
var EventFinishFieldEdit = IR.GetItem("Page 1").GetItem("EventFinishEdit");
var UpdateButton = IR.GetItem("Page 1").GetItem("UpdateBtn");
var Lamp = IR.GetItem("Page 1").GetItem("Lamp");
var Switch = IR.GetItem("Page 1").GetItem("Switch");
var EventsObj;
// processing incoming and outgoing values for the server
var EventChanger = function(in_list, in_server) {
this.list = in_list; // link to GUI list with items and data
// read event data from virtual tag in JSON format and fill the list with items
this.Read = function(in_ChannelName, in_Value) {
if (in_ChannelName == "EventData_from_server") {
this.events = JSON.Parse(in_Value);
this.list.Clear();
for (var event in this.events) {
this.list.AddItem(null, {
"Item 1":
{
Text: this.events[event].name
}
});
}
fill(0);
}
}
// write new date-times of event in virtual tag
this.Write = function(eventName, startNewTime, finishNewTime, enableEvent) {
var newEventsData = {
"name": eventName,
"start": startNewTime,
"end": finishNewTime,
"enable": enableEvent
};
Server.Set("EventData_to_server", JSON.Stringify(newEventsData));
}
// populating the first item in the list
IR.AddListener(IR.EVENT_ITEM_SELECT, ListBox, function(item, subitem) {
fill(item);
}, this);
IR.AddListener(IR.EVENT_TAG_CHANGE, in_server, this.Read, this);
}
IR.AddListener(IR.EVENT_START,0,function() {
EventsObj = new EventChanger(ListBox, Server);
});
// filling fields with data
function fill(index) {
var event = EventsObj.events[index];
var startTime = new Date(event.start * 1000);
var finishTime = new Date(event.end * 1000);
var enableState = event.enable;
EventNameField.Text = event.name;
EventStartField.Text = startTime;
EventFinishField.Text = finishTime;
EventStartFieldEdit.Text = startTime;
EventFinishFieldEdit.Text = finishTime;
Lamp.Value = enableState;
Switch.Value = enableState;
}
// sending new data to server
IR.AddListener(IR.EVENT_ITEM_PRESS, UpdateButton, function() {
var eventName = EventNameField.Text;
var startNewTime = Math.floor(new Date(EventStartFieldEdit.Text) / 1000);
var finishNewTime = Math.floor(new Date(EventFinishFieldEdit.Text) / 1000);
var enableEvent = Switch.Value;
if (startNewTime > 0 && finishNewTime > 0)
EventsObj.Write(eventName, startNewTime, finishNewTime, enableEvent);
else
IR.Log("invalid date")
});
System testing
You can run the server project and Panel Project on a standard computer. The server project can be uploaded to iRidi server for Windows using iRidi transfer. The Panel Project runs in the emulator.