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

Login:
Pass:
 
 

Page 1 of 2
Topic:
Prontoscript TCP HTTP command help please?
This thread has 25 replies. Displaying posts 1 through 15.
Post 1 made on Thursday September 30, 2010 at 08:34
jimmymac
Lurking Member
Joined:
Posts:
November 2009
2
Hi All,

I'm now into the swing of things with Prontoscript but I'm looking at my first time of creating a TCP function and need help please...

We have an IPPower 9258 device - [Link: opengear.com]

You can directly control the unit using http commands - the one given as an example in the user manual that I need to use is...

[Link: admin]

'admin' is the user name and '12345678' the password.

I need to open a socket and then login to send the command:

/Set.cmd?CMD=SetPower+P61=0

This turns of power port 2 (for a Sky HD box)

Then after a short while send

/Set.cmd?CMD=SetPower+P61=1

This powering the sky box back on - i.e. to power cycle the sky box when it freezes up.

I'm wondering how to do this as the manual shows login and the control command as one string.

After looking at the developers guide I tried the following to do an initial test but had no luck...

var socket = new TCPSocket(true);
socket.connect("192.168.1.230", 80, 3000);
socket.write("[Link: admin]");
socket.close();

Can anyone point me in the right direction please?

Also, I'm looking around for programming courses for javascript and http anyone got any suggestions?
Post 2 made on Thursday September 30, 2010 at 10:27
sWORDs
Long Time Member
Joined:
Posts:
November 2006
373
As far as I've found only http communication without username/pass works. If the username and password are send in the plaintext you could try to capture the ethernet frames with wireshark and look at the data section and try to build the exact same frames and send them. It might contain things like ip and hash, so make sure you try to build correct frames.

Edit: I just saw the data under your links, the username and password are part of the link. Try using urlencode or 
@ = %40
: = %3A
+ = %2B
Post 3 made on Thursday September 30, 2010 at 10:32
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,999
Training tips:

O'Reilly Webmaster in a Nutshell and online RFC's for HTTP are a bit help to me.

Flanagan Book first 11 chapters will get you started on pure javascript. Dev Guide will fill in holes. Also search for a thread I posted entitled something like: "But Really, what is Prontoscript" as it will shed some light on how all the pieces fit together.

You may also want to download the RSS Reader from Philips and also look at the HTTP module they provided. It is not that performant but it does show you how to process response headers from the html response you will be receiving to get to the <html>xxxxyyyyyyyy</html> as documented in the manual for the GetPower command.

Reading the manual for which you posted the link above, you are supposed to send via the http protocol a simple string:

username:[email protected]/Set.cmd?CMD=SetSchedule+Powe
r
=**+YY=****+MM=**+DD=**+HH=**+MN=**+SS=**+PARAM=****+ONOFF=*

So, assuming the equipment is at 192.168.0.50, you'd open a TCP socket to "192.168.0.50" on port 80 and send a string similar to the following with the MM, DD, YY, HH, MN, SS, PARAM values as you want to set them. [myusername] and [mypassword] should be the username and password you use to logon to the equipment:

[myusername]:[mypassword]@192.168.0.50/Set.cmd?CMD=SetSchedule+Powe
r
=**+YY=****+MM=**+DD=**+HH=**+MN=**+SS=**+PARAM=****+ONOFF=*

So, with your above script and the example from the manual using the new IP address, you'd do:

var socket = new TCPSocket(true);
var toSend = "admin:[email protected]/Set.cmd?CMD=SetSchedule+Power=1A+YY=2010+MM=09+DD=30+HH=23+MN=59+SS=59+PARAM=128+ONOFF=1";

socket.connect("192.168.0.50", 80, 3000);
socket.write(toSend + '\r\n\r\n'); // Note: the CRLF combination may not be required but for true HTTP, this signals the end of the HTTP transmission.
socket.close();

I also highly recommend that you use asynchronous sockets in which case you'd use the onConnect and onData functions as discussed in the dev guide (see the examples and read Appendix A for fine-grained detail) and tweak your socket constructor as follows:
var socket = new TCPSocket(false);

Note that this equipment also support simple string transmission via the telnet protocol, which is supported on port 23. So instead of using port 80 and having the overhead of HTTP reponse processing to get to the html body, you may want to try port 23 and the following:

