IP Control

717 views
Skip to first unread message

Dennis Williams

unread,
Feb 27, 2013, 7:56:44 PM2/27/13
to comman...@googlegroups.com
I posted a message earlier, apparently the code snipets I put in kept it from being displayed.  Here is my issue:
I have a Sony STR-DA5500ES that supports IP control.  I have gotten the control to work with a uPnP developer tool and used wireshark to capture the http post command needed to make it function.
It is a SOAP function with an XML payload and a custom header.  Both of these features trigger the browser to "preflight" the request.
Basically it sends out an OPTIONS request first to see if the server will accept the request, if there is no error response the actual command is sent.  Unfortunately my receiver responds to the preflight with an error.
I was able to get it to work using java in an android application.

I would like to get this working with iViewer, and have been reading up on the documentation.
My concern is, since iViewer uses the webkit java tools, will the http request be executed the same way it would be in a browser?  If it does the preflight, it isn't going to work for me.

Is there some easier way to do this?

Thanks
Dennis

Jarrod Bell

unread,
Feb 27, 2013, 10:02:31 PM2/27/13
to comman...@googlegroups.com
Have you tried using our CF.request API?
http://www.commandfusion.com/docs/scripting/net.html#cF.request

Regards,

Jarrod Bell
CommandFusion
www.commandfusion.com


--
You received this message because you are subscribed to the Google Groups "CommandFusion Software" group.
To unsubscribe from this group and stop receiving emails from it, send an email to commandfusio...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Dennis Williams

unread,
Feb 27, 2013, 10:19:55 PM2/27/13
to comman...@googlegroups.com


I am trying to figure out the logistics/mechanics of how to do that right now.  I'll experiment with it some.
Here is the command i need:

POST /upnp/control/CIS HTTP/1.1 HOST: 192.168.0.100:8888

SOAPACTION: "urn:schemas-sony-com:service:X_CIS:1#X_CIS_Command" CONTENT-TYPE: text/xml; charset="utf-8" Content-Length: 344

<?xml version="1.0" encoding="utf-8"?>

<s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">

<s:Body> <u:X_CIS_Command xmlns:u="urn:schemas-sony-com:service:X_CIS:1"> <CISDATA>0202A0213D</CISDATA> </u:X_CIS_Command> </s:Body> </s:Envelope>

Jarrod Bell

unread,
Feb 27, 2013, 10:47:08 PM2/27/13
to comman...@googlegroups.com
Checkout the Sonos module development to see some examples of more complex uses of CF.request:
https://github.com/CommandFusion/Sonos/tree/master/Current

In particular this one does some SOAP requests:
https://github.com/CommandFusion/Sonos/blob/master/Current/sonosplayer.js


Regards,

Jarrod Bell
CommandFusion
www.commandfusion.com


Barry Gordon

unread,
Feb 28, 2013, 12:04:39 AM2/28/13
to comman...@googlegroups.com

You should be able to deal with the Sony system using pure TCP.  AFter all SOAP and other higher level protocols really only send messages over TCP.  I have done it in VB and my experience with iViewer makes me believe it can also be done there just using a TCP control stack and the proper POST or GET strings with the proper headers and body information

--

Waldy,,,, Liverpool Uk

unread,
Feb 28, 2013, 4:05:45 AM2/28/13
to comman...@googlegroups.com
Hi Dennis,

I have the same amp and control it through serali/rs232. Sony are not great for feedback but I manage to control most of it. have you tried this way

Waldy,,,, Liverpool Uk

unread,
Feb 28, 2013, 6:44:53 AM2/28/13
to comman...@googlegroups.com
Sory Dennis,

It is the 5300 I have

Barry Gordon

unread,
Feb 28, 2013, 8:24:38 AM2/28/13
to comman...@googlegroups.com

I have all of the code to find and control SONY devices over IP and/or RS232. Specifically I have the code for the Blu Ray 7000ES changer.  One thing about Sony is that they are very good regarding the re-use of code, so all of their equipment will use the same TCP protocol IFIRC.   Unfortunately the code is written in VB not Javascript. The code is fairly table driven and If I recall correctly (IFIRC) it was working.  It was written as a test and explore program that I used when i got the changer initially. I also have the protocol documents from Sony. To control other Sony IP based devices the only thing that changes are the commands which was the same way Sony handled IR for their family of devices.  IFIRC the only difference between RS232 and TCP was the discovery and envelopes,  and not the commands. 

 

