Your Universal Remote Control Center
RemoteCentral.com
Philips Pronto Professional Forum - View Post
Previous section Next section Up level
Up level
The following page was printed from RemoteCentral.com:

Login:
Pass:
 
 

Topic:
Using Pronto UDP to perform SSDP search
This thread has 3 replies. Displaying all posts.
Post 1 made on Thursday December 26, 2013 at 17:35
cebrady
Lurking Member
Joined:
Posts:
February 2009
5
I am just a beginner with programming the Pronto TSU series of remotes. I am trying to understand the Pronto UDP functions so that I can perform a SSDP query to find he IP address of my Roku box. I think I know how to setup the UDP socket and send request but I don't understand how to read back the response so that I can parse if for the IP address.

I need to send the following request using http protocol to 239.255.255.250 port 1900

M-SEARCH * HTTP/1.1
Host: 239.255.255.250:1900
Man: "ssdp:discover"
ST: roku:ecp

I am doing this using the following code

var TARGETADDRESS = "239,255.255.250";
var PORT = 1900;
var aServiceType = "roku:ecp";
var reg;
var socket = new UDPSocket();

req = "M-SEARCH * HTTP/1.1\r\n";
req += "HOST: " + TARGETADDRESS + ":" + PORT + "\r\n";
req += "MAN: \"ssdp:discover\"\r\n";
req += "ST: " + aServiceType + "\r\n";
req += "\r\n";
socket.send(req, TARGETADDRESS, PORT);

I believe this is correct coding to send out the request. What I don't understand is how to get the response back into a string that I can parse to locate the IP address of my Roku. The response I am looking for is something like this

HTTP/1.1 200 OK
Cache-Control: max-age=300
ST: roku:ecp
Location: [Link: 192.168.1.134]
USN: uuid:roku:ecp:P0A070000007

With TCP sockets I would use a socket read to obtain the response, but there does not appear to be a socket read function with UDP socket. The developers guide shows the following example

var s = new UDPSocket(1900);
s.onData = function (aData, aHost, aPort) {
System.print("Received " + aData.length + " bytes");
System.print("Client IP address: " + aHost);
System.print("Client UDP port: " + aPort);
};

If I understand functions correctly aData, aHost and aPort are variables I pass into the function. I don't understand this example. How do I go about getting the data received when the Roku box response to my request. If it was a TCP socket I would do it using

var socket, aData;
socket = new TCPSocket();

socket.onData = function() {
aData = socket.read();
};

There does not appear to be an equivalent read function for UDP sockets. Can someone explain how to do it with a UDP socket. Do I need to set up the response port before I sent the request? Do I need a separate socket for the request and the response?

Thanks,

Ed
Post 2 made on Thursday December 26, 2013 at 23:30
cosmicvoid
Long Time Member
Joined:
Posts:
November 2007
104
OP | Post 3 made on Friday December 27, 2013 at 18:24
cebrady
Lurking Member
Joined:
Posts:
February 2009
5
OK,

I finally figured out how to do this. The code below will allow you to query a Roku streaming player such as the Roku 2 and obtain its IP address. Maybe this will be helpful to someone else.

// JavaScript Document

var Timeout = 5000;
var IPAddress; // When routine completes contains IP address of Roku device
var TARGETADDRESS = "239.255.255.250";
var PORT = 1900;
var aServiceType = "roku:ecp";

scheduleAfter(10,sendSearch);

// Open a UDP Socket
//
// This socket used to receive SSDP responses and
// to look for response from Roku device providing
// its IP address
//
// Looking for the following response
// HTTP/1.1 200 OK
// Cache-Control: max-age=300
// ST: roku:ecp
// Location: [Link: 192.168.1.134]
// USN: uuid:roku:ecp:P0A070000007

var socket = new UDPSocket(1900);
socket.onData = function (aData, aHost, aPort)
{
var aResults;

// Split packet data stored in aData at boundaries and
// store each string segment into array elements of aResults

aResults = aData.split(String.fromCharCode(13));

// Verify that line 0 and 1 are correct response for Roku
// device
if (aResults[0].search("HTTP/1.1 200 OK") >= 0 &&
aResults[2].search("ST: roku:ecp") >= 0)
{
IPAddress = aHost;
socket.close();
}
}

// Function querys for the roku IP address by sending an SSDP
// multicast request to IP address 239:255:255:250:1900. The
// request packet is as follows:
// M-SEARCH * HTTP/1.1
// Host: 239.255.255.250:1900
// Man: "ssdp:discover"
// ST: roku:ecp

function sendSearch()
{
var req = "M-SEARCH * HTTP/1.1\r\n";
req += "Host: " + TARGETADDRESS + ":" + PORT + "\r\n";
req += "Man: \"ssdp:discover\"\r\n";
req += "ST: " + aServiceType + "\r\n";
req += "\r\n";
socket.send(req, TARGETADDRESS, PORT);
}
Post 4 made on Sunday December 29, 2013 at 11:10
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,999
On December 26, 2013 at 23:30, cosmicvoid said...

The link above is a very old post and was written before UDP was added to the Pronto. UDP was required for Philips to be able to interface with the Sonos Equipment.
Lyndel McGee
Philips Pronto Addict/Beta Tester


Jump to


Protected Feature Before you can reply to a message...
You must first register for a Remote Central user account - it's fast and free! Or, if you already have an account, please login now.

Please read the following: Unsolicited commercial advertisements are absolutely not permitted on this forum. Other private buy & sell messages should be posted to our Marketplace. For information on how to advertise your service or product click here. Remote Central reserves the right to remove or modify any post that is deemed inappropriate.

Hosting Services by ipHouse