Uw opmerkingen

Which version are you using on the server?

You must reboot server after 1min or press ESC key twice

https://translate.google.com/translate?sl=ru&tl=en&u=https%3A%2F%2Fsupport.iridiummobile.net%2Fcommunities%2F5%2Ftopics%2F12955-sohranenie-znachenij-tegov-na-servere-iridium%23comment-138979

Good afternoon.
Thanks for the information provided.
Indeed, when choosing Store in DB = UTF-8, the interval is 1 minute (more precisely, no more than 1 minute). However, the choice of strategy (by changing the value or by the interval) is absent in the studio settings (both old and new). After your appeal, we decided to add the possibility of choosing a conservation strategy to the database, but the implementation deadlines have not yet been determined. We will inform you when ready.

https://support.iridiummobile.net/s/attachments/15553/18/11018/a7f9f2d84eec2f1982ffeba051241053.bmp

Sorry, it's old code

Server.js

moderator: please, edit message above

server (correct formatting)

function clone(obj) {
    if (null == obj || "object" != typeof obj) return obj;
    var copy = obj.constructor();
    for (var attr in obj) {//if (obj.hasOwnProperty(attr))
         copy[attr] = obj[attr];
    }
    return copy;
}


//IR.Log("ENUM " + createNewProperty);


var schedule = IR.GetScheduler("Schedule 1");
// creating a string with schedule data
var EventChanger = function() {
var EventBuff = [];

//function EventP() { }

//MonkeyPathcing
var EventProt = {
    //constructor: EventP,
    Name: undefined,     // event name
    Start: undefined,   // event start date-time
    End: undefined,  // event finish date-time
    Enabled: undefined,
    Type: undefined,
    //Parent: undefined,
    Day: undefined,
    End: undefined,
    WeekDays: undefined,
    RepeatEnd: undefined,
    MonthRepeatType: undefined,
    MonthDays: undefined,
    DayNumber: undefined,
    WeekDay: undefined,
    StartSunType: undefined,
    //TODO: Sun Offset
}
    //EventP.prototype=EventProt;
    
 /* 
var Event = function(inp) {
    this.Name;     // event name
    this.Start;   // event start date-time
    this.End;  // event finish date-time
    this.Enabled;
    this.Type;
    this.Day;
    this.End;
    this.WeekDays;
    this.RepeatEnd;
    this.MonthRepeatType;
    this.MonthDays;
    this.DayNumber;
    this.WeekDay;
    this.StartSunType;
    //TODO: Sun Offset
    for (var inpn in inp) {
    this[inpn] = inp[inpn];
        //if (inp.hasOwnProperty(inpn) && inp[inpn]!==undefined){ 
            //IR.Log("add prop " + inpn.toString() + " = " + inp[inpn]);        
            //this[inpn.toString()] = inp[inpn];
            //}
    }
} 
*/

// writing schedule data in virtual tag
  this.Write = function(in_events) {
  
 
    EventBuff = [];
    for(i in in_events) {
    //.propertyIsEnumerable("Name"));
    //IR.Log ("PROTEIN " + in_events[i].__proto__);
    
    
        in_events[i].__proto__= EventProt;
        //for(j in  in_events[i]) {
        //    IR.Log("Enumerable " + j + " == " + in_events[i][j]);
        //}
        
        var d2 = clone(in_events[i]);

        //var NEvent = new Event(in_events[i]);
      EventBuff.push(d2);
    }
    var string = JSON.Stringify(EventBuff);                     
    IR.SetVariable("Server.Tags.EventData_from_server", string);   
  }   
// reading schedule data in virtual tag 
  this.Read = function(in_schedule, in_NewData) { 
    EventEdit = in_schedule.GetEvent(in_NewData.Name);
    EventEdit.Start = Math.floor(new Date(in_NewData.Start));
    EventEdit.End = Math.floor(new Date(in_NewData.End));
    EventEdit.Enabled = (in_NewData.Enabled == 1);
    EventEdit.Done();  // event update
  }  
}

var EventsObj = new EventChanger();
// getting schedule data at server start
IR.AddListener(IR.EVENT_START,0,function() {
  var svdData = IR.GetVariable("Server.Tags.EventData_from_server");
  var schedule = IR.GetScheduler("Schedule 1");

  if (svdData)
  {
     IR.Log("SAVEVED DAta " + svdData);
     EventsObj.Read(schedule, JSON.Parse(svdData));
  }
  else {
    events = schedule.GetEvents();
    EventsObj.Write(events); 
  }  
});

