Uw opmerkingen

При тестировании проекта https://support.iridiummobile.net/communities/18/topics/21470-iridium-schedule-edit-server-client-project#comment-138847

выяснилось, что при Store In DB = String UTF8 запись значений происходит с некоторой задержкой,
т.е. если выключить сервер, то данные пропадут


1. Как это исправить?

2. Какое время записи в БД по умолчанию

на сервере (Win) настройки такие:

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

Нет, просто перенести имя фидбэка в кавычки, "16534" тоже должно работать, если фидбэк так называется

Channel_Feedback 16406

это было имя feedback'а, для Item'ов добавлять не надо

только должно быть верное имя feedback'а в сравнении

name=="abcde 16534"

по ссылке выше моем комментарии

IR.AddListener(IR.EVENT_TAG_CHANGE, IR.GetDevice("Modbus TCP")), function(name, value) 
{  
  IR.Log(" Name: " + name + " Value: " + value);
  if (name=="Channel_Feedback 16406") {
    var high = ((value >> 8) & 0xff);
    var low = value & 0xff;        
    IR.Log(value + " h: " + high + " l: " + low);
    //dev.Set("Channel_Command 16406", value );
  }
});

если не по событию

var dev=IR.GetDevice("Modbus TCP");
var value=dev.GetFeedback("Channel_Feedback 16406");