We can proceed in one of two way. I can give the code to whomever wants it as is and provide some help as it is not documented from a developers standpoint but rather from that of a user; or -

someone can send me a Sony Device that has an IP interface (with its manual) and I will port the code to Javascript and get it working.  If the later approach is chosen I will need about a week with the unit in my possession. The only rule is that I bear no expense (e.g. shipping) other than my time which I will donate.

 

If someone wants the former, email me and I will send you a zip archive or I will post the archive on my web site for others to download. If someone wants the later email me with your details (unit model) and a time frame and I will port the code now and be ready to test when the unit gets here.

Dennis Williams

unread,
Feb 28, 2013, 9:00:40 PM2/28/13
to comman...@googlegroups.com
Barry, you are correct, the sony commands for IP are the same as for RS232.  I have those commands and have it working in a simple native android application.
I was just hoping to use iViewer for more features than I can program into an android application.
This is for my own use at home, so i don't think i need the discovery etc.  I think for my purposes, i can just put the 10 or 15 codes i need in manually.
My receiver is several years old, a 2009 model, i don't know if it is the same as the newer ones.

So I took a look at the sonos modules as an example, and I think I have something close.
I am a little stumped as to how to get the script into guidesigner.
I used the script manager to add it - should I be able to use the edit button in the script manager to edit my scripts?
I get an error message that CF is not defined.



Is bonjour still not supported for android devices yet?
Below is a preliminary script with just an ON and OFF function - I am new to java scripting so any input would be helpful.
Do I need to have a CF.main in a script somewhere?





var SonyReceiver = function () {
   // static variables used by the receiver
  var self = {
        port:":8888", // default port to talk to Sony on
        IP:"192.168.0.100",
        host:"http://192.168.0.100:8888"}

     self.sendSoapRequest = function (url, xml, soapAction, callback) {
        Utils.debugLog("SOAP call made with url of: " + url + " and SOAP Action is: " + soapAction);
        var response = CF.request(url, "POST", {"SOAPAction":soapAction}, xml, function (status, headers, body) {
            if (status == 200) {
                Utils.debugLog("POST succeeded for SOAP Action: " + soapAction);
                body = Utils.unescape(body);
                if (typeof callback === 'function') {callback(true);}
                else {  return true; }
            }
            else {Utils.debugLog("POST failed with status " + status + ' for SOAP Action: ' + soapAction);
                return false;}
        });
    }


    self.SendCommand = function (command, callback) {
        var url =  self.host + '/upnp/control/CIS';
        var SOAPAction = 'urn:schemas-sony-com:service:X_CIS:1#X_CIS_Command';
        var CONTENTTYPE = 'text/xml; charset= "utf-8"'
        var SOAPBody = '<?xml version="1.0" encoding="utf-8"?>'+
        '<s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">'+
            '<s:Body>'+
                '<u:X_CIS_Command xmlns:u="urn:schemas-sony-com:service:X_CIS:1">'+
                '<CISDATA>'+command+'</CISDATA>'+
                '</u:X_CIS_Command>'+
            '</s:Body>'+
        '</s:Envelope>';
       
        self.sendSoapRequest(url, SOAPBody, SOAPAction, callback);
    }

  self.SendONCommand = function () {
      self.SendCommand("0202A0213D");
    }

  self.SendOFFCommand = function () {
      self.SendCommand("0202A0203E");
    }
    return self;
};



CF.modules.push({
    name:"Sony Receiver", // the name of the module (mostly for display purposes)
    object:SonyReceiver, // the object to which the setup function belongs ("this")
    version:1.0 // An optional module version number that is displayed in the Remote Debugger
});


--
You received this message because you are subscribed to a topic in the Google Groups "CommandFusion Software" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/commandfusion/gh3QhLSi3uw/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to commandfusio...@googlegroups.com.

Barry Gordon

unread,
Feb 28, 2013, 11:45:57 PM2/28/13
to comman...@googlegroups.com

Okay the fundamentals of CF iViewer and javascript are not easily delved out and understood. 

Lets define your root folder as whatever folder your gui is located in.

for convenience place a folder in your root folder and name it javascript. You will place all your javascript modules into that folder

There are other ways of doing this but this is the way I do it

 

open your gui file in guiDesigner. In the top of the left hand window which is holding the project tree is the project as the root of the tree.

Right click on this and click properties on the top of the window that opened. In the project properties window that has now opened click the bottom button titled Script Manager.

The window that now opens, the Script Manager is where you tell guiDesigner about your JS modules. Use the add script button and then in the line that appears use the browse button

 