// getting new data from panel
IR.SetGlobalListener(IR.EVENT_GLOBAL_TAG_CHANGE, function(in_sName, in_sValue) {

  var newData = JSON.Parse(in_sValue);
  EventsObj.Read(schedule, newData);
  events = schedule.GetEvents();
  EventsObj.Write(events); 
});
 
// subscribing for tag changes
IR.SubscribeTagChange("Server.Channels.EventData_to_server");

here with some modifications

server

function clone(obj) {
    if (null == obj || "object" != typeof obj) return obj;
    var copy = obj.constructor();
    for (var attr in obj) {//if (obj.hasOwnProperty(attr))
         copy[attr] = obj[attr];
    }
    return copy;
}

if (!Array.isArray) {
  Array.isArray = function(arg) {
    return Object.prototype.toString.call(arg) === '[object Array]';
  };
}

var schedule;
// creating a string with schedule data
var EventChanger = function() {
var EventBuff = [];

//function EventP() { }

//MonkeyPathcing
var EventProt = {
    //constructor: EventP,
    Name: undefined,     // event name
    Start: undefined,   // event start date-time
    End: undefined,  // event finish date-time
    Enabled: undefined,
    Type: undefined,
    //Parent: undefined,
    Day: undefined,
    End: undefined,
    WeekDays: undefined,
    RepeatEnd: undefined,
    MonthRepeatType: undefined,
    MonthDays: undefined,
    DayNumber: undefined,
    WeekDay: undefined,
    StartSunType: undefined,
    //TODO: Sun Offset
}
    //EventP.prototype=EventProt;
    
 /* 
var Event = function(inp) {
    this.Name;     // event name
    this.Start;   // event start date-time
    this.End;  // event finish date-time
    this.Enabled;
    this.Type;
    this.Day;
    this.End;
    this.WeekDays;
    this.RepeatEnd;
    this.MonthRepeatType;
    this.MonthDays;
    this.DayNumber;
    this.WeekDay;
    this.StartSunType;
    //TODO: Sun Offset
    for (var inpn in inp) {
    this[inpn] = inp[inpn];
        //if (inp.hasOwnProperty(inpn) && inp[inpn]!==undefined){ 
            //IR.Log("add prop " + inpn.toString() + " = " + inp[inpn]);        
            //this[inpn.toString()] = inp[inpn];
            //}
    }
} 
*/

// writing schedule data in virtual tag
  this.Write = function(in_events) {
  
 
    EventBuff = [];
    for(i in in_events) {
    //.propertyIsEnumerable("Name"));
      in_events[i].__proto__= EventProt;       
      var d2 = clone(in_events[i]);
      EventBuff.push(d2);
    }
    var string = JSON.Stringify(EventBuff);                     
    IR.SetVariable("Server.Tags.EventData_from_server", string);   
  }   
// reading schedule data in virtual tag 
  this.Read = function(in_schedule, in_NewData) { 
    for (u=0;u<in_newdata.length;++u) {="" in_newdata_u="in_NewData[u];" ir.log("update="" "="" +="" in_newdata_u.name);="" eventedit="in_schedule.GetEvent(in_NewData_u.Name);" eventedit.start="Math.floor(new" date(in_newdata_u.start));="" eventedit.end="Math.floor(new" date(in_newdata_u.end));="" eventedit.enabled="(in_NewData_u.Enabled" =="1);" eventedit.done();="" event="" update="" }="" var="" eventsobj="new" eventchanger();="" getting="" schedule="" data="" at="" server="" start="" ir.addlistener(ir.event_start,0,function()="" svddata="IR.GetVariable("Server.Tags.EventData_from_server");" 1");="" if="" (svddata)="" ir.log("saveved="" svddata);="" eventsobj.read(schedule,="" json.parse(svddata));="" else="" events="schedule.GetEvents();" eventsobj.write(events);="" });="" new="" from="" panel="" ir.setgloballistener(ir.event_global_tag_change,="" function(in_sname,="" in_svalue)="" newdata="JSON.Parse(in_sValue);" ?="" [newdata]:newdata;="" newdata);="" systembase.execute("commit");="" subscribing="" for="" tag="" changes="" ir.subscribetagchange("server.channels.eventdata_to_server");="" <="" pre=""></in_newdata.length;++u)>

client

