Похожие темы не найдены.
"IF" and "ELSE IF" conditions for Tag Change Event. Show Popup when the Driver Feedback = 1
Here is an Example for Modbus Driver.
The Modbus structure is not an "event based". It sends the value from each Feedback to iRidium each second, so the TAG_CHANGE_EVENT fires every time for the same value. It is not good when you use TAG_CHANGE_EVENT to make some action like Show Popup when the channel goes to 1 (popup showed every second in this case).
You can use an additional condition which triggering channel only ones, when it changes value from X to Y.
Example: "Show Popup when the Modbus Feedback = 1"
OpenPopupOnChange.irpz
The Modbus structure is not an "event based". It sends the value from each Feedback to iRidium each second, so the TAG_CHANGE_EVENT fires every time for the same value. It is not good when you use TAG_CHANGE_EVENT to make some action like Show Popup when the channel goes to 1 (popup showed every second in this case).
You can use an additional condition which triggering channel only ones, when it changes value from X to Y.
Example: "Show Popup when the Modbus Feedback = 1"
var reject = 0; // it locks the condition when the value not really changes IR.AddListener(IR.EVENT_TAG_CHANGE, IR.GetDevice("Modbus (TCP)"), function(name,value) { if (name == "Feedback 1" && value == 0) // feedback changes from 1 to 0 { reject = 0; } else if (name == "Command 2" && value == 1 && reject == 0) // feedback changes from 0 to 1 or it stays 1 for some time { IR.ShowPopup('Popup 1'); reject = 1; } });
OpenPopupOnChange.irpz
"OR" condition. Turn on the Item if one of feedbacks is not a zero
Use the script attached to work with the list of Feedback or List of Tokens by the OR condition.
You can use it, for example, when you need to activate item or make an action only if one of the feedbacks from the list > 0:
ONifOneTokenNotAzero.irpz
ONifOneChannelNotAzero.irpz
You can use it, for example, when you need to activate item or make an action only if one of the feedbacks from the list > 0:
var deviceName = "KNX"; // Driver Name var ChannelBuff = ['Dimmer', 'f32', 'u32', 's32', 'u16', 's16']; // List of Feedbacks var projectToken = "MyProjectToken"; // Project Token name function CheckChannels(DeviceID, _ChannelBuff, _Token) { DeviceID = IR.GetDevice(DeviceID); // Get the device ID for (var i = 0; i <= _ChannelBuff.length - 1; i++) // Check the Feedbacks if(DeviceID.GetFeedback(_ChannelBuff[i]) > 0) // If the Feedback > 0, then write 1 to Project Token IR.SetVariable("Global." + projectToken, 1) } IR.AddListener(IR.EVENT_TAG_CHANGE , IR.GetDevice(deviceName), function(name,value) { IR.SetVariable("Global." + projectToken, 0); CheckChannels(deviceName, ChannelBuff, projectToken); })
ONifOneTokenNotAzero.irpz
ONifOneChannelNotAzero.irpz
"IF" and "ELSE IF" for the data received. Change Item by receiving some Value
You have to to use this example to make a condition in your script:
Conditions in iRidium must be performed inside of EVENTS, which allows you to use some data, generated by events:
EVENT_TAG_CHANGE sends you a name and value of the Driver's Feedback in your project, which changes now. So, you can use a name of the feedback and value of this feedback in your conditions.
if (condition1 && condition2) { <action> };
Conditions in iRidium must be performed inside of EVENTS, which allows you to use some data, generated by events:
IR.AddListener(IR.EVENT_TAG_CHANGE , IR.GetDevice("MyDriver"), function(name,value) { <action> });
EVENT_TAG_CHANGE sends you a name and value of the Driver's Feedback in your project, which changes now. So, you can use a name of the feedback and value of this feedback in your conditions.
IR.AddListener(IR.EVENT_TAG_CHANGE , IR.GetDevice("MyDriver"), function(name,value) { if (name == "Feedback 1" && value == 100) { IR.Log("got 100 from Feedback 1"); IR.GetItem("Page 1").GetItem("Item 1").Value = 1; //got 100 but set 1 in Item } else if () { IR.Log("got something else"); } });
Pass an HTTP request variable in JSON format
When you send JSON object, then you must convert JSON object to string. For convert JSON object to string - please use function SON.Stringify
Description:
http://wiki2.iridiummobile.ru/Drivers_API#JSON.Stringify
Example:
error body contains invalid json - this answer from server. Maybe missed char end of line ',\r\n\r\n'.
Description:
http://wiki2.iridiummobile.ru/Drivers_API#JSON.Stringify
Example:
device.Send(['PUT,/api\r\n\HTTP/1.1,' + JSON.Stringify(request) + ',\r\n\r\n']);
error body contains invalid json - this answer from server. Maybe missed char end of line ',\r\n\r\n'.
Send command in HEX
Data are received from Telegram token in HEX format. The problem is that the function that.device.Send sends data in ASCII, not in HEX and then a wrong message is sent.
IR.AddListener(IR.EVENT_CHANNEL_SET,that.device,function(name) { that.Msg = IR.GetVariable("Drivers."+that.DriverName+".Telegram"); //Msg string will be "7F F2 FA 00 01 00 BD 67 FA FF FE 06 87 0D" IR.Log("Driver: Msg = "+ that.Msg); that.device.Send([that.Msg]); });
You can use something like
var value = parseInt("FF", 16);
to convert a hex string to a hex number
for(var cnt=0;cnt { partMSG=telegram.substring(cnt,cnt+2); partTel = parseInt(partMSG, 16); that.device.Send([partTel]); }
HTTP Send Command
To send the HTTP command via the script please use a following syntax
IR.GetDevice("DEVICE").Send(['GET,getverion\r\n HTTP 1.1', '\r\n\r\n']); IR.GetDevice("DEVICE").Send(['PUT,getverion\r\n HTTP 1.1', '\r\n\r\n']); IR.GetDevice("DEVICE").Send(['POST,getverion\r\n HTTP 1.1', '\r\n\r\n']);
Device.Send(['GET,/data/path/data.xml,']);use "," for end of string
Send several ir codes from a slider
Please take a look at the attached project, your IR commands have to be defined in the IRCodes array in the SendIR script.
LevelIR__1_.irpz
LevelIR__1_.irpz
Notifications for iOS
The iRidium notification system MUST NOT be used as the main one! iRidium notifications about important and potentially dangerous situations can be used as an auxiliary system to SMS, e-mail, notifications of the security system, etc.
At the moment notifications for the background mode (minimized or closed application) are not supported.
1. Notify about disconnecting from equipment (Offline)
At the moment notifications for the background mode (minimized or closed application) are not supported.
1. Notify about disconnecting from equipment (Offline)
/***** online notification ****/ IR.AddListener(IR.EVENT_OFFLINE, IR.GetDevice("My Driver"), function() { IR.GetItem("Page 1").GetItem("Item 1").Text = IR.GetVariable("System.Time.24") + " System Offline"; // notification IR.GetItem("Page 1").GetItem("Item 1").GetState(0).TextColor = 0xFF0000FF; // text color });3. Automatic opening of the popup when activating a channel
/***** event notification (Tag Change) ****/ var old_value1 = -1; // do not show notification if the previous state is the same var old_value2 = -1; IR.AddListener(IR.EVENT_START, 0, function() { IR.AddListener(IR.EVENT_TAG_CHANGE, IR.GetDevice("My Driver"), function(name, value) { if (name == 'Channel 10' && value == 1 && value != old_value1){ // Check the Value = 1 in Feedback "Channel 10" IR.ShowPopup("Notify_danger"); IR.GetItem("Popup 1").GetItem("Item_Display").Text = IR.GetVariable("System.Time.24") + " Lamp in Garden broken"; old_value1 = value; } else if (name == 'Channel 10' && value == 2 && value != old_value2){ // Check the feedback "Channel 10'" IR.ShowPopup("Notify_important"); IR.GetItem("Popup 1").GetItem("Item_Display").Text = IR.GetVariable("System.Time.24") + " Lamp in Garden Response Failed. Please Check"; old_value2 = value; } });4. Play a sound at channel activation
/***** event notification (Tag Change) ****/ IR.AddListener(IR.EVENT_START, 0, function() { IR.AddListener(IR.EVENT_TAG_CHANGE, IR.GetDevice("My Driver"), function(name, value) { if (name == 'Channel 11' && value == 1){ // Check the Value = 1 in Feedback "Channel 11" IR.PlaySound('BEEP1.WAV',1,70); // Play Sound ('name',slot,volume) IR.GetItem("Page 1").GetItem("Item 5").Text = IR.GetVariable("System.Time.24") + " Incoming Call"; } });
Сервис поддержки клиентов работает на платформе UserEcho