The edit button will launch the javascript editor based on the association set up in windows for the extension .js.

You can edit the JS files with any text editor, but I suggest you get a good Javascript editor I use the Antechinus editor by cPoint technologies, not free but not too expensive.

 

One of your modules needs to have a Javascript function named CF.userMain().     WARNING: capitalization (case) counts in Javascript.

CF.userMain is called by iViewer after all of your Javascript modules have been loaded as the first thing to be executed.

 

Javascript modules are linked to display pages through the manipulation of joins and the command to load pages  CF.flipToPage("Name of Page")

Pages link back to Javascript through "Watches" and calls to Javascript functions. Watches are the method by which you can trap events such as a page flip,

or connection to an external control system,  or  responses from control systems (feedback)

 

I suggest you read the CF document named Scripting Beta which is on their web site at http://www.commandfusion.com/docs/scripting-beta/ It has a lot of key information

relative to using Javascript and how to get started.

 

I did not look at your code in detail so I cannot comment on it at this time.

 

My web (www.the-gordons.net) site has several projects on it which provide exemplars of how I do it.

The serial and IR control project, The Jandy Aqualink project, The JVC Projector project, and the XBMC project

all show the style I use on my projects but none of the use SOAP. 

I did all my SOAP work in VB when I had some Sony devices but that was before I started with the iPads.

 

Hope the above helps

Dennis Williams

unread,
Mar 2, 2013, 10:52:07 PM3/2/13
to comman...@googlegroups.com
Thanks for the overview Barry, I am slowly seeing the trees in the forest.
I have a simplified java script function to try out, but i don't think my scripts are executing.

