0
Waiting for user's reply

Correct Syntax for TCP feedback

Iain Brew 7 years ago in iRidium Script updated by damian flynn 7 years ago 5

Hello

I have a Yamaha AVR which I want to show feedback for inputs, volume etc. I am trying to understand the Javascript side of things. For example, if I want feedback as to the current volume, I query the AVR using "@MAIN:VOL=?" to which it responds a numerical value. 


I want to show this numerical item on a text item. Am I on the right track?


var driver =IR.GetDevice("Yamaha RXV-1067");
IR.AddListener(IR.EVENT_RECEIVE_DATA, driver, function("@MAIN:VOL=?")
{
   IR.Log(yamaha_volume) 
   IR.SetVariable("Drivers.Yamaha RXV-1067.yamaha_volume");          
});


Waiting for user's reply

hello

Your script is uncorrect/

1) You you use EVENT_RECEIVE_DATA then you will get data in hex format. You should use EVENT_RECEIVE_TEXT

2) parameter in function is Incorrect. You should write function(text). When device send something in script, then iridium put it in "text" variable. if you write IR.Log(text) then you will see inforamtion from device. 

You should use somethinf like this

var driver =IR.GetDevice("Yamaha RXV-1067");
IR.AddListener(IR.EVENT_RECEIVE_TEXT, driver, function(text)
{

              if(text.indexOf("@MAIN:VOL") != -1) {
                           Here you should get the value and write it in variable
                }

       
});

Hi Ilya

Thank you for your response. Would the following then be correct (my JS knowledge is super limited haha)? Also to note, the actual command has a question mark - "@MAIN:VOL=?" - is your script saying, if this number has changed by plus or minus one, update the output?


----- 


var driver =IR.GetDevice("Yamaha RXV-1067"); 

IR.AddListener(IR.EVENT_RECEIVE_TEXT, driver, function(text) 

{

              if(text.indexOf("@MAIN:VOL") != -1) 

{             IR.SetVariable("Drivers.Yamaha RXV-1067.yamaha_volume");}

] });


-----


You script is incorrect. You has device protocol. In this protocol you can find something like this:

"if you send request to device @MAIN:VOL=?, then the device will answer @MAIN:VOL=100" It means that devices will send to you a message with volume level. So, we has 2 tasks. 


First task - we should identify the message. For this task we use text.indexOf command. This command will search @MAIN:VOL= string in messege. If command will find it, then it will receive you a position of this substring in message


Second task - we should find the volume level. There are several ways to get it. For example, we can get the substring from the end of @MAIN:VOL= till the end of message and it will be the volume value. So, you should use something like this

var driver = IR.GetDevice("Yamaha RXV-1067"); 
IR.AddListener(IR.EVENT_RECEIVE_TEXT, driver, function(text) 
{
  if(text.indexOf("@MAIN:VOL") != -1)   
{             
var volume = text.substring(text.indexOf("@MAIN:VOL") + 10,text.length-1)
IR.SetVariable("Drivers.Yamaha RXV-1067.yamaha_volume", volume);
}
});



I recomend you to watch our script webinar http://www.iridiummobile.net/academy/script_driver_pro/ There you will find all answers

Once again, thank you for your help! I will try this new script and will watch the tutorial, including continuing reading of 'Eloquent Javascript'

Ian 


If you still need help and have the protocol document, I’ll create a skeleton driver to get you going. 


Let me know

Damian