var socket = new TCPSocket(true);
var toSend = "getpower";

socket.connect("192.168.0.50", 80, 3000);
socket.write(toSend + '\r'); // Note: the CR combination will likely be required to signal the end of message via telnet. If this does not work, change \r to \r\n.
socket.close();

Note that you will get a multi-line response for getPower(). Each line will likely be terminated with \r.

With regard to handling multi-line responses, you must build a buffer of received data and then "peel off" each line one-by one.

There are various buffering techniques folks use and these are likely discussed in a document Barry Gordon put together on his site. http:\\www.the-gordons.net (go to downloads link and then select Pronto Communications document download from left-hand frame).

I've tried to be informative here and realize that some of this may be vague. It is that way because I don't have equipment in front of me to test with and I can only go on information I see in the protocol spec which may or may not be accurate.
Lyndel McGee
Philips Pronto Addict/Beta Tester
Post 4 made on Thursday September 30, 2010 at 10:43
sWORDs
Long Time Member
Joined:
Posts:
November 2006
373
Lyndel shouldn't that be HTTP/1.0\r\n? And isn't encodeURIComponent necessary for those chars?
Post 5 made on Thursday September 30, 2010 at 11:37
BluPhenix
Long Time Member
Joined:
Posts:
December 2008
371
As I remember it, HTTP requires 2x carriage return+ new line (at least in the docs), like Lyndel wrote.
Post 6 made on Thursday September 30, 2010 at 13:42
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,999
Yes, at the end of the string, you will likely need " HTTP/1.0\r\n\r\n"
Lyndel McGee
Philips Pronto Addict/Beta Tester
Post 7 made on Thursday May 1, 2014 at 15:22
Stealth
Long Time Member
Joined:
Posts:
December 2003
72
Can someone help me with a http command?

I have tested the command below in a web browser and it switches my Z-Wave light on ok.

htt p://192.168.0.151:3480/data_request?id=lu_action&output_format=xml&DeviceNum=3&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1

So far I have created a new page and setup a TCP/IP Socket connection with code in the Activities page connecting to 192.168.0.151 port 3480. On the UI page I have put a couple of test buttons on it but I can't workout how to send the command i.e.

/data_request?id=lu_action&output_format=xml&DeviceNum=3&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1

Can anyone tell me how best to do this?

Thanks

Steve
Post 8 made on Tuesday May 6, 2014 at 02:22
Stealth
Long Time Member
Joined:
Posts:
December 2003
72
On May 1, 2014 at 15:22, Stealth said...
Can someone help me with a http command?

I have tested the command below in a web browser and it switches my Z-Wave light on ok.

htt p://192.168.0.151:3480/data_request?id=lu_action&output_format=xml&DeviceNum=3&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1

So far I have created a new page and setup a TCP/IP Socket connection with code in the Activities page connecting to 192.168.0.151 port 3480. On the UI page I have put a couple of test buttons on it but I can't workout how to send the command i.e.

/data_request?id=lu_action&output_format=xml&DeviceNum=3&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1

Can anyone tell me how best to do this?

Thanks

Steve

Can anyone give me some help/advice on this please?

Thanks

Steve
Post 9 made on Thursday May 8, 2014 at 19:38
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,999
Steve, please post your prontoscript here. Including code to create the socket and everything you are writing to it.

Thanks,
Lyndel
Lyndel McGee
Philips Pronto Addict/Beta Tester
Post 10 made on Friday May 9, 2014 at 02:42
Stealth
Long Time Member
Joined:
Posts:
December 2003
72
Hi Lyndel,

Thank you for your reply, Its much appreciated. I was beginning to think there was no help on this for me.


I have this code in Advanced of Activity Properties -

// Define variables
var Target_PC = CF.widget("Remote_PC_IP_Address", "PARAMETERS").label
var Target_Port = CF.widget("Remote_PC_PORT", "PARAMETERS").label
var return_data = "";
var Remote_PC_Socket = new TCPSocket(false);

// Write log if failure
Remote_PC_Socket.onIOError = function(e)
{
Diagnostics.log("Remote_PC_Socket failure: " + e);
};


// Capture return data
Remote_PC_Socket.onData = function()
{
return_data += read();
};


// Initialize Socket
function Initialize()
{
Remote_PC_Socket.onConnect = function()
{
};

// Connect to socket
Remote_PC_Socket.connect(Target_PC,Target_Port,3000);
}

function TCPCommand(command)
{
Remote_PC_Socket.write(command + "\r\n");
}

The IP address and port is collected from two labels I have on a Parameters page.

The Http request command I need to run is -

[Link: 192.168.0.151]

This should switch my Z-Wave light on through my Vera Controller.

Thanks

Steve
Post 11 made on Tuesday May 13, 2014 at 02:38
Stealth
Long Time Member
Joined:
Posts:
December 2003
72
On May 9, 2014 at 02:42, Stealth said...
Hi Lyndel,

Thank you for your reply, Its much appreciated. I was beginning to think there was no help on this for me.

I have this code in Advanced of Activity Properties -

// Define variables
var Target_PC = CF.widget("Remote_PC_IP_Address", "PARAMETERS").label
var Target_Port = CF.widget("Remote_PC_PORT", "PARAMETERS").label
var return_data = "";
var Remote_PC_Socket = new TCPSocket(false);

// Write log if failure
Remote_PC_Socket.onIOError = function(e)
{
Diagnostics.log("Remote_PC_Socket failure: " + e);
};

// Capture return data
Remote_PC_Socket.onData = function()
{
return_data += read();
};

// Initialize Socket
function Initialize()
{
Remote_PC_Socket.onConnect = function()
{
};

// Connect to socket
Remote_PC_Socket.connect(Target_PC,Target_Port,3000);
}

function TCPCommand(command)
{
Remote_PC_Socket.write(command + "\r\n");
}

The IP address and port is collected from two labels I have on a Parameters page.

The Http request command I need to run is -

[Link: 192.168.0.151]

This should switch my Z-Wave light on through my Vera Controller.

Thanks

Steve

Lyndel,

Is this the information you requested?

Thanks Steve
Post 12 made on Tuesday May 13, 2014 at 20:42
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,999
If using PEP2, have you tried using the Philips HTTP library? Otherwise you will have to encode your parameter string.

What you write to socket will be something like this (4 lines total and you may need to use Javascript url encoding to get this working.) See this.

[Link: stackoverflow.com]


[Line 1]GET /data_request?id=lu_action&output_format=xml&DeviceNum=3&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1 HTTP 1.0\r\n
[Line 2]host:192.168.0.151\r\n
[Line 3]\r\n
[Line 4]\r\n

So, where you have a single function which writes command + '\r\n' you need to actually build your string as above and send that. Note that if you choose to use the function you have, you can build a command with only the first 3 lines and call the function with that.
Lyndel McGee
Philips Pronto Addict/Beta Tester
Post 13 made on Wednesday May 14, 2014 at 07:46
Stealth
Long Time Member
Joined:
Posts:
December 2003
72
On May 13, 2014 at 20:42, Lyndel McGee said...
If using PEP2, have you tried using the Philips HTTP library? Otherwise you will have to encode your parameter string.

What you write to socket will be something like this (4 lines total and you may need to use Javascript url encoding to get this working.) See this.

[Link: stackoverflow.com]

[Line 1]GET /data_request?id=lu_action&output_format=xml&DeviceNum=3&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1 HTTP 1.0\r\n
[Line 2]host:192.168.0.151\r\n
[Line 3]\r\n
[Line 4]\r\n

So, where you have a single function which writes command + '\r\n' you need to actually build your string as above and send that. Note that if you choose to use the function you have, you can build a command with only the first 3 lines and call the function with that.

Hi Lyndel,

Thank you for your help with this code. I will have to do some more reading up on this to better understand your instructions. I will report back with outcome.

Thanks again

Steve
Post 14 made on Wednesday May 14, 2014 at 20:17
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,999
You have to communicate over the socket in exactly the way a web browser would do it. That is what my lines above do. You can put a packet sniffer on your network if you'd like.

The lines above are the HTTP Protocol that I mentioned from Webmaster In A Nutshell. There is another option. You can use the Philips HTTP Library with PEP2 and see if that will do the trick for you.
Lyndel McGee
Philips Pronto Addict/Beta Tester
Post 15 made on Thursday May 15, 2014 at 02:36
Stealth
Long Time Member
Joined:
Posts:
December 2003
72
Thanks Lyndel, I will report back soon

Steeve
Page 1 of 2


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