var Server = IR.GetDevice("iRidium Server");
var ListBox = IR.GetItem("Page 1").GetItem("ListBox");
var EventNameField = IR.GetItem("Page 1").GetItem("EventName");
var Lamp = IR.GetItem("Page 1").GetItem("Lamp");
var Switch = IR.GetItem("Page 1").GetItem("Switch");
var EventStartField = IR.GetItem("Page 1").GetItem("EventStart");
var EventFinishField = IR.GetItem("Page 1").GetItem("EventFinish");
var EventStartField1 = IR.GetItem("Page 1").GetItem("EventStart 1");
var EventFinishField1 = IR.GetItem("Page 1").GetItem("EventFinish 1");
var UpdateButton = IR.GetItem("Page 1").GetItem("UpdateBtn");

var EventsObj;


var selectedItem = 0;

var events = [];

var EventProt = {}

/* var Event = function(inp) {
    this.Name;     // event name
    this.Start;   // event start date-time
    this.End;  // event finish date-time
    this.Enabled;
    this.Type;
    this.Day;
    this.End;
    this.WeekDays;
    this.RepeatEnd;
    this.MonthRepeatType;
    this.MonthDays;
    this.DayNumber;
    this.WeekDay;
    //TODO: Sun Offset
    for (var inpn in inp) {
        if (inp.hasOwnProperty(inpn)) 
            this[inpn] = inp[inpn];
    }
}
    
*/


var EventChanger = function(in_list) {

  var list = in_list;    //  link to GUI list with items and data
  var that = this;  
// 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") {   
      //IR.Log("Now we parse " + in_Value);
      events = JSON.Parse(in_Value);
      for (i in events) {
        list.CreateItem(parseInt(i), 1, {Text: events[i].Name});
      }
      fill(selectedItem);
    }
  }
// write new date-times of event in virtual tag 
  this.Write = function(NEvent) {
    Server.Set("EventData_to_server", JSON.Stringify(NEvent));
  }
}

IR.AddListener(IR.EVENT_START,0,function() {
  EventsObj = new EventChanger(ListBox);
}); 

IR.AddListener(IR.EVENT_ITEM_SELECT, ListBox, function(item, subitem) {
  selectedItem = item;
  fill(selectedItem);
});
      
IR.AddListener(IR.EVENT_TAG_CHANGE, Server, function(name, value) {
  EventsObj.Read(name, value);
});
 
 
fill = function (in_item) {
  startTime = new Date(events[in_item].Start * 1000);
  finishTime = new Date(events[in_item].End * 1000);
  EventNameField.Text = events[in_item].Name;
  Lamp.Value = events[in_item].Enabled;
  Switch.Value = events[in_item].Enabled;
  EventStartField.Text = startTime;
  EventFinishField.Text = finishTime;
  EventStartField1.Text = startTime;
  EventFinishField1.Text = finishTime;
}

IR.AddListener(IR.EVENT_ITEM_PRESS, UpdateButton, function() {

  startTime = new Date(EventStartField1.Text);
  finishTime = new Date(EventFinishField1.Text);
  
  //var NEvent = new Event({Name:EventNameField.Text, Start: Math.floor(startTime.getTime()/1000), End: Math.floor(finishTime.getTime()/1000), Enabled: Switch.Value});
  var NEvent = {Name:EventNameField.Text, Start: Math.floor(startTime.getTime()/1000), End: Math.floor(finishTime.getTime()/1000), Enabled: Switch.Value};
  EventsObj.Write(NEvent); 
});

linked:

https://support.iridiummobile.net/communities/5/topics/12357-log-of-channels-and-feedbacks-in-ui#comment-74761

https://support.iridiummobile.net/communities/5/topics/12955-sohranenie-znachenij-tegov-na-servere-iridium

IR.AddListener(IR.EVENT_START,0,function()
{
   //AV & Custom Systems (File)
   var device = IR.CreateDevice(IR.DEVICE_CUSTOM_STREAM, "name", {FileName:'/home/user/abc'});
   var val = 0;
   IR.AddListener(IR.EVENT_ONLINE, device, function()
   {
     IR.Log("ONLINE");
   });
 
    IR.AddListener(IR.EVENT_OFFLINE, device, function()
   {
     IR.Log("OFFLINE");
   });
 
   IR.AddListener(IR.EVENT_RECEIVE_DATA, device, function(data)
   {
     IR.Log("DATA RECEIVED: " + data);
   });
 
   function Blink()
   {
     val = (val) ? 0 : 1;
     if(device)
     device.Send([val.toString()]);
   }
 
   //IR.SetInterval(5000, Blink);
  });
$ echo command:1 > /home/user/abc
ls -l /home/user/abc
chmod 744 /home/user/abc

Arjan, have you solved your task?