I have simplified it down to a few functions and a couple of buttons on one screen to place comments in the log.
I am stuck on the remote debugger.  I have enabled it, manually entered a port (i can't get my device to show up in bonjour) and i can open the devices command fusion debug page in a browser.
It sticks on the Waiting for Remote Debugger page.
In browser is shows :
> Javascript interface up and running, opening connection with iViewer

I have read the manual several times, i don't know what else to do to get the browser to connect to the iViewer debug session.

Here is the contents of my java script file, do i have to do anything else in command fusion to load it, it is listed in my script manager  :

    CF.userMain= function () {
        CF.log("CF.userMain: *** Communications and Common function setup of Serial Main has been called");
 };

SendONCommand = function () {
      CF.log("CF.userMain: ON Button");
    };

SendOFFCommand = function () {
      CF.log("CF.userMain: OFF Button");
    };


// End of Module:   since there is nothing to "setup" no need to have a setup item or a this object
CF.modules.push({name:"Demo Main" });

Jarrod Bell

unread,
Mar 3, 2013, 12:23:01 AM3/3/13
to comman...@googlegroups.com
What browser version are you using? Make sure its latest chrome or safari.

And remove the CF.modules.push line, you don't need this as you don't have any modules in your script.

You might need to show the debugging console to see if there are JavaScript errors too. Syntax errors will not show in the debugger log, instead you use the browsers built in debugger tools:
http://www.commandfusion.com/docs/scripting/debug.html


Regards,

Jarrod Bell
CommandFusion
www.commandfusion.com


Barry Gordon

unread,
Mar 3, 2013, 12:35:26 AM3/3/13
to comman...@googlegroups.com

Do all the things Jarrod suggested. If you send me your system I will try it and see if it connects on my site.

 

It is not connecting. 

 

What I do is start the iviewer having the settings set to use the debugger on port 7009

 

Open chrome and enter as a URL in the address bar:    http://192.168.1.212:7009/  which is the address of the iPad and use port 7009. 

Error! Filename not specified.

Dennis Williams

unread,
Mar 3, 2013, 9:14:19 AM3/3/13
to comman...@googlegroups.com
Thanks Jarrod, i tried chrome instead of safari and it is connecting.  Not sure why the safari wasn't cooperating.

Still no joy with the scripting, however.  I am getting an error in the debugger, it looks like the debugger is requesting the script file from the device and it isn't there?

  1. Request URL:
  2. Request Method:
    GET
  3. Status Code:
    404 Not Found

I am loading the gui using the upload service. Shouldn't that be copied down to the device when it loads the gui?
Should i be able to find the .js file on the device somewhere?

Dennis Williams

unread,
Mar 3, 2013, 9:21:03 AM3/3/13
to comman...@googlegroups.com

I moved the .js script file to the same folder as my .gui and it loaded.  Looks like i am on my way to some real testing now.
I'll let you know how I make out.

Thanks for your help guys.

Dennis

Florent Pillet

unread,
Mar 3, 2013, 5:23:18 PM3/3/13
to comman...@googlegroups.com
I think this is because Safari on Windows is outdated and actually not supported by Apple anymore. Use Chrome, it works better.

Florent

On Mar 3, 2013, at 3:14 PM, Dennis Williams <dgato...@gmail.com> wrote:

Thanks Jarrod, i tried chrome instead of safari and it is connecting.  Not sure why the safari wasn't cooperating.

--
Florent Pillet - Software Engineering Lead



Dennis Williams

unread,
Mar 3, 2013, 9:45:43 PM3/3/13
to comman...@googlegroups.com
With you guys help getting to a starting point, I was able to try out my script sending the SOAP command to my receiver.  Only problem is that it is crashing iViewer.  I have been through sonos example and the java API, and I think I have everything correct.  I even tried sending a few of the fields as nulls to see if a simpler request would work, all with no success.
I sent in several crash reports, hopefully they help.

Here is my java script file, if anyone can see any issues with it.
Thanks
Dennis



CF.userMain= function() {

    CF.log("CF.userMain called");
 };

function SendCommand (command) {

        var url = '192.168.0.100:8888/upnp/control/CIS';

        var SOAPAction = 'urn:schemas-sony-com:service:X_CIS:1#X_CIS_Command';
    var CONTENTTYPE = 'text/xml; charset= "utf-8"'
    var SOAPBody = '<?xml version="1.0" encoding="utf-8"?>'+
        '<s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">'+
            '<s:Body>'+
                '<u:X_CIS_Command xmlns:u="urn:schemas-sony-com:service:X_CIS:1">'+
                    '<CISDATA>'+ command +'</CISDATA>'+

                '</u:X_CIS_Command>'+
            '</s:Body>'+
        '</s:Envelope>';
    CF.log("SOAP call made with url of: " + url + " and SOAP Action is: " + SOAPAction);
    CF.log("SOAP call made with SOAPBody of : " + SOAPBody);

        var response = CF.request(url,
        "POST",
        {"SOAPAction":SOAPAction, "CONTENTTYPE":CONTENTTYPE},
        SOAPBody,
        function(status, headers, body) {
            if (status == 200) {CF.log("Form data sent");}
            else {CF.log("Error: request returned status " + status);}
                    });
    CF.log("after SOAP call made");
    }

function SendONCommand () {

      CF.log("CF.userMain: ON Button");
      SendCommand("0202A0213D");
    }


function SendOFFCommand () {

      CF.log("CF.userMain: OFF Button");
      SendCommand("0202A0203E");
    }

Jarrod Bell

unread,
Mar 3, 2013, 9:50:48 PM3/3/13
to comman...@googlegroups.com
First verify it all works on an iOS device. Android is still in beta, and crash reports you send it are always appreciated.

Remove the 'var response = ' as the CF.request call doesn't actually return any data.
Everything is returned async in the callback function.


Regards,

Jarrod Bell
CommandFusion
www.commandfusion.com


Dennis Williams

unread,
Mar 3, 2013, 9:57:35 PM3/3/13
to comman...@googlegroups.com
Jarrod, unfortunately I don't have access to a iOS device.
I tried it with and without the 'var response = '

The CF.log enry after the CF.request call does execute - so I was thinking the crash could be happening during the asynchronous callback function processing.
But I also noticed in the scripting documentation that the actual command processing isn't exactly linear.

Thanks for the reply, let me know if you see anything in the crash report.

Thanks
Dennis

Florent Pillet

unread,
Mar 4, 2013, 6:35:29 AM3/4/13
to comman...@googlegroups.com
We're having trouble with the crash reports mechanism, so we don't get them anymore -- next build will enable them again so if you can keep around a copy of this crashing GUI it would be appreciated! Next build is scheduled to surface before the end of the week.

Florent

Dennis Williams

unread,
May 19, 2013, 12:32:05 AM5/19/13
to comman...@googlegroups.com

Okay, so I am back to working on getting IP control of my sony receiver working with iViewer for android.  I am using beta #151 on android 4.2.  I can't find any errors in the remote debugger.  The diagnostic messages show up in the logger, but i get no network traffic that i can see with wireshark.  I have verified that I can see network traffic with wireshark when I generate the same http request using a native android application i wrote.
It seems to me like the CF.request command for some reason isn't doing anything.  Below is my script - does anyone see any syntax errors?  I followed the example in the documentation as closely as possible.

Thanks
Dennis



Enter code here...


CF.userMain= function() {

        CF.log("CF.userMain called");
};



function SendCommand (command) {

        var url = '192.168.0.100:8888/upnp/control/CIS';
       var SOAPAction = 'urn:schemas-sony-com:service:X_CIS:1#X_CIS_Command';
 var CONTENTTYPE = 'text/xml; charset= "utf-8"'
 var SOAPBody = '<?xml version="1.0" encoding="utf-8"?>'+
               '<s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">'+
                '<s:Body>'+
                            '<u:X_CIS_Command xmlns:u="urn:schemas-sony-com:service:X_CIS:1">'+
                                    '<CISDATA>'+ command +'</CISDATA>'+
                            '</u:X_CIS_Command>'+
                  '</s:Body>'+
           '</s:Envelope>';
       CF.log("SOAP call made with url of: " + url + " and SOAP Action is: " + SOAPAction);
   CF.log("SOAP call made with SOAPBody of : " + SOAPBody);

claytonhdbahia

unread,
May 20, 2013, 6:58:51 PM5/20/13
to comman...@googlegroups.com
Well, today i get a license for my Galaxy Player and try to use CF.Request to control the xbmc, dont work. Some friends made the test to me and dont work too. Sometimes even getting feedback from my marantz block the connection with my GC, after that i cant control anything more in this connection.  Maybe there is something wrong with the Android version (151) or we are doing something wrong. Every thing its working in my ipad.


Em domingo, 19 de maio de 2013, Dennis Williams escreveu:

Okay, so I am back to working on getting IP control of my sony receiver working with iViewer for android.  I am using beta #151 on android 4.2.  I can't find any errors in the remote debugger.  The diagnostic messages show up in the logger, but i get no network traffic that i can see with wireshark.  I have verified that I can see network traffic with wireshark when I generate the same http request using a native android application i wrote.
It seems to me like the CF.request command for some reason isn't doing anything.  Below is my script - does anyone see any syntax errors?  I followed the example in the documentation as closely as possible.

Thanks
Dennis



Enter code here...

CF.userMain= function() {

        CF.log("CF.userMain called");
};



function SendCommand (command) {

        var url = '192.168.0.100:8888/upnp/control/CIS';
       var SOAPAction = 'urn:schemas-sony-com:service:X_CIS:1#X_CIS_Command';
 var CONTENTTYPE = 'text/xml; charset= "utf-8"'
 var SOAPBody = '<?xml version="1.0" encoding="utf-8"?>'+
       CF.request(url,
        "POST",
        {"SOAPAction":SOAPAction, "CONTENTTYPE":CONTENTTYPE},
          SOAPBody,
              function(status, headers, body) {
                      if (status == 200) {CF.log("Form data sent");}
                 else {CF.log("Error: request returned status " + status);}
                     });
    CF.log("after SOAP call made");
   }

function SendONCommand () {
--
You received this message because you are subscribed to the Google Groups "CommandFusion Software" group.
To unsubscribe from this group and stop receiving emails from it, send an email to commandfusio...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 


--
Enviado via Ipad

Florent Pillet

unread,
May 21, 2013, 9:14:50 AM5/21/13
to comman...@googlegroups.com
Prefix your URL with http://

Android is more sensitive than iOS to this. We're fixing this to automatically add the scheme (http) if it's missing. In the meantime, do this and the request will work.

There should be an error message appearing in the log but, due to something internally missing (now fixed), the error message never shows up.

Florent

On May 19, 2013, at 6:32 AM, Dennis Williams <dgato...@gmail.com> wrote:


Okay, so I am back to working on getting IP control of my sony receiver working with iViewer for android.  I am using beta #151 on android 4.2.  I can't find any errors in the remote debugger.  The diagnostic messages show up in the logger, but i get no network traffic that i can see with wireshark.  I have verified that I can see network traffic with wireshark when I generate the same http request using a native android application i wrote.
It seems to me like the CF.request command for some reason isn't doing anything.  Below is my script - does anyone see any syntax errors?  I followed the example in the documentation as closely as possible.


        var url = '192.168.0.100:8888/upnp/control/CIS';

Dennis Williams

unread,
May 22, 2013, 11:46:58 PM5/22/13
to comman...@googlegroups.com
Bingo, that did it, thanks for the help.

Dennis


--
You received this message because you are subscribed to a topic in the Google Groups "CommandFusion Software" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/commandfusion/gh3QhLSi3uw/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to commandfusio...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages