What is the difference between "Built-in iRidium drivers" and "JS Modules"?

Built-in (native) drivers are included in the standard iRidium base. Such drivers are quickly set up in GUI Editor. They are standardized and are provided with detailed instructions and examples.

Script drivers are always created on the base of the native AV & Custom Systems driver with the help of iRidium scripts (the programming language based on Java Script). They are used for controlling any systems which are not included int he standard iRidium base.

Usually the script drivers are distributed with the visualization project (for example, XBMC, Sonos, iTunes, ... ).

Javascript syntax checking

To debug without the 'syntax check',  make sure the log is set to start when the emulator starts (Tools | Options | Emulator | Show log at emulator start) and then run the emulator
If the script has an error in it, the start of the log will tell you, along with which line the error is on.

Logging Affects Performance of your projects

Please be aware of the fact that IR.Log calls in iRidium script will affect performance and should only be used when you are creating\developing  or troubleshooting your projects.  

This is relevant for low power devices ( IOS \ Android ) given their limited CPU power.

Before uploading a project which is to go into an live installation,  it recommended to search through the scripts in your project and comment out the logging lines (using \\  at the beginning of the IR.Log line).

"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"

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:

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:

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:
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 only via the script

Open Project Device Panel, select Driver, and change field Script Mode = Script Only
Image

How_Fixed.png

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

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)
/***** 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";  
}  
});

Parallax Effect (3D background in the project)


Use the script from example to make a Parallax Effect for your projects background.
Background Image should be bigger than the base page

Parallax_Effect.irpz

Custom Password in GUI for secured Page

If you want to create custom "edit box" item to secure access to some page of GUI,

you can use this script (see attachment, script is in the "JS" tab in GUI Editor)


Lists and Single/Double Tap on list item distinguishing

Hi everybody, 


I decided to write this post as I haven't found any clear solutions for the tasks I met. Writing a driver for Autonomic Mirage Media Server (MMS) I faced the necessity to provide a good way for the user to manage content of the media server so that the user could find and select the media to include into 'now playing' list. Imagine the following situation. A user wants to find a content to play by genre. I want to show on the popup both the list of genres as well as the list of albums related to the selected genre. Once the user choose a specific album, I want to show both the list of albums, related to the selected genre, as well as the list of songs within the selected album. Of course there are a number of ways how to organize that but I didn't want to have a mess of popups and I wanted the user to clearly understand the 'chain'. 

Thus I decided to do the following. A created a popup with a static list of 'list' popups. At once only two 'list' popups are visible. Once the user chooses the item in the left list within the 'list' popup, I scroll the static list so that the right 'list' popup becomes the left one and the third 'list' popup becomes visible... I didn't use the practice to populate a single list with different data as in a real life so called 'list popups' will have completely different layout.        


One more thing to be mentioned: I wanted to distinguish a single tap on the list item from a double tap and do different things. For instance I wanted to show special popup on the double tap on the item so that the user could choose whether to play the album/song immediately or just add it to the playlist.


In the attached project there are both technics are shown. Probably there is an easier way to do the same or I reinvented the wheel...


Vladimir Makarov


NestedLists.irpz

List Item Example project for Iridium V2.0

Q:
Is their an good Example out their showing the function of the "List Item". 
I found the example project under the Wiki page. But all comments are in Russian and the project does not have a function that you can actually press on the list items and some action will be executed.
 It would be nice if anyone has a good working example.

A:
Please try this project.

ListTest__2_.irpz

Custom Slider for the Level Item

In iRidium 2.1 you can use a slider from the ready list, available for each Level item. But if want to see your own slider on the Level to make it unique, please see this method.
Download the project from attachment. Here you can see the Level items, Slider items and Script file in [JS] window.  This script connects the Level with the separated Slider.
Using instances of the script you can make one, two or more Levels with unique Sliders.
alternate slider.irpz

3 state button

Need:
- item type = Level, name = Item 1
- item type =  Button, name = Item 2
- script 

1. For Item 1, create 3 states and changes property:

Feedback =  Channel
Min: 0
Max: 2


2. Item 2, for all state change property color alpha channel = 0;


3. open script editor (JS button)

4. create script

IR.AddListener(IR.EVENT_ITEM_RELEASE, IR.GetItem("Page 1").GetItem("Item 2"), function(){
   var item =  IR.GetItem("Page 1").GetItem("Item 1");
   item.Value = (item.Value + 1) % 3;      

   switch( item.Value )
   {
     case 0:
     // Commands
     break;

     case 1:
     // Commands
     break;

     case 2:
     // Commands
     break;
    }
});

3State_Buttons_2.irpz

Javascript Tutorials

Hi 

There 6 hours of tutorials going over the basics of Javascript.  Keep in mind that in some cases they will explain syntax which is unique to using Javascript in a browser.

https://www.youtube.com/playlist?feature=edit_ok&list=PLGJDCzBP5j3xKdHn-RYHvk3uafZSN0eYV">https://www.youtube.com/playlist?feature=edit_ok&list=PLGJDCzBP5j3xKdHn-RYHvk3uafZSN0eYV

thanks,


Roger


Сервис поддержки клиентов работает на платформе UserEcho