d_gatorfan Posted February 15, 2013 Posted February 15, 2013 I have not purchased and ISY yet, but I am planning to soon. I have quite a few INSTEON devices and would like to get a central control system. Part of that would be integrating my home theater system. To that end I am close to figuring out how to control my SONY STR-DA5500ES receiver via IP. For testing I am trying to write a simple html page with an on/off button and volume up/down. I have been able to turn the device on and off successfully via IP by using a uPnP developer tool to write the appropriate code to the device. I was able to use wireshark to capture the network traffic (a SOAP command) which is below. The CISDATA parameter is the appropriate control code from list of commands (volume/up/down on/off etc). At the bottom is the javascript function I ended up with to try to generate that SOAP command. The HTML code does not seem that complicated, but I am at a loss to get it working. Is there an easier method? I have little to no HTML programming experience - so it may be something simple I am missing. Any help or suggestions would be appreciated. Thanks Dennis 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"?> 0202A0213D Here is the JavaScript Function I came up with : function soap() { var objXMLHttpRequest = new XMLHttpRequest(); objXMLHttpRequest.open("POST", "http://192.168.0.100:8888/upnp/control/CIS ", true); // build SOAP request var packet = '<?xml version="1.0" encoding="utf-8"?>'+ ''+ ''+ ''+ '0202A0213D'+ ''+ ''+ ''; // set SOAP headers objXMLHttpRequest.setRequestHeader("SOAPACTION", "urn:schemas-sony-com:serviceId:X_CIS:1#X_CIS_Command"); objXMLHttpRequest.setRequestHeader("CONTENT-TYPE", "text/xml; charset=utf-8"); // send SOAP request objXMLHttpRequest.send(packet); }
Michel Kohanim Posted February 15, 2013 Posted February 15, 2013 Hello Dennis, Are you getting any type of errors? With kind regards, Michel
d_gatorfan Posted February 15, 2013 Author Posted February 15, 2013 As I pasted the function, i get this error message. It doesn't actually send a POST command but an OPTION command. Request URL: http://192.168.0.100:8888/upnp/control/CIS Request Method: OPTIONS Status Code: HTTP/1.1 405 Method Not Allowed Request Headers User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0Pragma:no-cacheOrigin:nullHost:192.168.0.100:8888Connection:keep-aliveCache-Control:no-cacheAccess-Control-Request-Method:POSTAccess-Control-Request-Headers:content-type,soapactionAccept-Language:en-US,en;q=0.5Accept-Encoding:gzip, deflateAccept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Response Headers X-AV-Server-Info:av=5.0; hn=""; cn="Sony Corporation"; mn="STR-DA5500ES"; mv="1.0"; Server:Trimedia pSOS+/NDK4.3 UPnP/1.0 MediabolicUPnP/-20110626.103844Content-Type:text/html; charset=utf-8Connection:close If I comment out the SetRequestHeader commands, it gives me a different error but actually sends a post command. It just doesn't have the headers that the working post command from the uPnP tool does. http://192.168.0.100:8888/upnp/control/CIS Request Method: POST Status Code: HTTP/1.1 400 Bad Request Request Headers User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64;rv:18.0) Gecko/20100101 Firefox/18.0Pragma:no-cacheOrigin:nullHost:192.168.0.100:8888Content-Type:text/plain; charset=UTF-8Content-Length:303Connection:keep-aliveCache-Control:no-cacheAccept-Language:en-US,en;q=0.5Accept-Encoding:gzip, deflateAccept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Response Headers X-AV-Server-Info:av=5.0; hn=""; cn="Sony Corporation"; mn="STR-DA5500ES"; mv="1.0";Server:Trimedia pSOS+/NDK4.3 UPnP/1.0 MediabolicUPnP/-20110626.103844Content-Type:text/html; charset=utf-8Connection:close My best guess is there is something wrong with the objXMLHttpRequest.setRequestHeader commands. Thanks so much for taking a look. Dennis
Michel Kohanim Posted February 15, 2013 Posted February 15, 2013 Hi Dennis, I do not see a SOAPACTION header. I think the best thing to do would be to use Wireshark to capture the actual traffic. Also, I have never seen an OPTION header. With kind regards, Michel
d_gatorfan Posted February 15, 2013 Author Posted February 15, 2013 With the function as shown above traffic does not show a POST command, but switches to an OPTIONS command with a mention of POST in the header. OPTIONS /upnp/control/CIS HTTP/1.1 Host: 192.168.0.100:8888 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate Origin: null Access-Control-Request-Method: POST Access-Control-Request-Headers: content-type,soapaction Connection: keep-alive Pragma: no-cache Cache-Control: no-cache This is the response : HTTP/1.1 405 Method Not Allowed Server: Trimedia pSOS+/NDK4.3 UPnP/1.0 MediabolicUPnP/-20110626.103844 X-AV-Server-Info: av=5.0; hn=""; cn="Sony Corporation"; mn="STR-DA5500ES"; mv="1.0"; Content-type: text/html; charset=utf-8 Connection: close If I comment out the two setRequestHeader functions I get this network traffic that returns a bad request error. POST /upnp/control/CIS HTTP/1.1 Host: 192.168.0.100:8888 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate Content-Length: 303 Content-Type: text/plain; charset=UTF-8 Origin: null Connection: keep-alive Pragma: no-cache Cache-Control: no-cache <?xml version="1.0" encoding="utf-8"?>0202A0213D This is the error i get HTTP/1.1 400 Bad Request Server: Trimedia pSOS+/NDK4.3 UPnP/1.0 MediabolicUPnP/-20110626.103844 X-AV-Server-Info: av=5.0; hn=""; cn="Sony Corporation"; mn="STR-DA5500ES"; mv="1.0"; Content-type: text/html; charset=utf-8 Connection: close
Michel Kohanim Posted February 15, 2013 Posted February 15, 2013 Hi Dennis, The latter is correct; it must be POST and then you also need an additional SOAPACTION header. With kind regards, Michel
d_gatorfan Posted February 16, 2013 Author Posted February 16, 2013 I think i have found the problem. According to the document below, since I am sending an xml payload and setting custom headers, the request is "preflighted". This apparently means it sends an OPTIONS request to make sure that the request is safe to send. My receiver is responding with an error to the preflight so the actual request is not getting sent. Is there any way around this - or can I just not use a browser to send this command? https://developer.mozilla.org/en-US/docs/HTTP/Access_control_CORS?redirectlocale=en-US&redirectslug=HTTP_access_control Preflighted requests Unlike simple requests (discussed above), "preflighted" requests first send an HTTP OPTIONS request header to the resource on the other domain, in order to determine whether the actual request is safe to send. Cross-site requests are preflighted like this since they may have implications to user data. In particular, a request is preflighted if: It uses methods other than GET or POST. Also, if POST is used to send request data with a Content-Type other than application/x-www-form-urlencoded, multipart/form-data, or text/plain, e.g. if the POST request sends an XML payload to the server using application/xml or text/xml, then the request is preflighted. It sets custom headers in the request (e.g. the request uses a header such as X-PINGOTHER)
Michel Kohanim Posted February 17, 2013 Posted February 17, 2013 Hi Dennis, I do not think you can use a browser to send this command. With kind regards, Michel
d_gatorfan Posted February 17, 2013 Author Posted February 17, 2013 I found a tutorial on writing android apps and was able to muddle my way through it. Amazingly it works!!! It is amazing what you can learn from Google. Thanks for your help on this, especially since I don't even own your product - great customer service for a soon to be customer! Dennis
Michel Kohanim Posted February 17, 2013 Posted February 17, 2013 Hi Dennis, My pleasure and I am so very glad to hear you got it working. With kind regards, Michel
Recommended Posts